freTimeStampedObject.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freTimeStampedObject.cxx,v $
00007   Language:  C++
00008 
00009 
00010   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00011   Institute for Medical Biometry and Informatics, University of Heidelberg,
00012   Germany). All rights reserved.
00013   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00014   for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even 
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00018      PURPOSE.  See the above copyright notices for more information.
00019 
00020 =========================================================================*/
00021 #include "freTimeStampedObject.h"
00022 
00023 #include "freConvert.h"
00024 
00025 namespace FREE
00026 {
00027 
00031 
00032 
00033 DurationType
00034 TimeStampedObject::
00035 GetDurationTo(const TimeStampedObject& object) const
00036 {
00037   if (object.GetCreationTimeStamp()<m_CreationTimeStamp) return -1;
00038   return object.GetCreationTimeStamp() - m_CreationTimeStamp;
00039 };
00040 
00041 DurationType
00042 TimeStampedObject::
00043 GetInterimDurationTo(const TimeStampedObject& object) const
00044 {
00045   if (object.GetCreationTimeStamp()<m_ClosingTimeStamp) return -1;
00046   return object.GetCreationTimeStamp() - m_ClosingTimeStamp;
00047 };
00048 
00049 DurationType
00050 TimeStampedObject::
00051 GetDuration() const
00052 {
00053   if (m_CreationTimeStamp>m_ClosingTimeStamp) return -1;
00054   return m_ClosingTimeStamp - m_CreationTimeStamp;
00055 };
00056 
00057 TimeStampedObject&
00058 TimeStampedObject::
00059 operator = (const TimeStampedObject& object)
00060 {
00061   //Convert the time stamps to the new offset
00062   TimeStampType sourceOffset = object.GetStampOffset()/(CLOCKS_PER_SEC/10);
00063   TimeStampType destinationOffset = m_StampOffset/(CLOCKS_PER_SEC/10);
00064 
00065   m_CreationTimeStamp = object.GetCreationTimeStamp()+sourceOffset-destinationOffset;
00066   m_ClosingTimeStamp = object.GetClosingTimeStamp()+sourceOffset-destinationOffset;
00067 
00068   return *this;
00069 };
00070 
00071 TimeStampedObject::
00072 TimeStampedObject(clock_t& stampOffset, const std::string& sXMLTag): m_StampOffset(stampOffset),XMLStreamObject(sXMLTag)
00073 {
00074   Reset();
00075 };
00076 
00077 TimeStampedObject::
00078 TimeStampedObject(const TimeStampedObject& object): m_StampOffset(object.GetStampOffset()),XMLStreamObject(object.GetXMLTag())
00079 {
00080   *this = object;
00081 }
00082 
00083 TimeStampedObject::
00084 ~TimeStampedObject()
00085 {
00086 };
00087 
00088 const TimeStampType&
00089 TimeStampedObject::
00090 GetCreationTimeStamp() const
00091 {
00092   return m_CreationTimeStamp;
00093 };
00094 
00095 const TimeStampType&
00096 TimeStampedObject::
00097 GetClosingTimeStamp() const
00098 {
00099   return m_ClosingTimeStamp;
00100 };
00101 
00102 clock_t&
00103 TimeStampedObject::
00104 GetStampOffset() const
00105 {
00106   return m_StampOffset;
00107 };
00108 
00109 const bool
00110 TimeStampedObject::
00111 IsClosed() const
00112 {
00113         return m_ClosingTimeStamp!=-1;
00114 };
00115 
00116 const bool
00117 TimeStampedObject::
00118 IsCreated() const
00119 {
00120         return m_CreationTimeStamp!=-1;
00121 };
00122 
00123 void
00124 TimeStampedObject::
00125 Reset()
00126 {
00127   XMLStreamObject::Reset();
00128   m_ClosingTimeStamp = -1;
00129   m_CreationTimeStamp = -1;
00130 };
00131 
00132 void
00133 TimeStampedObject::
00134 AttributesLoadProcessing(const AttributesType& rAttributes)
00135 {
00136   for (AttributesType::const_iterator pos = rAttributes.begin(); pos!= rAttributes.end(); pos++)
00137   {
00138     if (pos->first == XMLTags::TimeStampCreate) m_CreationTimeStamp = Convert::ToLong(pos->second);
00139     else if (pos->first == XMLTags::TimeStampClose) m_ClosingTimeStamp = Convert::ToLong(pos->second);
00140   }
00141 };
00142 
00143 void
00144 TimeStampedObject::
00145 SaveAttributes(AttributesSaveListType& rAttributes) const
00146 {
00147   rAttributes.push_back(AttributesSaveListType::value_type(XMLTags::TimeStampCreate, Convert::ToStr(m_CreationTimeStamp)));
00148   rAttributes.push_back(AttributesSaveListType::value_type(XMLTags::TimeStampClose, Convert::ToStr(m_ClosingTimeStamp)));
00149 }; 
00150 
00151 void
00152 TimeStampedObject::
00153 Stamp(TimeStampType& rTimeStamp, clock_t& stampOffset)
00154 {
00155   clock_t now = clock();
00156   now -= stampOffset;
00157   rTimeStamp = now / (CLOCKS_PER_SEC/10); //convert clocks to thenth second
00158 };
00159 
00160 } //end of namespace FREE

Generated at Sat Oct 13 17:53:21 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000