6 #ifndef NODE_LITERAL_HPP_
7 #define NODE_LITERAL_HPP_
9 #include "boost/functional/hash.hpp"
10 #include "boost/lexical_cast.hpp"
26 Node_id datatype()
const {
return datatype_impl();}
27 std::string value_str()
const {
return value_str_impl();}
29 virtual Node_id datatype_impl()
const =0;
30 virtual std::string value_str_impl()
const =0;
31 Ns_id ns_id_impl()
const {
return terms::empty::id(); }
40 typedef typename Dt::default_datatype default_datatype;
43 typedef typename Dt::value_type value_type;
45 template<
class In>
static value_type convert(In
const& in,
const Node_id dt) {
47 return Dt::convert(in, dt);
48 }
catch(std::bad_cast
const&) {
49 BOOST_THROW_EXCEPTION(
51 << Rdf_err::msg_t(
"error converting to " + Dt::name_str(dt))
52 << Rdf_err::str1_t(
"\"" + boost::lexical_cast<std::string>(in) +
"\"")
59 const Node_id dt = default_datatype::id()
61 : val_(convert<T>(val, dt)), dt_(dt)
66 const Node_id dt = default_datatype::id()
68 : val_(convert(std::string(val), dt)), dt_(dt)
72 std::string
const& val,
73 const Node_id dt = default_datatype::id()
75 : val_(convert(val, dt)), dt_(dt)
78 value_type value()
const {
return val_;}
86 std::string value_str_impl()
const {
return Dt::to_string(val_, dt_);}
88 Node_id datatype_impl()
const {
return dt_;}
90 bool equal_impl(
const Node& n)
const {
92 if(
self_type const*
const p = dynamic_cast<self_type const*>(&n) ) {
93 return dt_ == p->dt_ && val_ == p->val_;
98 std::size_t hash_impl()
const {
100 boost::hash_combine(h, val_);
101 boost::hash_combine(h, dt_);
113 typedef Datatype_string::default_datatype default_datatype;
115 static std::size_t _hash(std::string
const& val,
const Node_id dt, std::string
const& lang) {
117 boost::hash_combine(h, val);
118 boost::hash_combine(h, lang);
119 boost::hash_combine(h, dt);
124 typedef Datatype_string::value_type value_type;
127 std::string
const& val,
129 std::string
const& lang =
""
131 : val_(val), lang_(lang), hash_(_hash(val, dt, lang)), dt_(dt)
135 std::string
const& val,
136 std::string
const& lang =
""
140 hash_(_hash(val, default_datatype::id(), lang)),
141 dt_(default_datatype::id())
144 std::string
const& language()
const {
return lang_;}
145 std::string
const& value()
const {
return val_;}
155 Node_id datatype_impl()
const {
return dt_;}
157 std::string value_str_impl()
const {
return val_;}
159 bool empty_impl()
const {
return val_.empty() && lang_.empty() && is_empty(dt_); }
161 bool equal_impl(
const Node& n)
const {
163 if(
self_type const*
const p = dynamic_cast<self_type const*>(&n) ) {
164 return dt_ == p->dt_ && lang_ == p->lang_ && val_ == p->val_;
169 std::size_t hash_impl()
const {
return hash_;}