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 "license.h"
00048 #include "package.h"
00049 #include "dependency.h"
00050 #include "notes.h"
00051 #include "changes.h"
00052 #include "dversion.h"
00053 #include "bugfix.h"
00054 #include "feature.h"
00055 #include "improvement.h"
00056
00057 #include "version.h"
00058
00059 using namespace libsvx;
00060
00064 Version::Version(TiXmlElement & Element)
00065 :ElementName(Element,"version")
00066 ,ElementLicense(Element,"version")
00067 ,m_A_type(NULL)
00068 ,m_A_date(NULL)
00069 ,m_A_previous(NULL)
00070 ,m_Dependency(NULL)
00071 ,m_Notes(NULL)
00072 ,m_Changes(NULL)
00073 {
00074 assert(Element.Value().compare("version") == 0);
00075
00076
00077 if (Element.Attribute("type") != NULL)
00078 {
00079 m_A_type = new Attribute(*Element.Attribute("type"),"type");
00080 }
00081 else
00082 {
00083 m_A_type = new Attribute("retail","type");
00084 }
00085
00086 if (Element.Attribute("date") != NULL)
00087 {
00088 m_A_date = new Attribute(*Element.Attribute("date"),"date");
00089 }
00090
00091 if (Element.Attribute("previous") != NULL)
00092 {
00093 m_A_previous = new Attribute(*Element.Attribute("previous"),"previous");
00094 }
00095
00096
00097 if (Element.FirstChildElement("dependency") != NULL)
00098 {
00099 m_Dependency = new Dependency(*Element.FirstChildElement("dependency"));
00100 }
00101
00102 if (Element.FirstChildElement("notes") != NULL)
00103 {
00104 m_Notes = new Notes(*Element.FirstChildElement("notes"));
00105 }
00106
00107 if (Element.FirstChildElement("changes") != NULL)
00108 {
00109 m_Changes = new Changes(*Element.FirstChildElement("changes"));
00110 }
00111
00112 TiXmlElement * txIterator;
00113
00114 m_List_Package.clear();
00115 txIterator = Element.FirstChildElement("package");
00116
00117 while (txIterator != NULL)
00118 {
00119 Package * tmpText = new Package(*txIterator);
00120 m_List_Package.push_back(tmpText);
00121 txIterator = txIterator->NextSiblingElement("package");
00122 }
00123 }
00124
00128 Version::Version(const Version & a_version)
00129 :ElementName(a_version)
00130 ,ElementLicense(a_version)
00131 ,m_A_type(NULL)
00132 ,m_A_date(NULL)
00133 ,m_A_previous(NULL)
00134 ,m_Dependency(NULL)
00135 ,m_Notes(NULL)
00136 ,m_Changes(NULL)
00137 {
00138 if (a_version.m_A_type != NULL)
00139 m_A_type = new Attribute(*a_version.m_A_type);
00140
00141 if (a_version.m_A_date != NULL)
00142 m_A_date = new Attribute(*a_version.m_A_date);
00143
00144 if (a_version.m_A_previous != NULL)
00145 m_A_previous = new Attribute(*a_version.m_A_previous);
00146
00147 if (a_version.m_Dependency != NULL)
00148 m_Dependency = new Dependency(*a_version.m_Dependency);
00149
00150 if (a_version.m_Notes != NULL)
00151 m_Notes = new Notes(*a_version.m_Notes);
00152
00153 if (a_version.m_Changes != NULL)
00154 m_Changes = new Changes(*a_version.m_Changes);
00155
00156 for (size_t i = 0; i < a_version.m_List_Package.size();i++)
00157 {
00158 Package * tmpText = new Package(a_version.m_List_Package[i]);
00159 m_List_Package.push_back(tmpText);
00160 }
00161 }
00162
00166 Version::~Version()
00167 {
00168 if (m_A_type != NULL)
00169 delete m_A_type;
00170 if (m_A_date != NULL)
00171 delete m_A_date;
00172 if (m_A_previous != NULL)
00173 delete m_A_previous;
00174 if (m_Dependency != NULL)
00175 delete m_Dependency;
00176 if (m_Notes != NULL)
00177 delete m_Notes;
00178 if (m_Changes != NULL)
00179 delete m_Changes;
00180
00181
00182
00183
00184
00185
00186
00187
00188 }
00189
00193 bool Version::IsValid() const
00194 {
00195 return (m_A_name != NULL &&
00196 (m_A_type->String().compare("retail") == 0 ||
00197 m_A_type->String().compare("eval") == 0 ||
00198 m_A_type->String().compare("beta") == 0 ||
00199 m_A_type->String().compare("alpha") == 0 ||
00200 m_A_type->String().compare("todo") == 0));
00201 }
00202
00203 TiXmlElement & Version::XmlElement()
00204 {
00205 TiXmlElement * a_Node = ElementName::m_Node;
00206
00207 ElementName::XmlElement(*a_Node);
00208
00209 ElementLicense::XmlElement(*a_Node);
00210
00211 if (m_A_type != NULL)
00212 m_A_type->XmlElement(*a_Node);
00213
00214 if (m_A_date != NULL)
00215 m_A_date->XmlElement(*a_Node);
00216
00217 if (m_A_previous != NULL)
00218 m_A_previous->XmlElement(*a_Node);
00219
00220 if (m_Dependency != NULL)
00221 a_Node->InsertEndChild(m_Dependency->XmlElement());
00222
00223 if (m_Notes != NULL)
00224 a_Node->InsertEndChild(m_Notes->XmlElement());
00225
00226 if (m_Changes != NULL)
00227 a_Node->InsertEndChild(m_Changes->XmlElement());
00228
00229 for (size_t i = 0; i < m_List_Package.size();i++)
00230 {
00231 a_Node->InsertEndChild(m_List_Package[i].XmlElement());
00232 }
00233
00234 return *a_Node;
00235 }
00236
00240 Package * Version::FindPackage(const Package & the_item) const
00241 {
00242 size_t current_version = 0;
00243
00244 while (current_version < m_List_Package.size() &&
00245 m_List_Package[current_version] != the_item)
00246 {
00247 current_version++;
00248 }
00249
00250 if (current_version < m_List_Package.size())
00251 return &m_List_Package[current_version];
00252 else
00253 return NULL;
00254 }
00255
00256 Version & Version::operator+=(const Version & the_object_to_add)
00257 {
00258 assert(IsValid());
00259
00260 if (the_object_to_add.IsValid())
00261 {
00262
00263 static_cast<ElementName&>(*this) += the_object_to_add;
00264 static_cast<ElementLicense&>(*this) += the_object_to_add;
00265
00266
00267 if (the_object_to_add.m_A_date != NULL)
00268 {
00269 if (m_A_date == NULL)
00270 {
00271 delete m_A_date;
00272 }
00273 m_A_date = new Attribute(*the_object_to_add.m_A_date);
00274 }
00275
00276 if (the_object_to_add.m_A_previous != NULL)
00277 {
00278 if (m_A_previous == NULL)
00279 {
00280 delete m_A_previous;
00281 }
00282 m_A_previous = new Attribute(*the_object_to_add.m_A_previous);
00283 }
00284
00285 if (the_object_to_add.m_A_type != NULL)
00286 {
00287 if (m_A_type == NULL)
00288 {
00289 delete m_A_type;
00290 }
00291 m_A_type = new Attribute(*the_object_to_add.m_A_type);
00292 }
00293
00294
00295 if (the_object_to_add.m_Changes != NULL)
00296 {
00297 if (m_Changes == NULL)
00298 {
00299 delete m_Changes;
00300 }
00301 m_Changes = new Changes(*the_object_to_add.m_Changes);
00302 }
00303
00304 if (the_object_to_add.m_Dependency != NULL)
00305 {
00306 if (m_Dependency == NULL)
00307 {
00308 delete m_Dependency;
00309 }
00310 m_Dependency = new Dependency(*the_object_to_add.m_Dependency);
00311 }
00312
00313 if (the_object_to_add.m_Notes != NULL)
00314 {
00315 if (m_Notes == NULL)
00316 {
00317 delete m_Notes;
00318 }
00319 m_Notes = new Notes(*the_object_to_add.m_Notes);
00320 }
00321
00322
00323 size_t i = 0;
00324 Package * tmpFoundPackage;
00325 while (i < the_object_to_add.m_List_Package.size())
00326 {
00327 tmpFoundPackage = FindPackage(the_object_to_add.m_List_Package[i]);
00328 if (tmpFoundPackage == NULL)
00329 {
00330
00331 Package * tmpText = new Package(the_object_to_add.m_List_Package[i]);
00332 m_List_Package.push_back(tmpText);
00333 }
00334 else
00335 {
00336
00337 *tmpFoundPackage += the_object_to_add.m_List_Package[i];
00338 }
00339
00340 i++;
00341 }
00342 }
00343
00344 return *this;
00345 }
00346
00351 bool Version::operator!=(const Version & the_object_to_compare) const
00352 {
00353 bool result = !(IsValid() && the_object_to_compare.IsValid());
00354
00355 result = result || (static_cast<const ElementName&>(*this) != the_object_to_compare);
00356 result = result || (static_cast<const ElementLicense&>(*this) != the_object_to_compare);
00357
00358 if (!result)
00359 {
00360 if (m_A_type != NULL && the_object_to_compare.m_A_type != NULL)
00361 result = result || (*m_A_type != *the_object_to_compare.m_A_type);
00362
00363 if (m_A_date != NULL && the_object_to_compare.m_A_date != NULL)
00364 result = result || (*m_A_date != *the_object_to_compare.m_A_date);
00365
00366 if (m_Changes != NULL && the_object_to_compare.m_Changes != NULL)
00367 result = result || (*m_Changes != *the_object_to_compare.m_Changes);
00368
00369 if (m_Dependency != NULL && the_object_to_compare.m_Dependency != NULL)
00370 result = result || (*m_Dependency != *the_object_to_compare.m_Dependency);
00371
00372 if (m_Notes != NULL && the_object_to_compare.m_Notes != NULL)
00373 result = result || (*m_Notes != *the_object_to_compare.m_Notes);
00374 }
00375
00376 return result;
00377 }
00378
00383 bool Version::operator<(const Version & the_object_to_compare) const
00384 {
00385 return (the_object_to_compare.m_A_previous->String().compare(NameString()) == 0);
00386 }