xc
bimap.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. PĂ©rez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //bimap.h
22 
23 #ifndef BIMAP_H
24 #define BIMAP_H
25 
26 #include <boost/multi_index_container.hpp>
27 #include <boost/multi_index/member.hpp>
28 #include <boost/multi_index/ordered_index.hpp>
29 #include <string>
30 
31 /* tags for accessing both sides of a bidirectional map */
32 
33 struct from{};
34 struct to{};
35 
36 /* The class template bidirectional_map wraps the specification
37  * of a bidirectional map based on multi_index_container.
38  */
39 
40 template<typename FromType,typename ToType>
42  {
43  typedef std::pair<FromType,ToType> value_type;
44 
45 
46  /* A bidirectional map can be simulated as a multi_index_container
47  * of pairs of (FromType,ToType) with two unique indices, one
48  * for each member of the pair.
49  */
50 
51  typedef boost::multi_index_container< value_type,
52  boost::multi_index::indexed_by<
53  boost::multi_index::ordered_unique<
54  boost::multi_index::tag<from>,boost::multi_index::member<value_type,FromType,&value_type::first> >,
55  boost::multi_index::ordered_unique<
56  boost::multi_index::tag<to>, boost::multi_index::member<value_type,ToType,&value_type::second> >
57  >
58  > type;
59  };
60 
61 #endif
62 
63 
Definition: bimap.h:34
Definition: bimap.h:33
Definition: bimap.h:41