00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "freXMLStringMultiMap.h"
00023 #include "freExceptions.h"
00024
00025 namespace FREE
00026 {
00027
00031
00032
00033 XMLStringMultiMap::ElementIndexType
00034 XMLStringMultiMap::
00035 Size() const
00036 {
00037 return m_Keys.size();
00038 };
00039
00040 XMLStringMultiMap::ElementIndexType
00041 XMLStringMultiMap::
00042 AddElement(const std::string& sXMLTag, const std::string& sData)
00043 {
00044 m_Keys.push_back(sXMLTag);
00045 m_Datas.push_back(sData);
00046 return m_Keys.size()-1;
00047 };
00048
00049 XMLStringMultiMap::ElementIndexType
00050 XMLStringMultiMap::
00051 GetElementData(const std::string& sXMLTag, std::string& sData) const
00052 {
00053 ElementIndexType index = 0;
00054 return GetElementData(sXMLTag,sData,index);
00055 };
00056
00057 XMLStringMultiMap::ElementIndexType
00058 XMLStringMultiMap::
00059 GetElementData(const std::string& sXMLTag, std::string& sData, ElementIndexType& nextIndex) const
00060 {
00061 for (ElementIndexType index = nextIndex; index<m_Keys.size(); index++)
00062 {
00063 if (m_Keys[index]==sXMLTag)
00064 {
00065 sData = m_Datas[index];
00066 nextIndex = index+1;
00067 return index;
00068 };
00069 };
00070 return -1;
00071 };
00072
00073 bool
00074 XMLStringMultiMap::
00075 GetElementData(const ElementIndexType& index, std::string& sData) const
00076 {
00077 if (index>=m_Datas.size()) return false;
00078
00079 sData = m_Datas[index];
00080 return true;
00081 };
00082
00083 void
00084 XMLStringMultiMap::
00085 SetElementData(const ElementIndexType& index, const std::string& sData)
00086 {
00087 if (index>=m_Datas.size()) return;
00088
00089 m_Datas[index] = sData;
00090 };
00091
00092 void
00093 XMLStringMultiMap::
00094 DeleteElement(const ElementIndexType& index)
00095 {
00096 if (index>=m_Datas.size()) return;
00097
00098 m_Keys.erase(m_Keys.begin()+index);
00099 m_Datas.erase(m_Datas.begin()+index);
00100 };
00101
00102 bool
00103 XMLStringMultiMap::
00104 GetElementTag(const ElementIndexType& index, std::string& sXMLTag) const
00105 {
00106 if (index>=m_Keys.size()) return false;
00107
00108 sXMLTag = m_Keys[index];
00109 return true;
00110 };
00111
00112 void
00113 XMLStringMultiMap::
00114 Reset()
00115 {
00116 XMLStreamObject::Reset();
00117 m_Keys.clear();
00118 m_Datas.clear();
00119 };
00120
00121 XMLStringMultiMap&
00122 XMLStringMultiMap::
00123 operator = (const XMLStringMultiMap& rXMLStringMultiMap)
00124 {
00125 if (this==&rXMLStringMultiMap) return *this;
00126
00127 Reset();
00128
00129 for (ElementIndexType index = 0; index<rXMLStringMultiMap.Size(); index++)
00130 {
00131 std::string sKey;
00132 std::string sData;
00133
00134 rXMLStringMultiMap.GetElementTag(index,sKey);
00135 rXMLStringMultiMap.GetElementData(index,sData);
00136
00137 this->AddElement(sKey,sData);
00138 };
00139
00140 return *this;
00141 };
00142
00143 XMLStringMultiMap::
00144 XMLStringMultiMap(const std::string sXMLTag) : XMLStreamObject(sXMLTag)
00145 {
00146 };
00147
00148 XMLStringMultiMap::
00149 XMLStringMultiMap(const XMLStringMultiMap& rXMLStringMultiMap) : XMLStreamObject(rXMLStringMultiMap.GetXMLTag())
00150 {
00151 *this = rXMLStringMultiMap;
00152 };
00153
00154 XMLStringMultiMap::
00155 ~XMLStringMultiMap()
00156 {
00157 Reset();
00158 };
00159
00160 void
00161 XMLStringMultiMap::
00162 SubElementLoadProcessing(const std::string& rsXMLSubTag, const std::string& rsXMLSubElement, const std::string& rsXMLSubData)
00163 {
00164 if (rsXMLSubTag!=cXML_Text) AddElement(rsXMLSubTag,rsXMLSubData);
00165 };
00166
00167 std::string
00168 XMLStringMultiMap::
00169 SaveData(const unsigned int& iDepth, bool& bHasSubElements) const
00170 {
00171 std::string result;
00172
00173 for (ElementIndexType index = 0; index<m_Keys.size(); index++)
00174 {
00175 if (m_Keys[index]!=cXML_Text)
00176 {
00177 AddSubElement(result,m_Keys[index],m_Datas[index],iDepth);
00178 }
00179 };
00180 return result;
00181 };
00182
00183 }