6 #ifndef MAP_NS_PREFIX_HPP_
7 #define MAP_NS_PREFIX_HPP_
9 #include "boost/assert.hpp"
10 #include "boost/multi_index_container.hpp"
11 #include "boost/multi_index/ordered_index.hpp"
12 #include "boost/multi_index/member.hpp"
24 Pref_wrap(std::string
const& prefix,
const Ns_id nsid)
25 :pref(prefix), id(nsid) {}
30 typedef boost::multi_index_container<
32 boost::multi_index::indexed_by<
33 boost::multi_index::ordered_unique<
34 boost::multi_index::tag<struct pref_tag>,
35 boost::multi_index::member<Pref_wrap, std::string, &Pref_wrap::pref>
37 boost::multi_index::ordered_unique<
38 boost::multi_index::tag<struct id_tag>,
39 boost::multi_index::member<Pref_wrap, Ns_id, &Pref_wrap::id>
44 typedef pref_map_t::index<pref_tag>::type pref_index_t;
45 typedef pref_index_t::const_iterator pref_iterator_t;
46 typedef pref_map_t::index<id_tag>::type id_index_t;
47 typedef id_index_t::const_iterator id_iterator_t;
52 std::string prefix(
const Ns_id id)
const {
53 id_index_t
const& index = pref_.get<id_tag>();
54 const id_iterator_t iter = index.find(
id);
55 if( iter == index.end() )
return "";
59 Ns_id const* find(std::string
const& pref)
const {
60 pref_index_t
const& index = pref_.get<pref_tag>();
61 const pref_iterator_t iter = index.find(pref);
62 if( iter == index.end() )
return 0;
72 void set(
const Ns_id id, std::string
const& pref =
"") {
73 id_index_t& id_index = pref_.get<id_tag>();
74 const id_iterator_t id_iter = id_index.find(
id);
77 if( id_iter != id_index.end() ) id_index.erase(id_iter);
80 if( id_iter != id_index.end() ) {
81 if( id_iter->pref != pref ) BOOST_THROW_EXCEPTION(
83 << Err::msg_t(
"different IRI prefix has been set")
85 << Err::str2_t(id_iter->pref)
90 pref_index_t
const& pref_index = pref_.get<pref_tag>();
91 const pref_iterator_t pref_iter = pref_index.find(pref);
92 if( pref_iter != pref_index.end() ) BOOST_THROW_EXCEPTION(
94 << Err::msg_t(
"prefix used for different IRI")
97 pref_.insert(Pref_wrap(pref,
id));
100 void erase(
const Ns_id id) {pref_.get<id_tag>().erase(
id);}
102 void clear() {pref_.clear();}