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 "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
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
00103
00104
00105
00106
00107
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
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
00182
00183
00184 static_cast<Element&>(*this) += the_object_to_add;
00185
00186
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
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
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
00211 *tmpFound += the_object_to_add.m_List_Url[i];
00212 }
00213
00214 i++;
00215 }
00216 }
00217
00218 return *this;
00219 }