Mirror reflection library 0.5.13
|
00001 00010 #ifndef MIRROR_UTILS_MIJSON_FACTORY_1011291729_HPP 00011 #define MIRROR_UTILS_MIJSON_FACTORY_1011291729_HPP 00012 00013 #include <mirror/config.hpp> 00014 #include <mirror/utils/sdn_factory.hpp> 00015 #include <mirror/utils/mijson.hpp> 00016 00017 MIRROR_NAMESPACE_BEGIN 00018 00019 template <typename Iterator> 00020 class sdn_fact_mijson_property; 00021 00022 template <typename Iterator> 00023 class sdn_fact_mijson_element; 00024 00025 template <typename Iterator> 00026 class sdn_fact_mijson_range; 00027 00028 template <typename Iterator> 00029 class sdn_fact_mijson_property 00030 { 00031 private: 00032 typedef sdn_fact_mijson_property property; 00033 00034 friend class sdn_fact_mijson_element<Iterator>; 00035 00036 const mijson_element<Iterator>& attrib; 00037 00038 sdn_fact_mijson_property(const mijson_element<Iterator>& _attrib) 00039 : attrib(_attrib) 00040 { } 00041 public: 00042 operator bool (void) const 00043 { 00044 return true; 00045 } 00046 00047 bool operator ! (void) const 00048 { 00049 return false; 00050 } 00051 00052 bool has_type(const std::string& type_name) 00053 { 00054 return true; 00055 } 00056 00057 inline std::string text(void) 00058 { 00059 return attrib.value(); 00060 } 00061 }; 00062 00063 template <typename Iterator> 00064 class sdn_fact_mijson_range 00065 { 00066 private: 00067 typedef sdn_fact_mijson_element<Iterator> element; 00068 typedef typename mijson_element<Iterator>::element_list element_list; 00069 typename element_list::const_iterator cur,end; 00070 public: 00071 sdn_fact_mijson_range(const element_list& list) 00072 : cur(list.begin()) 00073 , end(list.end()) 00074 { } 00075 00076 bool empty(void) const 00077 { 00078 return cur == end; 00079 } 00080 00081 void step_front(void) 00082 { 00083 assert(!empty()); 00084 ++cur; 00085 } 00086 00087 element front(void) const; 00088 }; 00089 00090 template <typename Iterator> 00091 class sdn_fact_mijson_element 00092 { 00093 private: 00094 typedef sdn_fact_mijson_range<Iterator> range; 00095 typedef sdn_fact_mijson_element<Iterator> element; 00096 typedef sdn_fact_mijson_property<Iterator> property; 00097 00098 const mijson_element<Iterator>& node; 00099 public: 00100 sdn_fact_mijson_element(const mijson_element<Iterator>& _node) 00101 : node(_node) 00102 { } 00103 00104 operator bool (void) const 00105 { 00106 return true; 00107 } 00108 00109 bool operator ! (void) const 00110 { 00111 return false; 00112 } 00113 00114 bool has_type(const std::string& type_name) 00115 { 00116 return true; 00117 } 00118 00119 range elements(void) 00120 { 00121 return range(node.elements()); 00122 } 00123 00124 element child(const std::string& name) 00125 { 00126 try 00127 { 00128 return element(node.member(name)); 00129 } 00130 catch(std::runtime_error& e) 00131 { 00132 throw sdn_fact_node_not_found_error(e.what()); 00133 } 00134 } 00135 00136 property attribute(void) 00137 { 00138 try 00139 { 00140 assert(node.has_value()); 00141 return property(node); 00142 } 00143 catch(std::runtime_error& e) 00144 { 00145 throw sdn_fact_node_not_found_error(e.what()); 00146 } 00147 } 00148 00149 property attribute(const std::string& name) 00150 { 00151 try 00152 { 00153 assert(!name.empty()); 00154 return property(node.member(name)); 00155 } 00156 catch(std::runtime_error& e) 00157 { 00158 throw sdn_fact_node_not_found_error(e.what()); 00159 } 00160 } 00161 }; 00162 00163 template <typename Iterator> 00164 sdn_fact_mijson_element<Iterator> 00165 sdn_fact_mijson_range<Iterator>::front(void) const 00166 { 00167 assert(!empty()); 00168 return sdn_fact_mijson_element<Iterator>(*cur); 00169 } 00170 00171 typedef sdn_fact_traits< 00172 sdn_fact_mijson_range<const char*>, 00173 sdn_fact_mijson_element<const char*>, 00174 sdn_fact_mijson_property<const char*> 00175 > sdn_fact_mijson_traits; 00176 00177 typedef factory_maker< 00178 sdn_fact_manuf, 00179 sdn_fact_suppl, 00180 sdn_fact_enum, 00181 sdn_fact_mijson_traits 00182 > mijson_factory_maker; 00183 00184 typedef sdn_fact_data< 00185 sdn_fact_mijson_traits 00186 > mijson_factory_input; 00187 00188 MIRROR_NAMESPACE_END 00189 00190 #endif //include guard 00191