owlcpp  v0.3.3-86-g20d8c12~
C++ library for working with OWL ontologies
 All Classes Namespaces Files Functions Macros Pages
map_std_node_crtpb.hpp
Go to the documentation of this file.
1 
6 #ifndef MAP_STD_NODE_CRTPB_HPP_
7 #define MAP_STD_NODE_CRTPB_HPP_
8 #include "boost/assert.hpp"
9 #include "boost/concept/assert.hpp"
10 
11 #include "owlcpp/detail/map_traits.hpp"
12 #include "owlcpp/terms/detail/max_standard_id.hpp"
13 
14 namespace owlcpp{
15 
20 template<class Super> class Map_std_node_crtpb {
21  typedef detail::Map_traits<Super> traits;
22  typedef typename traits::map_std_type map_std_type;
23  typedef typename traits::map_node_type map_node_type;
24 
25  map_std_type const& _map_std() const {
26  return static_cast<Super const&>(*this).map_std_;
27  }
28 
29  map_node_type const& _map_node() const {
30  return static_cast<Super const&>(*this).map_node_;
31  }
32 
33  map_node_type& _map_node() {
34  return static_cast<Super&>(*this).map_node_;
35  }
36 
37 public:
38  typedef typename traits::node_type node_type;
39 
40  bool is_standard(const Node_id nid) const {return _map_std().is_standard(nid);}
41 
42  node_type const& operator[](const Node_id id) const {
43  return _map_std().is_standard(id) ? _map_std()[id] : _map_node()[id];
44  }
45 
51  node_type const& at(const Node_id id) const {
52  return _map_std().is_standard(id) ? _map_std().at(id) : _map_node().at(id);
53  }
54 
59  node_type const* find(const Node_id id) const {
60  return _map_std().is_standard(id) ?
61  _map_std().find(id) :
62  _map_node().find(id)
63  ;
64  }
65 
66  Node_id const* find_node_iri(const Ns_id nsid, std::string const& name) const {
67  BOOST_ASSERT(
68  static_cast<Super const&>(*this).find(nsid) &&
69  "invalid namespace ID"
70  );
71  if( Node_id const*const nid = _map_std().find(nsid, name) ) return nid;
72  return _map_node().find_iri(nsid, name);
73  }
74 
80  Node_id insert_node_iri(const Ns_id nsid, std::string const& name) {
81  BOOST_ASSERT(
82  static_cast<Super const&>(*this).find(nsid) &&
83  "invalid namespace ID"
84  );
85  typedef typename Super::Err Err;
86  if( is_blank(nsid) ) {
87  BOOST_THROW_EXCEPTION(
88  Err()
89  << typename Err::msg_t("blank namespace for IRI node")
90  << typename Err::str1_t(name)
91  );
92  }
93  if( Node_id const*const nid = _map_std().find(nsid, name) ) return *nid;
94 
95  if( _map_std().is_standard(nsid) ) {
96  BOOST_THROW_EXCEPTION(
97  Err()
98  << typename Err::msg_t("unknown term in standard namespace")
99  << typename Err::str1_t( name )
100  << typename Err::str2_t( _map_std().at(nsid).str() )
101  );
102  }
103  return _map_node().insert_iri(nsid, name);
104  }
105 };
106 
107 }//namespace owlcpp
108 #endif /* MAP_STD_NODE_CRTPB_HPP_ */
Node_id insert_node_iri(const Ns_id nsid, std::string const &name)
Insert IRI node.
Definition: map_std_node_crtpb.hpp:80
Definition: ns_id.hpp:15
Definition: map_std_node_crtpb.hpp:20
node_type const * find(const Node_id id) const
Definition: map_std_node_crtpb.hpp:59
Term identifier.
Definition: node_id.hpp:15
node_type const & at(const Node_id id) const
Definition: map_std_node_crtpb.hpp:51