owlcpp  v0.3.3~
C++ library for working with OWL ontologies
 All Classes Namespaces Files Functions Macros Pages
map_std.hpp
Go to the documentation of this file.
1 
6 #ifndef MAP_STD_HPP_
7 #define MAP_STD_HPP_
8 #include "boost/assert.hpp"
9 #include "boost/range.hpp"
10 #include "boost/range/algorithm/max_element.hpp"
11 #include "boost/utility.hpp"
12 #include "boost/concept/assert.hpp"
13 
15 #include "owlcpp/rdf/ns_iri.hpp"
16 #include "owlcpp/rdf/node_iri.hpp"
17 #include "owlcpp/node_id.hpp"
18 #include "owlcpp/rdf/detail/map_id_object.hpp"
20 #include "owlcpp/terms/detail/max_standard_id.hpp"
21 
22 namespace owlcpp{
23 
27 class Map_std : boost::noncopyable {
28  typedef detail::Map_id_object<Ns_iri, Ns_id> map_ns_t;
29  typedef detail::Map_id_object<Node_iri, Node_id> map_node_t;
30 
31  template<class Inserter> explicit Map_std(Inserter const& ins);
32 
33 public:
34 
47  template<class T> static Map_std const& get(T const& t) {
48  BOOST_CONCEPT_ASSERT((boost::UnaryFunction<T, void, Map_std&>));
49  static const Map_std map(t);
50  return map;
51  }
52 
53  void insert(const Ns_id nsid, Ns_iri const& nsiri, std::string const& pref) {
54  BOOST_ASSERT(nsid < detail::min_ns_id());
55  map_ns_.insert(nsid, nsiri);
56  map_pref_.set(nsid, pref);
57  }
58 
59  void insert(const Node_id nid, Node_iri const& node) {
60  BOOST_ASSERT(nid < detail::min_node_id());
61  BOOST_ASSERT(find(node.ns_id()));
62  map_node_.insert(nid, node);
63  }
64 
71  bool is_standard(const Ns_id nsid) const {
72  return nsid < detail::min_ns_id();
73  }
74 
75  bool is_standard(const Node_id nid) const {
76  return nid < detail::min_node_id();
77  }
78 
79  Ns_id const* find(Ns_iri const& iri) const {return map_ns_.find(iri);}
80  Ns_id const* find_prefix(std::string const& pref) const {return map_pref_.find(pref);}
81  Ns_iri const& operator[](const Ns_id nsid) const {return map_ns_[nsid];}
82  Ns_iri const& at(const Ns_id nsid) const {return map_ns_.at(nsid);}
83  Ns_iri const* find(const Ns_id nsid) const {return map_ns_.find(nsid);}
84  std::string prefix(const Ns_id nsid) const {return map_pref_.prefix(nsid);}
85 
86  Node_iri const& operator[](const Node_id nid) const {return map_node_[nid];}
87  Node_iri const& at(const Node_id nid) const {return map_node_.at(nid);}
88  Node_iri const* find(const Node_id nid) const {return map_node_.find(nid);}
89  Node_id const* find(Node_iri const& node) const {return map_node_.find(node);}
90 
91  Node_id const* find(const Ns_id ns, std::string const& val) const {
92  if( is_blank(ns) || ns >= detail::min_ns_id() ) return 0;
93  return map_node_.find(Node_iri(ns, val));
94  }
95 
96 private:
97  map_ns_t map_ns_;
98  Map_ns_prefix map_pref_;
99  map_node_t map_node_;
100 };
101 
102 namespace detail{
103 
106 class Ns_inserter {
107 public:
108  explicit Ns_inserter(Map_std& map) : map_(&map) {}
109  template<class NsTag> void operator()(NsTag const&) const {
110  map_->insert(NsTag::id(), Ns_iri(NsTag::iri()), NsTag::prefix());
111  }
112 private:
113  mutable Map_std* map_;
114 };
115 
119 public:
120  explicit Node_inserter(Map_std& map) : map_(&map) {}
121  template<class NodeTag> void operator()(NodeTag const&) const {
122  typedef typename NodeTag::ns_type ns_type;
123  map_->insert(ns_type::id(), Ns_iri(ns_type::iri()), ns_type::prefix());
124  map_->insert(NodeTag::id(), Node_iri(ns_type::id(), NodeTag::fragment()));
125  }
126 private:
127  mutable Map_std* map_;
128 };
129 }//namespace detail
130 
131 template<class Inserter> Map_std::Map_std(Inserter const& ins)
132 : map_ns_(Ns_id(0)), map_pref_(), map_node_(Node_id(0))
133 {
134  detail::Ns_inserter ns_ins(*this);
135  ns_ins(terms::empty());
136  ns_ins(terms::blank());
137  detail::Node_inserter node_ins(*this);
138  node_ins(terms::empty_());
139 
140  ins(*this);
141 }
142 
143 }//namespace owlcpp
144 #endif /* MAP_STD_HPP_ */