owlcpp  v0.3.3~
C++ library for working with OWL ontologies
 All Classes Namespaces Files Functions Macros Pages
node_iri.hpp
Go to the documentation of this file.
1 
6 #ifndef NODE_IRI_HPP_
7 #define NODE_IRI_HPP_
8 #include "boost/functional/hash.hpp"
9 #include "owlcpp/rdf/node.hpp"
10 #include "owlcpp/rdf/exception.hpp"
13 
14 namespace owlcpp{
15 
18 class Node_iri : public Node {
19  friend inline std::size_t hash_value(Node_iri const& node)
20  {return node.hash_impl();}
21 
22 public:
23 
24  explicit Node_iri(const Ns_id ns = terms::empty::id(), std::string const& val = "")
25  : val_(val), ns_(ns)
26  {
27  if( is_blank(ns_) ) BOOST_THROW_EXCEPTION(
28  Rdf_err() << Rdf_err::msg_t("blank \"_\" namespace in IRI node")
29  );
30  }
31 
32  std::string const& fragment() const {return val_;}
33 
34 private:
35  std::string val_;
36  Ns_id ns_;
37 
38  OWLCPP_VISITABLE
39 
40  Ns_id ns_id_impl() const { return ns_; }
41 
42  bool equal_impl(const Node& n) const {
43  //todo: use typeid()?
44  if( Node_iri const*const p = dynamic_cast<Node_iri const*>(&n) ) {
45  return ns_ == p->ns_ && val_ == p->val_;
46  }
47  return false;
48  }
49 
50  std::size_t hash_impl() const {
51  std::size_t h = 0;
52  boost::hash_combine(h, val_);
53  boost::hash_combine(h, ns_);
54  return h;
55  }
56 
57  Node* clone_impl() const {return new Node_iri(*this);}
58 };
59 
60 }//namespace owlcpp
61 #endif /* NODE_IRI_HPP_ */