10 #include "boost/assert.hpp" 11 #include "boost/foreach.hpp" 12 #include "boost/functional/hash_fwd.hpp" 13 #include "boost/unordered_set.hpp" 17 namespace vdj_pipe{
namespace detail{
28 class Hash_id : std::unary_function<id_type, std::size_t> {
46 class Equal_id :
public std::binary_function<id_type, id_type, bool>{
54 template<
class ObjCompat>
56 return m_[
id1] == obj;
59 template<
class ObjCompat>
61 return obj ==
m_[
id2];
73 return m_[
id1] == obj;
77 return obj ==
m_[
id2];
84 typedef boost::unordered_set<id_type, Hash_id, Equal_id>
map_t;
95 map_(
boost::unordered::detail::default_bucket_count,
Hash_id(*this), Equal_id(*this)),
102 map_(
boost::unordered::detail::default_bucket_count,
Hash_id(*this), Equal_id(*this)),
117 const_iterator
end()
const {
return map_.end();}
123 BOOST_ASSERT(
vpos(
id) <
vid_.size() );
128 BOOST_ASSERT(
vpos(
id) <
vid_.size() );
132 obj_type
const&
at(
const id_type
id)
const {
133 if(
id <
id0_ ||
vpos(
id) >=
vid_.size() ) BOOST_THROW_EXCEPTION(
141 obj_type&
at(
const id_type
id) {
142 if(
id <
id0_ ||
vpos(
id) >=
vid_.size() ) BOOST_THROW_EXCEPTION(
150 template<
class ObjCompat>
151 id_type
const*
find(ObjCompat
const& obj)
const {
152 const const_iterator i =
map_.find(
154 boost::hash<ObjCompat>(),
155 Equal_obj<ObjCompat>(*
this)
157 return i ==
map_.end() ? 0 : &(*i);
160 std::pair<id_type, bool>
insert(obj_type
const& obj) {
161 if( id_type
const* idp =
find(obj) )
return std::make_pair(*idp,
false);
166 return std::make_pair(
id,
true);
169 const id_type
id =
erased_.back();
171 const std::size_t
n =
vpos(
id);
172 BOOST_ASSERT(
vid_.size() >
n);
175 return std::make_pair(
id,
true);
179 BOOST_ASSERT(
vpos(
id) <
vid_.size() );
180 const std::size_t pos =
vpos(
id);
198 std::size_t
vpos(
const id_type
id)
const {
199 BOOST_ASSERT(
id >= id0_ &&
"invalid ID");
200 return id() -
id0_();
205 void copy(self_type
const& bm) {
206 vid_.resize(bm.
vid_.size());
209 BOOST_FOREACH(
const id_type
id, bm) {
210 (*this)[id] = bm[id];
bool operator()(id_type id1, ObjCompat const &obj) const
Definition: id_bimap.hpp:55
std::pair< id_type, bool > insert(obj_type const &obj)
Definition: id_bimap.hpp:160
std::size_t operator()(const id_type id) const
Definition: id_bimap.hpp:32
Definition: sanitize_string.cpp:15
id_type min_id() const
Definition: id_bimap.hpp:119
Equal_id(self_type const &m)
Definition: id_bimap.hpp:48
Definition: id_bimap.hpp:28
std::vector< obj_type > vector_t
Definition: id_bimap.hpp:85
obj_type & at(const id_type id)
Definition: id_bimap.hpp:141
Definition: id_bimap.hpp:46
boost::unordered_set< id_type, Hash_id, Equal_id > map_t
Definition: id_bimap.hpp:84
bool operator()(ObjCompat const &obj, id_type id2) const
Definition: id_bimap.hpp:60
bool empty() const
Definition: id_bimap.hpp:118
void erase(const id_type id)
Definition: id_bimap.hpp:178
map_t map_
Definition: id_bimap.hpp:194
bool operator()(id_type id1, id_type id2) const
Definition: id_bimap.hpp:50
obj_type const & operator[](const id_type id) const
Definition: id_bimap.hpp:122
id_type pos2id(const std::size_t n) const
Definition: id_bimap.hpp:203
Hash_id(self_type const &v)
Definition: id_bimap.hpp:30
Definition: id_bimap.hpp:21
bool operator()(id_type id1, ObjCompat const &obj) const
Definition: id_bimap.hpp:72
map_t::value_type value_type
Definition: id_bimap.hpp:88
Id_bimap(self_type const &bm)
Definition: id_bimap.hpp:100
boost::error_info< struct errinfo_int1_, int > int1_t
Definition: exception.hpp:28
const_iterator end() const
Definition: id_bimap.hpp:117
std::size_t hash_value(Base_id< S, V > const &id)
Definition: object_id_base.hpp:55
base_exception Err
Definition: id_bimap.hpp:91
std::size_t vpos(const id_type id) const
Definition: id_bimap.hpp:198
id_type max_id() const
Definition: id_bimap.hpp:120
vector_t vid_
Definition: id_bimap.hpp:193
Obj obj_type
Definition: id_bimap.hpp:24
self_type const & m_
Definition: id_bimap.hpp:81
id_type const * find(ObjCompat const &obj) const
Definition: id_bimap.hpp:151
Main namespace of vdj_pipe library.
Definition: keywords_variable.hpp:11
self_type const & m_
Definition: id_bimap.hpp:43
std::size_t hash_value(basic_string_ref< charT, traits > const &str)
Definition: string_ref.hpp:15
bool operator()(ObjCompat const &obj, id_type id2) const
Definition: id_bimap.hpp:76
const std::string id1
Definition: file_ostream_variant_run.cpp:21
id_type id0_
Definition: id_bimap.hpp:196
const std::size_t n
Definition: vector_set_test.cpp:26
Id id_type
Definition: id_bimap.hpp:25
self_type const & m_
Definition: id_bimap.hpp:65
obj_type & operator[](const id_type id)
Definition: id_bimap.hpp:127
std::vector< id_type > erased_
Definition: id_bimap.hpp:195
Definition: exception.hpp:23
void clear()
Definition: id_bimap.hpp:186
boost::error_info< struct errinfo_message_, std::string > msg_t
Definition: exception.hpp:24
Equal_obj(self_type const &m)
Definition: id_bimap.hpp:70
map_t::iterator iterator
Definition: id_bimap.hpp:89
self_type & operator=(self_type const &bm)
Definition: id_bimap.hpp:109
Id_bimap self_type
Definition: id_bimap.hpp:23
std::size_t size() const
Definition: id_bimap.hpp:115
const_iterator begin() const
Definition: id_bimap.hpp:116
const std::string id2
Definition: file_ostream_variant_run.cpp:25
Id_bimap(const id_type id0)
Definition: id_bimap.hpp:93
std::size_t operator()(obj_type const &obj) const
Definition: id_bimap.hpp:37
obj_type const & at(const id_type id) const
Definition: id_bimap.hpp:132
map_t::const_iterator const_iterator
Definition: id_bimap.hpp:90
void copy(self_type const &bm)
Definition: id_bimap.hpp:205
Definition: id_bimap.hpp:68