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 "mirrors.h"
00048
00049 #include "license.h"
00050
00051 using namespace libsvx;
00052
00055 License::License(TiXmlElement & Element)
00056 :ElementText(Element,"license")
00057 ,ElementDownloadable(Element,"license")
00058 ,m_A_type(NULL)
00059 ,m_A_name(NULL)
00060 {
00061 assert(Element.Value().compare("license") == 0);
00062
00063
00064 if (Element.Attribute("type") != NULL)
00065 {
00066 m_A_type = new Attribute(*Element.Attribute("type"),"type");
00067 }
00068
00069 if (Element.Attribute("name") != NULL)
00070 {
00071 m_A_name = new Attribute(*Element.Attribute("name"),"name");
00072 }
00073 }
00074
00075 License::License(const License & a_license)
00076 :ElementText(a_license)
00077 ,ElementDownloadable(a_license)
00078 {
00079 if (a_license.m_A_type != NULL)
00080 m_A_type = new Attribute(*a_license.m_A_type);
00081 else
00082 m_A_type = NULL;
00083
00084 if (a_license.m_A_name != NULL)
00085 m_A_name = new Attribute(*a_license.m_A_name);
00086 else
00087 m_A_name = NULL;
00088 }
00089
00093 License::~License()
00094 {
00095 if (m_A_type != NULL)
00096 delete m_A_type;
00097 if (m_A_name != NULL)
00098 delete m_A_name;
00099 }
00100
00104 bool License::IsValid() const
00105 {
00106 return (m_A_type != NULL && m_A_name != NULL && (
00107 m_A_name->String().compare("free-software") == 0 ||
00108 m_A_name->String().compare("osi-approved") == 0 ||
00109 m_A_name->String().compare("freeware") == 0 ||
00110 m_A_name->String().compare("commercial") == 0 ||
00111 m_A_name->String().compare("shareware") == 0 ||
00112 m_A_name->String().compare("adware") == 0 ||
00113 m_A_name->String().compare("cardware") == 0
00114 ));
00115 }
00116
00117 TiXmlElement & License::XmlElement()
00118 {
00119 TiXmlElement * a_Node = ElementText::m_Node;
00120
00121 ElementText::XmlElement(*a_Node);
00122
00123 ElementDownloadable::XmlElement(*a_Node);
00124
00125 if (m_A_type != NULL)
00126 m_A_type->XmlElement(*a_Node);
00127
00128 if (m_A_name != NULL)
00129 m_A_name->XmlElement(*a_Node);
00130
00131 return *a_Node;
00132 }
00133
00134 bool License::operator!=(const License & the_object_to_compare) const
00135 {
00136 bool result = !(IsValid() && the_object_to_compare.IsValid());
00137
00138 result = result || (static_cast<const ElementDownloadable&>(*this) != the_object_to_compare);
00139 result = result || (static_cast<const ElementText&>(*this) != the_object_to_compare);
00140 result = result || (m_A_type == NULL && the_object_to_compare.m_A_type != NULL);
00141 result = result || (m_A_type != NULL && the_object_to_compare.m_A_type == NULL);
00142 result = result || (m_A_name == NULL && the_object_to_compare.m_A_name != NULL);
00143 result = result || (m_A_name != NULL && the_object_to_compare.m_A_name == NULL);
00144
00145 if (!result)
00146 {
00147 if (m_A_type != NULL && the_object_to_compare.m_A_type != NULL)
00148 result = result || (*m_A_type != *the_object_to_compare.m_A_type);
00149
00150 if (m_A_name != NULL && the_object_to_compare.m_A_name != NULL)
00151 result = result || (*m_A_name != *the_object_to_compare.m_A_name);
00152 }
00153
00154 return result;
00155 }
00156
00157 License & License::operator+=(const License & the_object_to_add)
00158 {
00159 assert(IsValid());
00160
00161 if (the_object_to_add.IsValid())
00162 {
00163
00164 static_cast<ElementText&>(*this) += the_object_to_add;
00165 static_cast<ElementDownloadable&>(*this) += the_object_to_add;
00166
00167
00168 if (the_object_to_add.m_A_type != NULL)
00169 {
00170 if (m_A_type == NULL)
00171 {
00172 delete m_A_type;
00173 }
00174 m_A_type = new Attribute(*the_object_to_add.m_A_type);
00175 }
00176
00177 if (the_object_to_add.m_A_name != NULL)
00178 {
00179 if (m_A_name == NULL)
00180 {
00181 delete m_A_name;
00182 }
00183 m_A_name = new Attribute(*the_object_to_add.m_A_name);
00184 }
00185 }
00186
00187 return *this;
00188 }