owlcpp  v0.3.3~
C++ library for working with OWL ontologies
 All Classes Namespaces Files Functions Macros Pages
map_ns.hpp
Go to the documentation of this file.
1 
6 #ifndef MAP_NS_HPP_
7 #define MAP_NS_HPP_
8 #include <map>
9 #include <vector>
10 #include <functional>
11 #include "boost/assert.hpp"
12 
13 #include "owlcpp/ns_id.hpp"
14 #include "owlcpp/rdf/ns_iri.hpp"
15 #include "owlcpp/rdf/detail/map_id_object.hpp"
17 #include "owlcpp/detail/iterator_member_pair.hpp"
18 #include "owlcpp/detail/member_iterator.hpp"
19 #include "owlcpp/terms/detail/max_standard_id.hpp"
20 
21 namespace owlcpp{
22 
25 class Map_ns {
26 public:
27  typedef Ns_id id_type;
28 private:
29 
30  typedef detail::Map_id_object<Ns_iri, id_type> map_t;
31 
32 public:
33  typedef Iterator_member_pair<map_t::const_iterator, id_type const, 2> iterator;
34  typedef iterator const_iterator;
35 
36  struct Err : public Rdf_err {};
37 
38  Map_ns(const Ns_id id0 = detail::min_ns_id())
39  : iri_(id0), pref_()
40  {}
41 
42  std::size_t size() const {return iri_.size();}
43  const_iterator begin() const {return iri_.begin();}
44  const_iterator end() const {return iri_.end();}
45  bool empty() const {return iri_.empty();}
46  Ns_iri const& operator[](const Ns_id id) const {return iri_[id];}
47  Ns_iri const& at(const Ns_id id) const {return iri_.at(id);}
48  Ns_iri const* find(const Ns_id id) const {return iri_.find(id);}
49  std::string prefix(const Ns_id id) const {return pref_.prefix(id);}
50  Ns_id const* find_prefix(std::string const& pref) const {return pref_.find(pref);}
51 
56  Ns_id const* find(Ns_iri const& iri) const {return iri_.find(iri);}
57  Ns_id const* find(std::string const& iri) const {return iri_.find(Ns_iri(iri));}
58 
59  Ns_id insert(Ns_iri const& iri) {return iri_.insert(iri);}
60  Ns_id insert(std::string const& iri) {return insert(Ns_iri(iri));}
61 
62  void set_prefix(const Ns_id id, std::string const& pref = "") {
63  if( ! find(id) ) BOOST_THROW_EXCEPTION(
64  Err()
65  << Err::msg_t("invalid namespace ID")
66  << Err::int1_t(id())
67  );
68  pref_.set(id, pref);
69  }
70 
71  void remove(const Ns_id id) {
72  iri_.remove(id);
73  pref_.erase(id);
74  }
75 
76  void clear() {
77  pref_.clear();
78  iri_.clear();
79  }
80 
81 private:
82  map_t iri_;
83  Map_ns_prefix pref_;
84 };
85 
86 }//namespace owlcpp
87 #endif /* MAP_NS_HPP_ */