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

package.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 "../tinyxml/tinyxml.h"
00045 
00046 #include "attribute.h"
00047 #include "activation.h"
00048 #include "license.h"
00049 #include "mirrors.h"
00050 #include "verification.h"
00051 
00052 #include "package.h"
00053 
00054 using namespace libsvx;
00055 
00058 Package::Package(TiXmlElement & Element)
00059  :ElementText(Element,"package")
00060  ,ElementLicense(Element,"package")
00061  ,ElementDownloadable(Element,"package")
00062  ,m_Verification(NULL)
00063  ,m_A_size(NULL)
00064  ,m_A_type(NULL)
00065  ,m_A_os(NULL)
00066  ,m_A_cpu(NULL)
00067  ,m_A_lang(NULL)
00068 {
00069   assert(Element.Value().compare("package") == 0);
00070 
00071   // attributes
00072   if (Element.Attribute("size") != NULL)
00073   {
00074     m_A_size = new Attribute(*Element.Attribute("size"),"size");
00075   }
00076 
00077   if (Element.Attribute("type") != NULL)
00078   {
00079     m_A_type = new Attribute(*Element.Attribute("type"),"type");
00080   }
00081 
00082   if (Element.Attribute("os") != NULL)
00083   {
00084     m_A_os = new Attribute(*Element.Attribute("os"),"os");
00085   }
00086   else
00087   {
00088     m_A_os = new Attribute("win32","os");
00089   }
00090 
00091   if (Element.Attribute("cpu") != NULL)
00092   {
00093     m_A_cpu = new Attribute(*Element.Attribute("cpu"),"cpu");
00094   }
00095   else
00096   {
00097     m_A_cpu = new Attribute("x86","cpu");
00098   }
00099 
00100   if (Element.Attribute("lang") != NULL)
00101   {
00102     m_A_lang = new Attribute(*Element.Attribute("lang"),"lang");
00103   }
00104   else
00105   {
00106     m_A_lang = new Attribute("en","lang");
00107   }
00108 
00109   // elements
00110   if (Element.FirstChildElement("verification") != NULL)
00111   {
00112     m_Verification = new Verification(*Element.FirstChildElement("verification"));
00113   }
00114 
00115   TiXmlElement * txIterator;
00116   
00117   m_List_Activation.clear();
00118   txIterator = Element.FirstChildElement("activation");
00119   while (txIterator != NULL)
00120   {
00121     Activation * tmpText = new Activation(*txIterator);
00122     m_List_Activation.push_back(tmpText);
00123     txIterator = txIterator->NextSiblingElement("activation");
00124   }
00125 }
00126 
00127 Package::Package(const Package & a_package)
00128  :ElementText(a_package)
00129  ,ElementLicense(a_package)
00130  ,ElementDownloadable(a_package)
00131 {
00132   m_Verification = a_package.m_Verification;
00133   if (a_package.m_A_size != NULL)
00134     m_A_size = new Attribute(*a_package.m_A_size);
00135   else
00136     m_A_size = a_package.m_A_size;
00137 
00138   if (a_package.m_A_type != NULL)
00139     m_A_type = new Attribute(*a_package.m_A_type);
00140   else
00141     m_A_type = a_package.m_A_type;
00142 
00143   if (a_package.m_A_os != NULL)
00144     m_A_os = new Attribute(*a_package.m_A_os);
00145   else
00146     m_A_os = a_package.m_A_os;
00147 
00148   if (a_package.m_A_cpu != NULL)
00149     m_A_cpu = new Attribute(*a_package.m_A_cpu);
00150   else
00151     m_A_cpu = a_package.m_A_cpu;
00152 
00153   if (a_package.m_A_lang != NULL)
00154     m_A_lang = new Attribute(*a_package.m_A_lang);
00155   else
00156     m_A_lang = a_package.m_A_lang;
00157 
00158   for (size_t i = 0; i < a_package.m_List_Activation.size();i++)
00159   {
00160     Activation * tmpText = new Activation(a_package.m_List_Activation[i]);
00161     m_List_Activation.push_back(tmpText);
00162   }
00163 }
00164 
00168 Package::~Package()
00169 {
00170   if (m_Verification != NULL)
00171     delete m_Verification;
00172   if (m_A_size != NULL)
00173     delete m_A_size;
00174   if (m_A_type != NULL)
00175     delete m_A_type;
00176   if (m_A_os != NULL)
00177     delete m_A_os;
00178   if (m_A_cpu != NULL)
00179     delete m_A_cpu;
00180   if (m_A_lang != NULL)
00181     delete m_A_lang;
00182 /* done automatically
00183   while (m_List_Activation.size() != 0)
00184   {
00185     Activation * tmp = m_List_Activation.front();
00186     m_List_Activation.pop_front();
00187     delete tmp;
00188   }
00189 */
00190 }
00191 
00195 bool Package::IsValid() const
00196 {
00197   return (m_List_Activation.size() > 0 && m_List_Mirrors.size() > 0 &&
00198     m_A_type != NULL &&
00199     (m_A_type->String().compare("binary") == 0 || m_A_type->String().compare("source") == 0) && 
00200     (m_A_os == NULL || m_A_os->String().compare("win32") == 0 ||
00201                        m_A_os->String().compare("win95") == 0 ||
00202                        m_A_os->String().compare("winNT") == 0 ||
00203                        m_A_os->String().compare("win2K") == 0 ||
00204                        m_A_os->String().compare("winXP") == 0 ||
00205                        m_A_os->String().compare("Linux") == 0 ||
00206                        m_A_os->String().compare("MacOS") == 0 ||
00207                        m_A_os->String().compare("MacOSX") == 0 ||
00208                        m_A_os->String().compare("DOS") == 0 ||
00209                        m_A_os->String().compare("BSD") == 0 ||
00210                        m_A_os->String().compare("OS2") == 0 ||
00211                        m_A_os->String().compare("Solaris") == 0 ||
00212                        m_A_os->String().compare("SunOS") == 0 ||
00213                        m_A_os->String().compare("none") == 0) && 
00214     (m_A_cpu == NULL || m_A_cpu->String().compare("x86") == 0 ||
00215                         m_A_cpu->String().compare("IA64") == 0 ||
00216                         m_A_cpu->String().compare("AMD64") == 0 ||
00217                         m_A_cpu->String().compare("mips") == 0 ||
00218                         m_A_cpu->String().compare("alpha") == 0 ||
00219                         m_A_cpu->String().compare("ppc") == 0 ||
00220                         m_A_cpu->String().compare("sparc") == 0 ||
00221                         m_A_cpu->String().compare("680x0") == 0 ||
00222                         m_A_cpu->String().compare("none") == 0)
00223     );
00224 }
00225 
00226 TiXmlElement & Package::XmlElement()
00227 {
00228   TiXmlElement * a_Node = ElementText::m_Node;
00229 
00230   ElementText::XmlElement(*a_Node);
00231   ElementLicense::XmlElement(*a_Node);
00232   ElementDownloadable::XmlElement(*a_Node);
00233 
00234   if (m_A_size != NULL)
00235     m_A_size->XmlElement(*a_Node);
00236 
00237   if (m_A_type != NULL)
00238     m_A_type->XmlElement(*a_Node);
00239 
00240   if (m_A_os != NULL)
00241     m_A_os->XmlElement(*a_Node);
00242 
00243   if (m_A_cpu != NULL)
00244     m_A_cpu->XmlElement(*a_Node);
00245 
00246   if (m_A_lang != NULL)
00247     m_A_lang->XmlElement(*a_Node);
00248 
00249   if (m_Verification != NULL)
00250     a_Node->InsertEndChild(m_Verification->XmlElement());
00251 
00252   for (size_t i = 0; i < m_List_Activation.size();i++)
00253   {
00254     a_Node->InsertEndChild(m_List_Activation[i].XmlElement());
00255   }
00256   
00257   return *a_Node;
00258 }
00259 
00263 bool Package::operator!=(const Package & the_object_to_compare) const
00264 {
00265   bool result = !(IsValid() && the_object_to_compare.IsValid());
00266 
00267   // any of the following cases should never happen
00268 
00269   result = result || (static_cast<const ElementDownloadable&>(*this) != the_object_to_compare);
00270   result = result || (static_cast<const ElementText&>(*this) != the_object_to_compare);
00271   result = result || (static_cast<const ElementLicense&>(*this) != the_object_to_compare);
00272   
00273   if (!result)
00274   {
00275     if (m_A_size != NULL && the_object_to_compare.m_A_size != NULL)
00276       result = result || (*m_A_size != *the_object_to_compare.m_A_size);
00277 
00278     if (m_A_type != NULL && the_object_to_compare.m_A_type != NULL)
00279       result = result || (*m_A_type != *the_object_to_compare.m_A_type);
00280     
00281     if (m_A_os != NULL && the_object_to_compare.m_A_os != NULL)
00282       result = result || (*m_A_os != *the_object_to_compare.m_A_os);
00283 
00284     if (m_A_cpu != NULL && the_object_to_compare.m_A_cpu != NULL)
00285       result = result || (*m_A_cpu != *the_object_to_compare.m_A_cpu);
00286 
00287     if (m_A_lang != NULL && the_object_to_compare.m_A_lang != NULL)
00288       result = result || (*m_A_lang != *the_object_to_compare.m_A_lang);
00289     
00290     if (m_Verification != NULL && the_object_to_compare.m_Verification != NULL)
00291       result = result || (*m_Verification != *the_object_to_compare.m_Verification);
00292   }
00293   
00294   return result;
00295 }
00296 
00300 Package & Package::operator+=(const Package & the_object_to_add)
00301 {
00302   assert(IsValid());
00303 
00304   if (the_object_to_add.IsValid())
00305   {
00306     static_cast<ElementText&>(*this) += the_object_to_add;
00307     static_cast<ElementLicense&>(*this) += the_object_to_add;
00308     static_cast<ElementDownloadable&>(*this) += the_object_to_add;
00309 
00310     // attributes
00311     if (the_object_to_add.m_Verification != NULL)
00312     {
00313       if (m_Verification == NULL)
00314       {
00315         delete m_Verification;
00316       }
00317       m_Verification = new Verification(*the_object_to_add.m_Verification);
00318     }
00319     
00320     if (the_object_to_add.m_A_size != NULL)
00321     {
00322       if (m_A_size == NULL)
00323       {
00324         delete m_A_size;
00325       }
00326       m_A_size = new Attribute(*the_object_to_add.m_A_size);
00327     }
00328 
00329     if (the_object_to_add.m_A_type != NULL)
00330     {
00331       if (m_A_type == NULL)
00332       {
00333         delete m_A_type;
00334       }
00335       m_A_type = new Attribute(*the_object_to_add.m_A_type);
00336     }
00337 
00338     if (the_object_to_add.m_A_os != NULL)
00339     {
00340       if (m_A_os == NULL)
00341       {
00342         delete m_A_os;
00343       }
00344       m_A_os = new Attribute(*the_object_to_add.m_A_os);
00345     }
00346 
00347     if (the_object_to_add.m_A_cpu != NULL)
00348     {
00349       if (m_A_cpu == NULL)
00350       {
00351         delete m_A_cpu;
00352       }
00353       m_A_cpu = new Attribute(*the_object_to_add.m_A_cpu);
00354     }
00355     
00356     if (the_object_to_add.m_A_lang != NULL)
00357     {
00358       if (m_A_lang == NULL)
00359       {
00360         delete m_A_lang;
00361       }
00362       m_A_lang = new Attribute(*the_object_to_add.m_A_lang);
00363     }
00364   }
00365 
00366   return *this;
00367 }

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