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
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
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
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 }