27 #ifndef RL_XML_OBJECT_H
28 #define RL_XML_OBJECT_H
32 #include <boost/numeric/conversion/cast.hpp>
33 #include <libxml/xpath.h>
45 explicit Object(::xmlXPathObjectPtr
object) :
55 xmlXPathObjectPtr
get()
const
57 return this->
object.get();
62 return this->
object->type;
76 const ::std::type_info&
type()
const
78 switch (this->
object->type)
81 throw ::std::bad_typeid();
87 return typeid(this->
object->boolval);
90 return typeid(this->
object->floatval);
93 return typeid(this->
object->stringval);
97 case XPATH_LOCATIONSET:
101 throw ::std::bad_typeid();
109 ::std::shared_ptr< ::xmlXPathObject>
object;
116 double Object::getValue<double>(
const double& val)
const
118 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? this->
object->floatval : val;
123 float Object::getValue<float>(
const float& val)
const
125 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<float>(this->
object->floatval) : val;
130 short int Object::getValue<short int>(
const short int& val)
const
132 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<short int>(this->
object->floatval) : val;
137 int Object::getValue<int>(
const int& val)
const
139 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<int>(this->
object->floatval) : val;
144 long int Object::getValue<long int>(
const long int& val)
const
146 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<long int>(this->
object->floatval) : val;
151 long long int Object::getValue<long long int>(
const long long int& val)
const
153 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<long long int>(this->
object->floatval) : val;
158 unsigned short int Object::getValue<unsigned short int>(
const unsigned short int& val)
const
160 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<unsigned short int>(this->
object->floatval) : val;
165 unsigned int Object::getValue<unsigned int>(
const unsigned int& val)
const
167 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<unsigned int>(this->
object->floatval) : val;
172 unsigned long int Object::getValue<unsigned long int>(
const unsigned long int& val)
const
174 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<unsigned long int>(this->
object->floatval) : val;
179 unsigned long long int Object::getValue<unsigned long long int>(
const unsigned long long int& val)
const
181 return 0 == ::xmlXPathIsNaN(this->
object->floatval) ? ::boost::numeric_cast<unsigned long long int>(this->
object->floatval) : val;
186 bool Object::getValue<bool>()
const
188 return 1 == this->
object->boolval ? true :
false;
193 double Object::getValue<double>()
const
195 return this->getValue<double>(::std::numeric_limits<double>::quiet_NaN());
200 float Object::getValue<float>()
const
202 return this->getValue<float>(::std::numeric_limits<float>::quiet_NaN());
207 short int Object::getValue<short int>()
const
209 return this->getValue<short int>(::std::numeric_limits<short int>::quiet_NaN());
214 int Object::getValue<int>()
const
216 return this->getValue<int>(::std::numeric_limits<int>::quiet_NaN());
221 long int Object::getValue<long int>()
const
223 return this->getValue<long int>(::std::numeric_limits<long int>::quiet_NaN());
228 long long int Object::getValue<long long int>()
const
230 return this->getValue<long long int>(::std::numeric_limits<long long int>::quiet_NaN());
235 unsigned short int Object::getValue<unsigned short int>()
const
237 return this->getValue<unsigned short int>(::std::numeric_limits<unsigned short int>::quiet_NaN());
242 unsigned int Object::getValue<unsigned int>()
const
244 return this->getValue<unsigned int>(::std::numeric_limits<unsigned int>::quiet_NaN());
249 unsigned long int Object::getValue<unsigned long int>()
const
251 return this->getValue<unsigned long int>(::std::numeric_limits<unsigned long int>::quiet_NaN());
256 unsigned long long int Object::getValue<unsigned long long int>()
const
258 return this->getValue<unsigned long long int>(::std::numeric_limits<unsigned long long int>::quiet_NaN());
270 ::std::string Object::getValue< ::std::string>()
const
272 return nullptr != this->
object->stringval ?
reinterpret_cast<char*
>(this->
object->stringval) : ::std::string();
277 #endif // RL_XML_PATH_H