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

element_text.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 "text.h"
00047 #include "element_text.h"
00048 
00049 using namespace libsvx;
00050 
00053 ElementText::ElementText(TiXmlElement & Element, const std::string the_name)
00054  :ElementGeneric(Element,the_name)
00055 {
00056   //elements
00057   m_List_Text.clear();
00058   TiXmlElement * txIterator = Element.FirstChildElement("text");
00059 
00060   while (txIterator != NULL)
00061   {
00062     Text * tmpText = new Text(*txIterator);
00063     m_List_Text.push_back(tmpText);
00064     txIterator = txIterator->NextSiblingElement("text");
00065   }
00066 }
00067 
00068 ElementText::ElementText(const ElementText & a_element)
00069  :ElementGeneric(a_element)
00070 {
00071   for (size_t i = 0; i < a_element.m_List_Text.size();i++)
00072   {
00073     Text * tmpText = new Text(a_element.m_List_Text[i]);
00074     m_List_Text.push_back(tmpText);
00075   }
00076 }
00077 
00081 ElementText::~ElementText()
00082 {
00083 /* done automatically
00084   while (m_List_Text.size() != 0)
00085   {
00086     Text * tmp = m_List_Text.front();
00087     m_List_Text.pop_front();
00088     delete tmp;
00089   }
00090 */
00091 }
00092 
00096 bool ElementText::IsValid() const
00097 {
00098   return true;
00099 }
00100 
00101 
00102 void ElementText::XmlElement(TiXmlElement & the_element_to_fill)
00103 {
00104   for (size_t i = 0; i < m_List_Text.size();i++)
00105   {
00106     the_element_to_fill.InsertEndChild(m_List_Text[i].XmlElement());
00107   }
00108 }
00109 
00113 Text * ElementText::FindText(const Text & the_item) const
00114 {
00115   size_t current_version = 0;
00116 
00117   while (current_version < m_List_Text.size() &&
00118        m_List_Text[current_version] != the_item)
00119   {
00120     current_version++;
00121   }
00122 
00123   if (current_version < m_List_Text.size())
00124     return &m_List_Text[current_version];
00125   else
00126     return NULL;
00127 }
00128 
00129 ElementText & ElementText::operator+=(const ElementText & the_object_to_add)
00130 {
00131   assert(IsValid());
00132 
00133   if (the_object_to_add.IsValid())
00134   {
00135     // hierarchy classes
00136     static_cast<ElementGeneric&>(*this) += the_object_to_add;
00137 
00138     // lists
00139     size_t i = 0;
00140     Text * tmpFoundText;
00141     while (i < the_object_to_add.m_List_Text.size())
00142     {
00143       tmpFoundText = FindText(the_object_to_add.m_List_Text[i]);
00144       if (tmpFoundText == NULL)
00145       {
00146         // add this version to the list
00147         Text * tmpText = new Text(the_object_to_add.m_List_Text[i]);
00148         m_List_Text.push_back(tmpText);
00149       }
00150       else
00151       {
00152         // merge the same versions
00153         *tmpFoundText += the_object_to_add.m_List_Text[i];
00154       }
00155 
00156       i++;
00157     }
00158   }
00159 
00160   return *this;
00161 }
00165 bool ElementText::operator!=(const ElementText & the_object_to_compare) const
00166 {
00167   bool result = !(IsValid() && the_object_to_compare.IsValid());
00168 
00169   result = result || (static_cast<const ElementGeneric&>(*this) != the_object_to_compare);
00170 
00171   return result;
00172 }

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