00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 StatisticEntry::Pointer
00036 StatisticData::
00037 CreateEntry()
00038 {
00039 StatisticEntry::Pointer smpNew = StatisticEntry::New(++m_LastID,m_StampOffset,this);
00040 return smpNew;
00041 };
00042
00043 StatisticEntry::Pointer
00044 StatisticData::
00045 CreateChildEntry(const IDType& parentID)
00046 {
00047 StatisticEntry* pParent = GetEntry(parentID);
00048 if (!pParent) throwExceptionMacro("Error. Cannot create child entry. Unable to find parent entry with given ID. ID: "<<parentID);
00049
00050 return pParent->CreateChildEntry();
00051 };
00052
00053 StatisticEntry::Pointer
00054 StatisticData::
00055 PostCreateChildEntry(const IDType& parentID)
00056 {
00057 StatisticEntry* pParent = GetEntry(parentID);
00058 if (!pParent) throwExceptionMacro("Error. Cannot create child entry. Unable to find parent entry with given ID. ID: "<<parentID);
00059
00060 return pParent->PostCreateChildEntry();
00061 };
00062
00063 StatisticEntry::Pointer
00064 StatisticData::
00065 GetEntry(const IDType& entryID)
00066 {
00067 return SearchEntry(m_smpRoot,entryID);
00068 };
00069
00071 void
00072 StatisticData::
00073 CloseEntries()
00074 {
00075 m_smpRoot->CloseEntry();
00076 };
00077
00078 StatisticData::
00079 ~StatisticData()
00080 {
00081 m_smpRoot = 0;
00082 };
00083
00084 void
00085 StatisticData::
00086 Reset()
00087 {
00088 m_LastID = 0;
00089 m_LastEntryID = 0;
00090 m_StampOffset = clock();
00091 m_smpRoot = StatisticEntry::New(0,m_StampOffset,this);
00092 m_smpRoot->SetCreationTimeStamp();
00093 };
00094
00095 const StatisticData::EntriesType&
00096 StatisticData::
00097 GetEntries() const
00098 {
00099 return m_smpRoot->GetEntries();
00100 };
00101
00102 StatisticData::EntriesType&
00103 StatisticData::
00104 GetEntries()
00105 {
00106 return m_smpRoot->GetEntries();
00107 };
00108
00109 StatisticData::
00110 StatisticData() : XMLStreamObject(XMLTags::StatisticData)
00111 {
00112 Reset();
00113 };
00114
00115 StatisticEntry*
00116 StatisticData::
00117 SearchEntry(StatisticEntry* pCurrentEntry, const IDType& entryID)
00118 {
00119 if (pCurrentEntry->GetID()==entryID)
00120 {
00121 return pCurrentEntry;
00122 }
00123 else
00124 {
00125 for (EntriesType::iterator pos = pCurrentEntry->GetEntries().begin(); pos != pCurrentEntry->GetEntries().end(); pos++)
00126 {
00127 StatisticEntry* pFinding = SearchEntry((*pos),entryID);
00128 if (pFinding) return pFinding;
00129 }
00130 }
00131
00132 return 0;
00133 };
00134
00135
00136 StatisticData& StatisticData::operator = (const StatisticData& data)
00137 {
00138 if (this == &data) return *this;
00139
00140 Reset();
00141
00142
00143 for (EntriesType::const_iterator pos = data.GetEntries().begin(); pos != data.GetEntries().end(); pos++)
00144 {
00145 StatisticEntry::Pointer smpChild = CreateEntry();
00146 smpChild->operator = (*(*pos));
00147 m_smpRoot->GetEntries().push_back(smpChild);
00148 }
00149
00150 return *this;
00151 };
00152
00153 void
00154 StatisticData::
00155 SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData)
00156 {
00157 if (rsXMLSubTag == XMLTags::StatisticEntry)
00158 {
00159 StatisticEntry::Pointer smpChild = CreateEntry();
00160 smpChild->LoadFromString(rsXMLSubElement);
00161 m_smpRoot->GetEntries().push_back(smpChild);
00162 }
00163 };
00164
00165 std::string
00166 StatisticData::
00167 SaveData(const unsigned int& iDepth, bool& bHasSubElements) const
00168 {
00169 std::string result;
00170
00171 for (EntriesType::const_iterator pos = m_smpRoot->GetEntries().begin(); pos != m_smpRoot->GetEntries().end(); pos++)
00172 {
00173 AddSubElement(result,(*pos),iDepth);
00174 }
00175 return result;
00176 };
00177
00178 StatisticEntry::Pointer
00179 StatisticData::
00180 GetCurrentEntry()
00181 {
00182 IDType id = GetCurrentEntryID();
00183 StatisticEntry::Pointer smpEntry = 0;
00184 if (id!=0)
00185 {
00186 smpEntry = GetEntry(id);
00187 }
00188 return smpEntry;
00189 };
00190
00191 StatisticData::IDType
00192 StatisticData::
00193 GetCurrentEntryID() const
00194 {
00195 if (m_EntryStack.size()==0) return 0;
00196
00197 return m_EntryStack.back();
00198 };
00199
00200 StatisticData::IDType
00201 StatisticData::
00202 GetLastClosedEntryID() const
00203 {
00204 return m_LastEntryID;
00205 };
00206
00207 StatisticData::IDType
00208 StatisticData::
00209 CloseEntry(const IDType& entryID)
00210 {
00211 std::vector<IDType>::iterator pos = m_EntryStack.begin();
00212
00213
00214 while (pos!=m_EntryStack.end())
00215 {
00216 if (*pos == entryID) break;
00217 pos++;
00218 }
00219
00220
00221 m_EntryStack.erase(pos,m_EntryStack.end());
00222
00223 IDType currentID = 0;
00224 if (m_EntryStack.size()>0) currentID = m_EntryStack.back();
00225
00226 m_LastEntryID = entryID;
00227
00228 return currentID;
00229 };
00230
00231 void
00232 StatisticData::
00233 OpenEntry(const IDType& entryID)
00234 {
00235 m_EntryStack.push_back(entryID);
00236 };
00237
00238 }