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

element_downloadable.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 Mirrors
00013 Version 1.0 (the "Mirrors"); you may not use this file in any way except
00014 in compliance with the Mirrors. You should have received a copy of the
00015 Mirrors with this source; see <file or member name>. You may also obtain
00016 a copy of the Mirrors 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 Mirrors is distributed on an "AS IS" basis,
00022 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the Mirrors for
00023 the specific language governing rights and limitations under the Mirrors.
00024 
00025 Definitions required by the Mirrors:
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 "mirrors.h"
00047 #include "url.h"
00048 
00049 #include "element_downloadable.h"
00050 
00051 using namespace libsvx;
00052 
00055 ElementDownloadable::ElementDownloadable(TiXmlElement & Element, const std::string the_name)
00056  :ElementGeneric(Element,the_name)
00057 {
00058   //elements
00059   m_List_Mirrors.clear();
00060   TiXmlElement * txIterator = Element.FirstChildElement("mirrors");
00061 
00062   while (txIterator != NULL)
00063   {
00064     Mirrors * tmpText = new Mirrors(*txIterator);
00065     m_List_Mirrors.push_back(tmpText);
00066     txIterator = txIterator->NextSiblingElement("mirrors");
00067   }
00068 }
00069 
00070 ElementDownloadable::ElementDownloadable(const ElementDownloadable & a_element)
00071  :ElementGeneric(a_element)
00072 {
00073   for (size_t i = 0; i < a_element.m_List_Mirrors.size();i++)
00074   {
00075     Mirrors * tmpText = new Mirrors(a_element.m_List_Mirrors[i]);
00076     m_List_Mirrors.push_back(tmpText);
00077   }
00078 }
00079 
00083 ElementDownloadable::~ElementDownloadable()
00084 {
00085 /* done automatically
00086   while (m_List_Mirrors.size() != 0)
00087   {
00088     Mirrors * tmp = m_List_Mirrors.front();
00089     m_List_Mirrors.pop_front();
00090     delete tmp;
00091   }
00092 */
00093 }
00094 
00098 bool ElementDownloadable::IsValid() const
00099 {
00100   return true;
00101 }
00102 
00103 
00104 void ElementDownloadable::XmlElement(TiXmlElement & the_element_to_fill)
00105 {
00106   for (size_t i = 0; i < m_List_Mirrors.size();i++)
00107   {
00108     the_element_to_fill.InsertEndChild(m_List_Mirrors[i].XmlElement());
00109   }
00110 }
00111 
00115 Mirrors * ElementDownloadable::FindMirrors(const Mirrors & the_item) const
00116 {
00117   size_t current_version = 0;
00118 
00119   while (current_version < m_List_Mirrors.size() &&
00120        m_List_Mirrors[current_version] != the_item)
00121   {
00122     current_version++;
00123   }
00124 
00125   if (current_version < m_List_Mirrors.size())
00126     return &m_List_Mirrors[current_version];
00127   else
00128     return NULL;
00129 }
00130 
00131 ElementDownloadable & ElementDownloadable::operator+=(const ElementDownloadable & the_object_to_add)
00132 {
00133   assert(IsValid());
00134 
00135   if (the_object_to_add.IsValid())
00136   {
00137     // hierarchy classes
00138     *static_cast<ElementGeneric*>(this) += the_object_to_add;
00139 
00140     // lists
00141     size_t i = 0;
00142     Mirrors * tmpFoundMirrors;
00143     while (i < the_object_to_add.m_List_Mirrors.size())
00144     {
00145       tmpFoundMirrors = FindMirrors(the_object_to_add.m_List_Mirrors[i]);
00146       if (tmpFoundMirrors == NULL)
00147       {
00148         // add this version to the list
00149         Mirrors * tmpMirrors = new Mirrors(the_object_to_add.m_List_Mirrors[i]);
00150         m_List_Mirrors.push_back(tmpMirrors);
00151       }
00152       else
00153       {
00154         // merge the same versions
00155         *tmpFoundMirrors += the_object_to_add.m_List_Mirrors[i];
00156       }
00157 
00158       i++;
00159     }
00160   }
00161 
00162   return *this;
00163 }
00164 
00168 bool ElementDownloadable::operator!=(const ElementDownloadable & the_object_to_compare) const
00169 {
00170   bool result = !(IsValid() && the_object_to_compare.IsValid());
00171 
00172   result = result || (static_cast<const ElementGeneric &>(*this) != the_object_to_compare);
00173 
00174   return result;
00175 }

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