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

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 "attribute.h"
00047 
00048 #include "text.h"
00049 
00050 using namespace libsvx;
00051 
00054 Text::Text(TiXmlElement & Element)
00055  :ElementPCData(Element,"text")
00056  ,m_A_lang(NULL)
00057 {
00058   assert(Element.Value().compare("text") == 0);
00059 
00060   if (Element.Attribute("lang") != NULL)
00061   {
00062     m_A_lang = new Attribute(*Element.Attribute("lang"),"lang");
00063   }
00064   else
00065   {
00066     m_A_lang = new Attribute("en","lang");
00067   }
00068 
00069   if (Element.Attribute("ctype") != NULL)
00070   {
00071     m_A_ctype = new Attribute(*Element.Attribute("ctype"),"ctype");
00072   }
00073   else
00074   {
00075     m_A_ctype = new Attribute("text/plain","ctype");
00076   }
00077 }
00078 
00079 Text::Text(const Text & a_text)
00080  :ElementPCData(a_text)
00081 {
00082   if (a_text.m_A_ctype != NULL)
00083     m_A_ctype = new Attribute(*a_text.m_A_ctype);
00084   else
00085     m_A_ctype = NULL;
00086 
00087   if (a_text.m_A_lang != NULL)
00088     m_A_lang = new Attribute(*a_text.m_A_lang);
00089   else
00090     m_A_lang = NULL;
00091 }
00092 
00096 Text::~Text()
00097 {
00098   if (m_A_lang != NULL)
00099     delete m_A_lang;
00100   if (m_A_ctype != NULL)
00101     delete m_A_ctype;
00102 }
00103 
00108 bool Text::IsValid() const
00109 {
00110   return true;
00111 }
00112 
00113 TiXmlElement & Text::XmlElement()
00114 {
00115   assert(m_Node != NULL);
00116 
00117   ElementPCData::XmlElement();
00118 
00119   if (m_A_lang != NULL)
00120     m_A_lang->XmlElement(*m_Node);
00121 
00122   if (m_A_ctype != NULL)
00123     m_A_ctype->XmlElement(*m_Node);
00124 
00125   return *m_Node;
00126 }
00127 
00128 bool Text::operator!=(const Text & the_object_to_compare) const
00129 {
00130   bool result = !(IsValid() && the_object_to_compare.IsValid());
00131 
00132   // any of the following cases should never happen
00133   result = result || (m_A_ctype == NULL && the_object_to_compare.m_A_ctype != NULL);
00134   result = result || (m_A_ctype != NULL && the_object_to_compare.m_A_ctype == NULL);
00135   result = result || (m_A_lang == NULL && the_object_to_compare.m_A_lang != NULL);
00136   result = result || (m_A_lang != NULL && the_object_to_compare.m_A_lang == NULL);
00137   result = result || (static_cast<const ElementPCData&>(*this) != the_object_to_compare);
00138   
00139   if (!result)
00140   {
00141     if (m_A_ctype != NULL && the_object_to_compare.m_A_ctype != NULL)
00142       result = result || (*m_A_ctype != *the_object_to_compare.m_A_ctype);
00143 
00144     if (m_A_lang != NULL && the_object_to_compare.m_A_lang != NULL)
00145       result = result || (*m_A_lang != *the_object_to_compare.m_A_lang);
00146   }
00147 
00148   return result;
00149 }
00150 
00151 Text & Text::operator+=(const Text & the_object_to_add)
00152 {
00153   assert(IsValid());
00154 
00155   if (the_object_to_add.IsValid())
00156   {
00157     static_cast<ElementPCData&>(*this) += the_object_to_add;
00158 
00159     // attributes
00160     if (the_object_to_add.m_A_lang != NULL)
00161     {
00162       if (m_A_lang == NULL)
00163       {
00164         delete m_A_lang;
00165       }
00166       m_A_lang = new Attribute(*the_object_to_add.m_A_lang);
00167     }
00168 
00169     if (the_object_to_add.m_A_ctype != NULL)
00170     {
00171       if (m_A_ctype == NULL)
00172       {
00173         delete m_A_ctype;
00174       }
00175       m_A_ctype = new Attribute(*the_object_to_add.m_A_ctype);
00176     }
00177   }
00178 
00179   return *this;
00180 }

Generated on Sat Apr 13 15:45:48 2002 for libsvx by doxygen1.2.15