Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

product.cxx

Go to the documentation of this file.
00001 /******************************************************************************
00002 
00003                            Copyright Notice.
00004 
00005                Licensed material - Property of Steve Lhomme
00006 
00007 This source file is part of Steve Lhomme's libSVX.
00008 (C) Copyright Steve Lhomme, France, 2001-2002.
00009 All rights reserved. Modifications (C) copyrighted by their respective
00010 contributors, all rights reserved.
00011 
00012 The contents of this file are subject to the Bixoft Public License
00013 Version 1.0 (the "License"); you may not use this file in any way except
00014 in compliance with the License. You should have received a copy of the
00015 License with this source; see <file or member name>. You may also obtain
00016 a copy of the License at http://www.bixoft.nl/english/license.htm
00017 or http://mukoli.free.fr/BXAPL/
00018 
00019 ANY USE OF THE SOFTWARE CONSTITUTES ACCEPTANCE OF THE LICENSE.
00020 
00021 Anything distributed under the License is distributed on an "AS IS" basis,
00022 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
00023 the specific language governing rights and limitations under the License.
00024 
00025 Definitions required by the License:
00026 Copyright Holder: Steve Lhomme, France
00027           e-mail: steve.lhomme@free.fr
00028 Country: France, i.e. the laws of France apply.
00029 Court  : ????
00030 Programming Tool status: This source is not a Programming Tool.
00031 
00032 Contributor(s):                      Contribution:
00033 
00034 ******************************************************************************/
00035 
00044 //#include <algorithm>
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   // attributes
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   // elements
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 /* done automatically
00122   while (m_List_Version.size() != 0)
00123   {
00124     Version & tmp = m_List_Version.back();
00125     m_List_Version.pop_back();
00126     delete tmp;
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 //  return (m_A_name != NULL && m_List_Version.size() > 0);
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 //    a_Node->InsertEndChild((*i)->XmlElement());
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   // sort the versions
00196 //  std::sort(m_List_Version.begin(),m_List_Version.end(),toto);
00197   m_List_Version.sort();
00198   // get the most recent one
00199   return &(m_List_Version[0]);
00200 /*  for (std::list<Version *>::const_iterator i = m_List_Version.begin(); i != m_List_Version.end();i++)
00201   {
00202     if (latest.IsOlder(**i))
00203     {
00204       latest = **i;
00205     }
00206   }
00207 *
00208   if (latest.Name() != NULL)
00209   {
00210     latest_version_name = latest.Name()->String();
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     // hierarchy classes
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     // attributes
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     // parameters
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     // lists
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         // add this version to the list
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         // merge the same versions
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 }

Generated on Sat Apr 13 22:56:50 2002 for libsvx by doxygen1.2.15