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

mirrors.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 "url.h"
00048 
00049 #include "mirrors.h"
00050 
00051 using namespace libsvx;
00052 
00055 Mirrors::Mirrors(TiXmlElement & a_Element)
00056  :Element(a_Element,"mirrors")
00057  ,m_A_country(NULL)
00058 {
00059   assert(a_Element.Value().compare("mirrors") == 0);
00060 
00061   // attributes
00062   if (a_Element.Attribute("country") != NULL)
00063   {
00064     m_A_country = new Attribute(*a_Element.Attribute("country"),"country");
00065   }
00066 
00067   TiXmlElement * txIterator;
00068 
00069   m_List_Url.clear();
00070   txIterator = a_Element.FirstChildElement("url");
00071 
00072   while (txIterator != NULL)
00073   {
00074     Url * tmpUrl = new Url(*txIterator);
00075     m_List_Url.push_back(tmpUrl);
00076     txIterator = txIterator->NextSiblingElement("url");
00077   }
00078 }
00079 
00080 Mirrors::Mirrors(const Mirrors & a_element)
00081  :Element(a_element)
00082 {
00083   if (a_element.m_A_country != NULL)
00084     m_A_country = new Attribute(*a_element.m_A_country);
00085   else
00086     m_A_country = a_element.m_A_country;
00087 
00088   for (size_t i = 0; i < a_element.m_List_Url.size();i++)
00089   {
00090     Url * tmpText = new Url(a_element.m_List_Url[i]);
00091     m_List_Url.push_back(tmpText);
00092   }
00093 }
00094 
00098 Mirrors::~Mirrors()
00099 {
00100   if (m_A_country != NULL)
00101     delete m_A_country;
00102 /* done automatically
00103   while (m_List_Url.size() != 0)
00104   {
00105     Url * tmp = m_List_Url.front();
00106     m_List_Url.pop_front();
00107     delete tmp;
00108   }
00109 */
00110 }
00111 
00116 bool Mirrors::IsValid() const
00117 {
00118   return (m_List_Url.size() > 0);
00119 }
00120 
00121 TiXmlElement & Mirrors::XmlElement()
00122 {
00123   if (m_A_country != NULL)
00124     m_A_country->XmlElement(*m_Node);
00125 
00126   for (size_t i = 0; i < m_List_Url.size();i++)
00127   {
00128     m_Node->InsertEndChild(m_List_Url[i].XmlElement());
00129   }
00130   
00131   return *m_Node;
00132 }
00133 
00137 bool Mirrors::operator!=(const Mirrors & the_object_to_compare) const
00138 {
00139   bool result = !(IsValid() && the_object_to_compare.IsValid());
00140   
00141   // any of the following cases should never happen
00142   
00143   if (!result)
00144   {
00145     result = result || (static_cast<const Element&>(*this) != the_object_to_compare);
00146     
00147     if (m_A_country != NULL && the_object_to_compare.m_A_country != NULL)
00148       result = result || (*m_A_country != *the_object_to_compare.m_A_country);
00149   }
00150 
00151   return result;
00152 }
00153 
00157 Url * Mirrors::FindUrl(const Url & the_item) const
00158 {
00159   size_t current = 0;
00160 
00161   while (current < m_List_Url.size() && m_List_Url[current] != the_item)
00162   {
00163     current++;
00164   }
00165 
00166   if (current < m_List_Url.size())
00167     return &m_List_Url[current];
00168   else
00169     return NULL;
00170 }
00175 Mirrors & Mirrors::operator+=(const Mirrors & the_object_to_add)
00176 {
00177   assert(IsValid());
00178 
00179   if (the_object_to_add.IsValid())
00180   {
00181 //    assert(the_object_to_add.UID()->String().compare(m_A_uid->String()) == 0);
00182     
00183     // hierarchy classes
00184     static_cast<Element&>(*this) += the_object_to_add;
00185 
00186     // attributes
00187     if (the_object_to_add.m_A_country != NULL)
00188     {
00189       if (m_A_country == NULL)
00190       {
00191         delete m_A_country;
00192       }
00193       m_A_country = new Attribute(*the_object_to_add.m_A_country);
00194     }
00195 
00196     // lists
00197     size_t i = 0;
00198     Url * tmpFound;
00199     while (i < the_object_to_add.m_List_Url.size())
00200     {
00201       tmpFound = FindUrl(the_object_to_add.m_List_Url[i]);
00202       if (tmpFound == NULL)
00203       {
00204         // add this version to the list
00205         Url * tmpText = new Url(the_object_to_add.m_List_Url[i]);
00206         m_List_Url.push_back(tmpText);
00207       }
00208       else
00209       {
00210         // merge the same versions
00211         *tmpFound += the_object_to_add.m_List_Url[i];
00212       }
00213 
00214       i++;
00215     }
00216   }
00217 
00218   return *this;
00219 }

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