00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00044 #include "../tinyxml/tinyxml.h"
00045
00046 #include "attribute.h"
00047 #include "product.h"
00048
00049 #include "svx.h"
00050
00051 using namespace libsvx;
00052
00053 static std::string NullString = "";
00054
00057 Svx::Svx(TiXmlElement & a_Element)
00058 :Element(a_Element,"svx")
00059 ,m_A_href(NULL)
00060 ,m_A_version(NULL)
00061 {
00062 assert(a_Element.Value().compare("svx") == 0);
00063 Add(a_Element);
00064 }
00065
00069 Svx::~Svx()
00070 {
00071 if (m_A_href != NULL)
00072 delete m_A_href;
00073 if (m_A_version != NULL)
00074 delete m_A_version;
00075
00076
00077
00078
00079
00080
00081
00082
00083 }
00084
00091 bool Svx::Add(TiXmlElement & Element)
00092 {
00093 bool result = true;
00094
00095 assert(Element.Value().compare("svx") == 0);
00096
00097 if (m_A_version != NULL && Element.Attribute("version") != NULL)
00098 {
00099
00100 result = (m_A_version->String().compare(*Element.Attribute("version")) == 0);
00101 }
00102
00103 if (result)
00104 {
00105
00106 if (Element.Attribute("href") != NULL)
00107 {
00108 if (m_A_href != NULL)
00109 delete m_A_href;
00110
00111 m_A_href = new Attribute(*Element.Attribute("href"),"href");
00113 }
00114
00115
00116 TiXmlElement * txIterator = Element.FirstChildElement("product");
00117
00118 while (txIterator != NULL)
00119 {
00120 Product * tmpNewText = new Product(*txIterator);
00121
00122 Product * tmpFound = FindProduct(tmpNewText->UID()->String());
00123 if (tmpFound == NULL)
00124 {
00125
00126 m_List_Product.push_back(tmpNewText);
00127 }
00128 else
00129 {
00130
00131 *tmpFound += *tmpNewText;
00132 delete tmpNewText;
00133 }
00134
00135 txIterator = txIterator->NextSiblingElement("product");
00136 }
00137 }
00138
00139 return result;
00140 }
00141
00145 bool Svx::IsValid() const
00146 {
00147 return (m_List_Product.size() > 0 && m_A_version != NULL && m_A_version->String().compare("1.0") == 0);
00148 }
00149
00150 TiXmlElement & Svx::XmlElement()
00151 {
00152 assert(m_Node != NULL);
00153
00154 if (m_A_href != NULL)
00155 m_A_href->XmlElement(*m_Node);
00156
00157 if (m_A_version != NULL)
00158 m_A_version->XmlElement(*m_Node);
00159
00160 for (size_t i = 0; i < m_List_Product.size();i++)
00161 {
00162 m_Node->InsertEndChild(m_List_Product[i].XmlElement());
00163 }
00164
00165 return *m_Node;
00166 }
00167
00171 Product * Svx::FindProduct(const std::string & the_product_uid) const
00172 {
00173 size_t current_product = 0;
00174
00175 while (current_product < m_List_Product.size() &&
00176 m_List_Product[current_product].UID() != NULL &&
00177 m_List_Product[current_product].UID()->String().compare(the_product_uid) != 0)
00178 {
00179 current_product++;
00180 }
00181
00182 if (current_product < m_List_Product.size())
00183 return &m_List_Product[current_product];
00184 else
00185 return NULL;
00186 }
00187
00191 void Svx::Iterate_Product_Begin()
00192 {
00193 m_Iterator_Product = 0;
00194 }
00195
00199 bool Svx::Iterate_Product_IsEnd()
00200 {
00201 return (m_Iterator_Product == m_List_Product.size()-1);
00202 }
00203
00207 const std::string & Svx::Iterate_Product_Next()
00208 {
00209 return m_List_Product[m_Iterator_Product++].UID()->String();
00210 }
00211
00215 const std::string & Svx::Iterate_Product_Prev()
00216 {
00217 return m_List_Product[m_Iterator_Product--].UID()->String();
00218 }
00219
00223 Version * Svx::FindVersion(const std::string & the_product_uid, const std::string & the_version_name)
00224 {
00225 Product * the_product = FindProduct(the_product_uid);
00226
00227 if (the_product == NULL)
00228 return NULL;
00229 else return the_product->FindVersion(the_version_name);
00230 }
00231
00235 void Svx::Iterate_Version_Begin(const std::string & the_product_uid)
00236 {
00237 Product * the_product = FindProduct(the_product_uid);
00238
00239 if (the_product != NULL)
00240 the_product->Iterate_Version_Begin();
00241 }
00242
00246 bool Svx::Iterate_Version_IsBegin(const std::string & the_product_uid)
00247 {
00248 Product * the_product = FindProduct(the_product_uid);
00249
00250 if (the_product == NULL)
00251 return false;
00252 else
00253 return the_product->Iterate_Version_IsBegin();
00254 }
00255
00259 bool Svx::Iterate_Version_IsEnd(const std::string & the_product_uid)
00260 {
00261 Product * the_product = FindProduct(the_product_uid);
00262
00263 if (the_product == NULL)
00264 return false;
00265 else
00266 return the_product->Iterate_Version_IsEnd();
00267 }
00268
00272 const std::string & Svx::Iterate_Version_Next(const std::string & the_product_uid)
00273 {
00274 Product * the_product = FindProduct(the_product_uid);
00275
00276 if (the_product == NULL)
00277 return NullString;
00278 else
00279 return the_product->Iterate_Version_Next();
00280 }
00281
00285 const std::string & Svx::Iterate_Version_Prev(const std::string & the_product_uid)
00286 {
00287 Product * the_product = FindProduct(the_product_uid);
00288
00289 if (the_product == NULL)
00290 return NullString;
00291 else
00292 return the_product->Iterate_Version_Prev();
00293 }