Mirror reflection library 0.5.13

mirror/utils/rapidxml_factory.hpp

Go to the documentation of this file.
00001 
00010 #ifndef MIRROR_UTILS_RAPIDXML_FACTORY_1011291729_HPP
00011 #define MIRROR_UTILS_RAPIDXML_FACTORY_1011291729_HPP
00012 
00013 #include <mirror/config.hpp>
00014 #include <mirror/utils/sdn_factory.hpp>
00015 #include <rapidxml.hpp>
00016 
00017 MIRROR_NAMESPACE_BEGIN
00018 
00019 class sdn_fact_rapidxml_property;
00020 class sdn_fact_rapidxml_element;
00021 class sdn_fact_rapidxml_range;
00022 
00023 class sdn_fact_rapidxml_property
00024 {
00025 private:
00026     typedef sdn_fact_rapidxml_property property;
00027     typedef rapidxml::xml_attribute<> xml_attrib;
00028     xml_attrib* attrib;
00029 
00030     friend class sdn_fact_rapidxml_element;
00031 
00032     sdn_fact_rapidxml_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(
00055             attrib->value(),
00056             attrib->value() +
00057             attrib->value_size()
00058         );
00059     }
00060 };
00061 
00062 class sdn_fact_rapidxml_range
00063 {
00064 private:
00065     typedef sdn_fact_rapidxml_element element;
00066     typedef rapidxml::xml_node<> xml_node;
00067     xml_node* node;
00068 public:
00069     sdn_fact_rapidxml_range(xml_node* _node)
00070      : node(_node)
00071     { }
00072 
00073     bool empty(void) const
00074     {
00075         return node == nullptr;
00076     }
00077 
00078     void step_front(void)
00079     {
00080         assert(!empty());
00081         node = node->next_sibling();
00082     }
00083 
00084     element front(void) const;
00085 };
00086 
00087 class sdn_fact_rapidxml_element
00088 {
00089 private:
00090     typedef sdn_fact_rapidxml_range range;
00091     typedef sdn_fact_rapidxml_element element;
00092     typedef sdn_fact_rapidxml_property property;
00093     typedef rapidxml::xml_node<> xml_node;
00094     xml_node* node;
00095 public:
00096     sdn_fact_rapidxml_element(rapidxml::xml_document<>& doc)
00097      : node(doc.first_node())
00098     {
00099     }
00100 
00101     sdn_fact_rapidxml_element(xml_node* _node)
00102      : node(_node)
00103     {
00104     }
00105 
00106     operator bool (void) const
00107     {
00108         return node != nullptr;
00109     }
00110 
00111     bool operator ! (void) const
00112     {
00113         return node == nullptr;
00114     }
00115 
00116     bool has_type(const std::string& type_name)
00117     {
00118         assert(node != nullptr);
00119         // TODO: check a type attribute if present ?
00120         return true;
00121     }
00122 
00123     range elements(void) const
00124     {
00125         assert(node != nullptr);
00126         return range(node->first_node());
00127     }
00128 
00129     element child(const std::string& name)
00130     {
00131         assert(node != nullptr);
00132         return element(node->first_node(name.c_str()));
00133     }
00134 
00135     property attribute(void)
00136     {
00137         assert(node != nullptr);
00138         return property(node->first_attribute());
00139     }
00140 
00141     property attribute(const std::string& name)
00142     {
00143         assert(node != nullptr);
00144         assert(!name.empty());
00145         return property(node->first_attribute(name.c_str()));
00146     }
00147 };
00148 
00149 inline sdn_fact_rapidxml_element sdn_fact_rapidxml_range::front(void) const
00150 {
00151     assert(!empty());
00152     return sdn_fact_rapidxml_element(node);
00153 }
00154 
00155 typedef sdn_fact_traits<
00156     sdn_fact_rapidxml_range,
00157     sdn_fact_rapidxml_element,
00158     sdn_fact_rapidxml_property
00159 > sdn_fact_rapidxml_traits;
00160 
00161 typedef factory_maker<
00162     sdn_fact_manuf,
00163     sdn_fact_suppl,
00164     sdn_fact_enum,
00165     sdn_fact_rapidxml_traits
00166 > rapidxml_factory_maker;
00167 
00168 typedef sdn_fact_data<
00169     sdn_fact_rapidxml_traits
00170 > rapidxml_factory_input;
00171 
00172 MIRROR_NAMESPACE_END
00173 
00174 #endif //include guard
00175 

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.