Mirror reflection library 0.5.13

mirror/utils/wxxml_factory.hpp

Go to the documentation of this file.
00001 
00010 #ifndef MIRROR_UTILS_WXXML_FACTORY_1011291729_HPP
00011 #define MIRROR_UTILS_WXXML_FACTORY_1011291729_HPP
00012 
00013 #include <mirror/config.hpp>
00014 #include <mirror/utils/sdn_factory.hpp>
00015 #include <wx/xml/xml.h>
00016 
00017 MIRROR_NAMESPACE_BEGIN
00018 
00019 class sdn_fact_wxxml_property;
00020 class sdn_fact_wxxml_element;
00021 class sdn_fact_wxxml_range;
00022 
00023 class sdn_fact_wxxml_property
00024 {
00025 private:
00026     typedef sdn_fact_wxxml_property property;
00027     typedef wxXmlProperty xml_attrib;
00028     xml_attrib* attrib;
00029 
00030     friend class sdn_fact_wxxml_element;
00031 
00032     sdn_fact_wxxml_property(xml_attrib* _attrib)
00033      : attrib(_attrib)
00034     { }
00035 public:
00036     operator bool (void) const
00037     {
00038         return attrib != nullptr;
00039     }
00040 
00041     bool operator ! (void) const
00042     {
00043         return attrib == nullptr;
00044     }
00045 
00046     bool has_type(const std::string& type_name)
00047     {
00048         return true;
00049     }
00050 
00051     std::string text(void)
00052     {
00053         assert(attrib != nullptr);
00054         return std::string(attrib->GetValue().mb_str(wxConvUTF8));
00055     }
00056 };
00057 
00058 class sdn_fact_wxxml_range
00059 {
00060 private:
00061     typedef sdn_fact_wxxml_element element;
00062     typedef wxXmlNode xml_node;
00063     xml_node* node;
00064 public:
00065     sdn_fact_wxxml_range(xml_node* _node)
00066      : node(_node)
00067     {
00068     }
00069 
00070     bool empty(void) const
00071     {
00072         return node == nullptr;
00073     }
00074 
00075     void step_front(void)
00076     {
00077         assert(!empty());
00078         node = node->GetNext();
00079     }
00080 
00081     element front(void) const;
00082 };
00083 
00084 class sdn_fact_wxxml_element
00085 {
00086 private:
00087     typedef sdn_fact_wxxml_range range;
00088     typedef sdn_fact_wxxml_element element;
00089     typedef sdn_fact_wxxml_property property;
00090     typedef wxXmlNode xml_node;
00091     xml_node* node;
00092 public:
00093     sdn_fact_wxxml_element(wxXmlDocument& doc)
00094      : node(doc.GetRoot())
00095     {
00096     }
00097 
00098     sdn_fact_wxxml_element(xml_node* _node)
00099      : node(_node)
00100     {
00101     }
00102 
00103     operator bool (void) const
00104     {
00105         return node != nullptr;
00106     }
00107 
00108     bool operator ! (void) const
00109     {
00110         return node == nullptr;
00111     }
00112 
00113     bool has_type(const std::string& type_name)
00114     {
00115         assert(node != nullptr);
00116         // TODO: check a type attribute if present ?
00117         return true;
00118     }
00119 
00120     range elements(void) const
00121     {
00122         assert(node != nullptr);
00123         return range(node->GetChildren());
00124     }
00125 
00126     element child(const std::string& name)
00127     {
00128         assert(node != nullptr);
00129         wxXmlNode* child_node = node->GetChildren();
00130         wxString cmp_name(name.c_str(), wxConvUTF8, name.size());
00131         while(child_node != nullptr && !name.empty())
00132         {
00133             if(child_node->GetName() == cmp_name)
00134                 break;
00135             child_node = child_node->GetNext();
00136         }
00137         return element(child_node);
00138     }
00139 
00140     property attribute(void)
00141     {
00142         assert(node != nullptr);
00143         return property(node->GetProperties());
00144     }
00145 
00146     property attribute(const std::string& name)
00147     {
00148         assert(!name.empty());
00149         assert(node != nullptr);
00150         wxXmlProperty* child_attr = node->GetProperties();
00151         wxString cmp_name(name.c_str(), wxConvUTF8, name.size());
00152         while(child_attr != nullptr)
00153         {
00154             if(child_attr->GetName() == cmp_name)
00155                 break;
00156             child_attr = child_attr->GetNext();
00157         }
00158         return property(child_attr);
00159     }
00160 };
00161 
00162 inline sdn_fact_wxxml_element sdn_fact_wxxml_range::front(void) const
00163 {
00164     assert(!empty());
00165     return sdn_fact_wxxml_element(node);
00166 }
00167 
00168 typedef sdn_fact_traits<
00169     sdn_fact_wxxml_range,
00170     sdn_fact_wxxml_element,
00171     sdn_fact_wxxml_property
00172 > sdn_fact_wxxml_traits;
00173 
00174 typedef factory_maker<
00175     sdn_fact_manuf,
00176     sdn_fact_suppl,
00177     sdn_fact_enum,
00178     sdn_fact_wxxml_traits
00179 > wxxml_factory_maker;
00180 
00181 typedef sdn_fact_data<
00182     sdn_fact_wxxml_traits
00183 > wxxml_factory_input;
00184 
00185 MIRROR_NAMESPACE_END
00186 
00187 #endif //include guard
00188 

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.