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

svx.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 "product.h"
00048 
00049 #include "svx.h"
00050 
00051 using namespace libsvx;
00052 
00053 static std::string NullString = "";
00054 
00057 Svx::Svx(TiXmlElement & a_Element)
00058  :Element(a_Element,"svx")
00059  ,m_A_href(NULL)
00060  ,m_A_version(NULL)
00061 {
00062   assert(a_Element.Value().compare("svx") == 0);
00063   Add(a_Element);
00064 }
00065 
00069 Svx::~Svx()
00070 {
00071   if (m_A_href != NULL)
00072     delete m_A_href;
00073   if (m_A_version != NULL)
00074     delete m_A_version;
00075 /* done automatically
00076   while (m_List_Product.size() != 0)
00077   {
00078     Product * tmp = m_List_Product.front();
00079     m_List_Product.pop_front();
00080     delete tmp;
00081   }
00082 */
00083 }
00084 
00091 bool Svx::Add(TiXmlElement & Element)
00092 {
00093   bool result = true;
00094 
00095   assert(Element.Value().compare("svx") == 0);
00096 
00097   if (m_A_version != NULL && Element.Attribute("version") != NULL)
00098   {
00099     // should be "1.0"
00100     result = (m_A_version->String().compare(*Element.Attribute("version")) == 0);
00101   }
00102 
00103   if (result)
00104   {
00105     // override the URL
00106     if (Element.Attribute("href") != NULL)
00107     {
00108       if (m_A_href != NULL)
00109         delete m_A_href;
00110       
00111       m_A_href = new Attribute(*Element.Attribute("href"),"href");
00113     }
00114 
00115     // treat all the child Elements and chain them
00116     TiXmlElement * txIterator = Element.FirstChildElement("product");
00117 
00118     while (txIterator != NULL)
00119     {
00120       Product * tmpNewText = new Product(*txIterator);
00121 
00122       Product * tmpFound = FindProduct(tmpNewText->UID()->String());
00123       if (tmpFound == NULL)
00124       {
00125         // this is a new product, add it to the list
00126         m_List_Product.push_back(tmpNewText);
00127       }
00128       else
00129       {
00130         // this is a known product, merge the content with the old one
00131         *tmpFound += *tmpNewText;
00132         delete tmpNewText;
00133       }
00134       
00135       txIterator = txIterator->NextSiblingElement("product");
00136     }
00137   }
00138 
00139   return result;
00140 }
00141 
00145 bool Svx::IsValid() const
00146 {
00147   return (m_List_Product.size() > 0 && m_A_version != NULL && m_A_version->String().compare("1.0") == 0);
00148 }
00149 
00150 TiXmlElement & Svx::XmlElement()
00151 {
00152   assert(m_Node != NULL);
00153 
00154   if (m_A_href != NULL)
00155     m_A_href->XmlElement(*m_Node);
00156 
00157   if (m_A_version != NULL)
00158     m_A_version->XmlElement(*m_Node);
00159 
00160   for (size_t i = 0; i < m_List_Product.size();i++)
00161   {
00162     m_Node->InsertEndChild(m_List_Product[i].XmlElement());
00163   }
00164   
00165   return *m_Node;
00166 }
00167 
00171 Product * Svx::FindProduct(const std::string & the_product_uid) const
00172 {
00173   size_t current_product = 0;
00174 
00175   while (current_product < m_List_Product.size() &&
00176        m_List_Product[current_product].UID() != NULL &&
00177        m_List_Product[current_product].UID()->String().compare(the_product_uid) != 0)
00178   {
00179     current_product++;
00180   }
00181 
00182   if (current_product < m_List_Product.size())
00183     return &m_List_Product[current_product];
00184   else
00185     return NULL;
00186 }
00187 
00191 void Svx::Iterate_Product_Begin()
00192 {
00193   m_Iterator_Product = 0;
00194 }
00195 
00199 bool Svx::Iterate_Product_IsEnd()
00200 {
00201   return (m_Iterator_Product == m_List_Product.size()-1);
00202 }
00203 
00207 const std::string & Svx::Iterate_Product_Next()
00208 {
00209   return m_List_Product[m_Iterator_Product++].UID()->String();
00210 }
00211 
00215 const std::string & Svx::Iterate_Product_Prev()
00216 {
00217   return m_List_Product[m_Iterator_Product--].UID()->String();
00218 }
00219 
00223 Version * Svx::FindVersion(const std::string & the_product_uid, const std::string & the_version_name)
00224 {
00225   Product * the_product = FindProduct(the_product_uid);
00226 
00227   if (the_product == NULL)
00228     return NULL;
00229   else return the_product->FindVersion(the_version_name);
00230 }
00231 
00235 void Svx::Iterate_Version_Begin(const std::string & the_product_uid)
00236 {
00237   Product * the_product = FindProduct(the_product_uid);
00238 
00239   if (the_product != NULL)
00240     the_product->Iterate_Version_Begin();
00241 }
00242 
00246 bool Svx::Iterate_Version_IsBegin(const std::string & the_product_uid)
00247 {
00248   Product * the_product = FindProduct(the_product_uid);
00249 
00250   if (the_product == NULL)
00251     return false;
00252   else
00253     return the_product->Iterate_Version_IsBegin();
00254 }
00255 
00259 bool Svx::Iterate_Version_IsEnd(const std::string & the_product_uid)
00260 {
00261   Product * the_product = FindProduct(the_product_uid);
00262 
00263   if (the_product == NULL)
00264     return false;
00265   else
00266     return the_product->Iterate_Version_IsEnd();
00267 }
00268 
00272 const std::string & Svx::Iterate_Version_Next(const std::string & the_product_uid)
00273 {
00274   Product * the_product = FindProduct(the_product_uid);
00275 
00276   if (the_product == NULL)
00277     return NullString;
00278   else
00279     return the_product->Iterate_Version_Next();
00280 }
00281 
00285 const std::string & Svx::Iterate_Version_Prev(const std::string & the_product_uid)
00286 {
00287   Product * the_product = FindProduct(the_product_uid);
00288 
00289   if (the_product == NULL)
00290     return NullString;
00291   else
00292     return the_product->Iterate_Version_Prev();
00293 }

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