freStatisticEntry.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: freStatisticEntry.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 
00022 #include "freStatisticEntry.h"
00023 #include "freStatisticData.h"
00024 
00025 #include "freConvert.h"
00026 
00027 namespace FREE
00028 {
00029 
00030 
00034 
00035 const StatisticEntry::ReferenceIDType StatisticEntry::cUndefinedRef = 0;
00036 
00037 StatisticEntry& StatisticEntry::operator = (const StatisticEntry& entry)
00038 {
00039   if (this == &entry) return *this;
00040 
00041   TimeStampedObject::operator =(entry);
00042 
00043   //Copy values;
00044   for (ValuesType::const_iterator pos = entry.m_Values.begin(); pos != entry.m_Values.end(); pos++)
00045   {
00046     StatisticValue newValue(*pos);
00047     m_Values.push_back(newValue);
00048   }
00049 
00050   //Copy entries;
00051   for (EntriesType::const_iterator pos = entry.m_Entries.begin(); pos != entry.m_Entries.end(); pos++)
00052   {
00053     StatisticEntry::Pointer smpChild = m_pData->CreateEntry();
00054     smpChild->operator = (*(*pos));
00055     m_Entries.push_back(smpChild);
00056   }
00057 
00058   return *this;
00059 };
00060 
00061 StatisticEntry::Pointer
00062 StatisticEntry::
00063 CreateChildEntry()
00064 {
00065   if (!m_pData) throwExceptionMacro("Error. Cannot create a statistic entry, parent entry has no StatisticData defined.");
00066 
00067   if (IsClosed())
00068   {
00069     return PostCreateChildEntry();
00070   }
00071   else
00072   {
00073     StatisticEntry::Pointer smpChild = m_pData->CreateEntry();
00074     smpChild->SetCreationTimeStamp();
00075 
00076     //if there is a preceeding sibling, close it
00077     if (m_Entries.size()!=0)
00078     {
00079       m_Entries.back()->CloseEntry();
00080     }
00081 
00082     m_Entries.push_back(smpChild);
00083     m_pData->OpenEntry(smpChild->GetID());
00084 
00085     return smpChild;
00086   }
00087 };
00088 
00089 StatisticEntry::Pointer
00090 StatisticEntry::
00091 PostCreateChildEntry()
00092 {
00093   if (!m_pData) throwExceptionMacro("Error. Cannot create a statistic entry, parent entry has no StatisticData defined.");
00094 
00095   StatisticEntry::Pointer smpChild = m_pData->CreateEntry();
00096 
00097   //Set creation time
00098   if (m_Entries.size()==0)
00099   { //no preceeding siblings
00100     smpChild->SetCreationTimeStamp(this->GetCreationTimeStamp());
00101   }
00102   else
00103   { //equals the closing time stamp of the preceeding sibling, so close sibling and get stamp
00104     m_Entries.back()->CloseEntry();
00105     smpChild->SetCreationTimeStamp(m_Entries.back()->GetClosingTimeStamp());
00106   }
00107 
00108   //Set closing time
00109   if (IsClosed())
00110   {
00111     smpChild->SetClosingTimeStamp(this->GetClosingTimeStamp());
00112   }
00113   else
00114   {
00115     smpChild->SetClosingTimeStamp();
00116   }
00117 
00118   m_pData->OpenEntry(smpChild->GetID());
00119   m_Entries.push_back(smpChild);
00120 
00121   return smpChild;
00122 };
00123 
00124 void
00125 StatisticEntry::
00126 CloseEntry()
00127 {
00128   for (EntriesType::const_iterator pos = m_Entries.begin(); pos != m_Entries.end(); pos++)
00129   {
00130     (*pos)->CloseEntry();
00131   }
00132 
00133   if (!IsClosed()) this->SetClosingTimeStamp();
00134 
00135   m_pData->CloseEntry(m_ID);
00136 };
00137 
00138 StatisticEntry::
00139 StatisticEntry(const IDType& id, clock_t& stampOffset, StatisticData* pData):TimeStampedObject(stampOffset,XMLTags::StatisticEntry)
00140 {
00141   if (!pData) throwExceptionMacro("Error. Cannot create a statistic entry, no StatisticData defined.");
00142   m_ID = id;
00143   m_pData = pData;
00144 };
00145 
00146 StatisticEntry::
00147 ~StatisticEntry()
00148 {
00149   Reset();
00150 };
00151 
00152 void
00153 StatisticEntry::
00154 Reset()
00155 {
00156   TimeStampedObject::Reset();
00157   m_Values.clear();
00158   m_Entries.clear();
00159 };
00160 
00161 StatisticValue&
00162 StatisticEntry::
00163 AddValue(const std::string& sValue, const StatisticValue::ReferenceIDType& refID)
00164 {
00165   StatisticValue value(sValue,refID);
00166   m_Values.push_back(value);
00167   return m_Values.back();
00168 };
00169 
00170 void
00171 StatisticEntry::
00172 SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData)
00173 {
00174   if (rsXMLSubTag == XMLTags::StatisticValue)
00175   {
00176     StatisticValue newValue("");
00177     newValue.LoadFromString(rsXMLSubElement);
00178     m_Values.push_back(newValue);
00179   }
00180   else if (rsXMLSubTag == XMLTags::StatisticEntry)
00181   {
00182     StatisticEntry::Pointer smpChild = m_pData->CreateEntry();
00183     smpChild->LoadFromString(rsXMLSubElement);
00184     m_Entries.push_back(smpChild);
00185   }
00186   else TimeStampedObject::SubElementLoadProcessing(rsXMLSubTag, rsXMLSubElement, rsXMLSubData);
00187 };
00188 
00189 std::string
00190 StatisticEntry::
00191 SaveData(const unsigned int& iDepth, bool& bHasSubElements) const
00192 {
00193   std::string result;
00194   //values
00195   for (ValuesType::const_iterator pos = m_Values.begin(); pos != m_Values.end(); pos++)
00196   {
00197                 AddSubElement(result,&(*pos),iDepth);
00198   }
00199   //entries
00200   for (EntriesType::const_iterator pos = m_Entries.begin(); pos != m_Entries.end(); pos++)
00201   {
00202                 AddSubElement(result,*pos,iDepth);
00203   }
00204   return result;
00205 };
00206 
00207 void
00208 StatisticEntry::
00209 AttributesLoadProcessing(const AttributesType& rAttributes)
00210 {
00211   AttributesType::const_iterator pos = rAttributes.find(XMLTags::StatisticEntryRef);
00212   if (pos == rAttributes.end()) m_RefID = cUndefinedRef;
00213   else m_RefID = Convert::ToInt(pos->second);
00214 
00215   TimeStampedObject::AttributesLoadProcessing(rAttributes);
00216 };
00217 
00218 void
00219 StatisticEntry::
00220 SaveAttributes(AttributesSaveListType& rAttributes) const
00221 {
00222   rAttributes.push_back(AttributesSaveListType::value_type(XMLTags::StatisticEntryRef,Convert::ToStr(m_RefID)));
00223   rAttributes.push_back(AttributesSaveListType::value_type(XMLTags::StatisticEntryID, Convert::ToStr(m_ID)));
00224   
00225   TimeStampedObject::SaveAttributes(rAttributes);
00226 }; 
00227 
00228 
00229 } //end of namespace FREE

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