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
00045
00046 #include "../tinyxml/tinyxml.h"
00047
00048 #include "attribute.h"
00049 #include "license.h"
00050 #include "version.h"
00051 #include "description.h"
00052 #include "vendor.h"
00053
00054 #include "product.h"
00055
00056 using namespace libsvx;
00057
00061 Product::Product(TiXmlElement & a_Element)
00062 :ElementName(a_Element,"product")
00063 ,ElementUid(a_Element,"product")
00064 ,ElementLicense(a_Element,"product")
00065 ,m_A_href(NULL)
00066 ,m_A_ihref(NULL)
00067 ,m_Vendor(NULL)
00068 ,m_Description(NULL)
00069 {
00070 assert(a_Element.Value().compare("product") == 0);
00071
00072
00073 if (a_Element.Attribute("href") != NULL)
00074 {
00075 m_A_href = new Attribute(*a_Element.Attribute("href"),"href");
00076 }
00077
00078 if (a_Element.Attribute("ihref") != NULL)
00079 {
00080 m_A_ihref = new Attribute(*a_Element.Attribute("ihref"),"ihref");
00081 }
00082
00083
00084 if (a_Element.FirstChildElement("description") != NULL)
00085 {
00086 m_Description = new Description(*a_Element.FirstChildElement("description"));
00087 }
00088
00089 if (a_Element.FirstChildElement("vendor") != NULL)
00090 {
00091 m_Vendor = new Vendor(*a_Element.FirstChildElement("vendor"));
00092 }
00093
00094 TiXmlElement * txIterator;
00095
00096 m_List_Version.clear();
00097 txIterator = a_Element.FirstChildElement("version");
00098
00099 while (txIterator != NULL)
00100 {
00101 Version * tmpText = new Version(*txIterator);
00102 m_List_Version.push_back(tmpText);
00103 txIterator = txIterator->NextSiblingElement("version");
00104 }
00105 m_Iterator_Version = 0;
00106 }
00107
00111 Product::~Product()
00112 {
00113 if (m_A_href != NULL)
00114 delete m_A_href;
00115 if (m_A_ihref != NULL)
00116 delete m_A_ihref;
00117 if (m_Description != NULL)
00118 delete m_Description;
00119 if (m_Vendor != NULL)
00120 delete m_Vendor;
00121
00122
00123
00124
00125
00126
00127
00128
00129 }
00130
00135 bool Product::IsValid() const
00136 {
00137 return (m_A_uid != NULL && m_A_name != NULL && m_List_Version.size() > 0);
00138
00139 }
00140
00141 TiXmlElement & Product::XmlElement()
00142 {
00143 TiXmlElement * a_Node = ElementName::m_Node;
00144
00145 assert(a_Node != NULL);
00146
00147 ElementName::XmlElement(*a_Node);
00148 ElementLicense::XmlElement(*a_Node);
00149 ElementUid::XmlElement(*a_Node);
00150
00151 if (m_A_href != NULL)
00152 m_A_href->XmlElement(*a_Node);
00153
00154 if (m_A_ihref != NULL)
00155 m_A_ihref->XmlElement(*a_Node);
00156
00157 if (m_Description != NULL)
00158 a_Node->InsertEndChild(m_Description->XmlElement());
00159
00160 if (m_Vendor != NULL)
00161 a_Node->InsertEndChild(m_Vendor->XmlElement());
00162
00163 for (size_t i = 0; i < m_List_Version.size();i++)
00164 {
00165 a_Node->InsertEndChild(m_List_Version[i].XmlElement());
00166 }
00167
00168 return *a_Node;
00169 }
00170
00171 bool Product::IsOldVersion(const std::string & the_version_to_check) const
00172 {
00173 bool result = false;
00174 for (size_t i = 0; i < m_List_Version.size();i++)
00175 {
00176
00177 const Version & tmpVer = m_List_Version[i];
00178 }
00179
00180 return result;
00181 }
00182
00188 const Version *Product::GetLatestVersion()
00189 {
00190 if (m_List_Version.size() == 0)
00191 {
00192 return NULL;
00193 }
00194
00195
00196
00197 m_List_Version.sort();
00198
00199 return &(m_List_Version[0]);
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 }
00214
00220 Product & Product::operator+=(const Product & the_object_to_add)
00221 {
00222 assert(IsValid());
00223
00224 if (the_object_to_add.IsValid())
00225 {
00226 assert(the_object_to_add.UID()->String().compare(m_A_uid->String()) == 0);
00227
00228
00229 static_cast<ElementName&>(*this) += the_object_to_add;
00230 static_cast<ElementLicense&>(*this) += the_object_to_add;
00231 static_cast<ElementUid&>(*this) += the_object_to_add;
00232
00233
00234 if (the_object_to_add.m_A_href != NULL)
00235 {
00236 if (m_A_href == NULL)
00237 {
00238 delete m_A_href;
00239 }
00240 m_A_href = new Attribute(*the_object_to_add.m_A_href);
00241 }
00242
00243 if (the_object_to_add.m_A_ihref != NULL)
00244 {
00245 if (m_A_ihref == NULL)
00246 {
00247 delete m_A_ihref;
00248 }
00249 m_A_ihref = new Attribute(*the_object_to_add.m_A_ihref);
00250 }
00251
00252
00253 if (the_object_to_add.m_Description != NULL)
00254 {
00255 if (m_Description == NULL)
00256 {
00257 delete m_Description;
00258 }
00259 m_Description = new Description(*the_object_to_add.m_Description);
00260 }
00261
00262 if (the_object_to_add.m_Vendor != NULL)
00263 {
00264 if (m_Vendor == NULL)
00265 {
00266 delete m_Vendor;
00267 }
00268 m_Vendor = new Vendor(*the_object_to_add.m_Vendor);
00269 }
00270
00271
00272 size_t i = 0;
00273 Version * tmpFoundVersion;
00274 while (i < the_object_to_add.m_List_Version.size())
00275 {
00276 tmpFoundVersion = FindVersion(the_object_to_add.m_List_Version[i].NameString());
00277 if (tmpFoundVersion == NULL)
00278 {
00279
00280 Version * tmpText = new Version(the_object_to_add.m_List_Version[i]);
00281 m_List_Version.push_back(tmpText);
00282 }
00283 else
00284 {
00285
00286 *tmpFoundVersion += the_object_to_add.m_List_Version[i];
00287 }
00288
00289 i++;
00290 }
00291 }
00292
00293 return *this;
00294 }
00295
00299 Version * Product::FindVersion(const std::string & the_version_name)
00300 {
00301 size_t current_version = 0;
00302
00303 while (current_version < m_List_Version.size() &&
00304 m_List_Version[current_version].Name() != NULL &&
00305 m_List_Version[current_version].NameString().compare(the_version_name) != 0)
00306 {
00307 current_version++;
00308 }
00309
00310 if (current_version < m_List_Version.size())
00311 return &m_List_Version[current_version];
00312 else
00313 return NULL;
00314 }
00315
00338 void Product::Iterate_Version_Begin()
00339 {
00340 m_Iterator_Version = 0;
00341 }
00342
00346 bool Product::Iterate_Version_IsBegin()
00347 {
00348 return (m_Iterator_Version == 0);
00349 }
00350
00354 bool Product::Iterate_Version_IsEnd()
00355 {
00356 return (m_Iterator_Version == m_List_Version.size() - 1);
00357 }
00358
00362 const std::string & Product::Iterate_Version_Next()
00363 {
00364 return m_List_Version[m_Iterator_Version++].Name()->String();
00365 }
00366
00370 const std::string & Product::Iterate_Version_Prev()
00371 {
00372 return m_List_Version[m_Iterator_Version--].Name()->String();
00373 }