claw  1.9.0
multi_type_map.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@stuff-o-matic.com
24 */
30 #ifndef __CLAW_MULTI_TYPE_MAP_HPP__
31 #define __CLAW_MULTI_TYPE_MAP_HPP__
32 
33 #include <claw/meta/no_type.hpp>
34 #include <claw/meta/type_list.hpp>
35 #include <map>
36 
37 namespace claw
38 {
59  template <typename ValueType, typename Map>
61 
67  template <typename Map>
69 
89  template <typename Key, typename TypeList>
91 
95  template <typename Key>
96  class multi_type_map<Key, meta::no_type>
97  {}; // class multi_type_map
98 
103  template <typename Key, typename Head, typename Tail>
104  class multi_type_map<Key, meta::type_list<Head, Tail> >
105  : public multi_type_map<Key, Tail>
106  {
107  public:
108  typedef Key key_type;
109  typedef Head value_type;
112  typedef std::map<key_type, value_type> container_type;
114 
115  friend struct multi_type_map_wrapper<value_type, self_type>;
116  friend struct multi_type_map_helper<self_type>;
117 
120  template <typename ValueType>
121  struct iterator
122  {
124  typedef typename std::map<key_type, ValueType>::iterator type;
125 
127  typedef
128  typename std::map<key_type, ValueType>::const_iterator const_type;
129  }; // struct iterator
130 
131  private:
132  typedef typename iterator<value_type>::type iterator_type;
133  typedef typename iterator<value_type>::const_type const_iterator_type;
134 
135  public:
136  template <typename ValueType>
137  void erase(typename iterator<ValueType>::type it);
138 
139  template <typename ValueType>
140  std::size_t erase(const key_type& k);
141 
142  template <typename ValueType>
143  const ValueType& get(const key_type& k) const;
144 
145  template <typename ValueType>
146  ValueType& get(const key_type& k);
147 
148  template <typename ValueType>
149  void set(const key_type& k, const ValueType& v);
150 
151  void set(const self_type& m);
152 
153  template <typename ValueType>
154  bool exists(const key_type& k) const;
155 
156  std::size_t size() const;
157 
158  template <typename ValueType>
159  typename iterator<ValueType>::type begin();
160 
161  template <typename ValueType>
162  typename iterator<ValueType>::type end();
163 
164  template <typename ValueType>
165  typename iterator<ValueType>::const_type begin() const;
166 
167  template <typename ValueType>
168  typename iterator<ValueType>::const_type end() const;
169 
170  private:
172  container_type m_data;
173 
174  }; // class multi_type_map
175 
176 }
177 
178 #include <claw/multi_type_map.tpp>
179 
180 #endif // __CLAW_MULTI_TYPE_MAP_HPP__
This class can associate values of different types to a key.
Template classes for lists of types.
This class provides types and methods to allow the call of methods for a given type in the inheritanc...
Use this class to make a list of types.
Definition: type_list.hpp:59
An empty class not considered as a effective type.
std::map< key_type, ValueType >::const_iterator const_type
The type of the const_iterator.
std::map< key_type, ValueType >::iterator type
The type of the iterator.
This class can associate values of different types to a key.
This is the main namespace.
Definition: application.hpp:49
This class provides types and methods to allow the call of methods recursively along the inherintance...