Claw 1.7.3
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@gamned.org
24*/
30#ifndef __CLAW_MULTI_TYPE_MAP_HPP__
31#define __CLAW_MULTI_TYPE_MAP_HPP__
32
33#include <claw/meta/no_type.hpp>
35#include <map>
36
37namespace 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 {
98
99 }; // class multi_type_map
100
105 template<typename Key, typename Head, typename Tail>
106 class multi_type_map< Key, meta::type_list<Head, Tail> >:
107 public multi_type_map<Key, Tail>
108 {
109 public:
110 typedef Key key_type;
111 typedef Head value_type;
114 typedef std::map<key_type, value_type> container_type;
116
117 friend struct multi_type_map_wrapper<value_type, self_type>;
118 friend struct multi_type_map_helper<self_type>;
119
122 template<typename ValueType>
123 struct iterator
124 {
126 typedef typename std::map<key_type, ValueType>::iterator type;
127
129 typedef
130 typename std::map<key_type, ValueType>::const_iterator const_type;
131 }; // struct iterator
132
133 private:
134 typedef typename iterator<value_type>::type iterator_type;
135 typedef typename iterator<value_type>::const_type const_iterator_type;
136
137 public:
138 template<typename ValueType>
139 void erase( typename iterator<ValueType>::type it );
140
141 template<typename ValueType>
142 std::size_t erase( const key_type& k );
143
144 template<typename ValueType>
145 const ValueType& get( const key_type& k ) const;
146
147 template<typename ValueType>
148 ValueType& get( const key_type& k );
149
150 template<typename ValueType>
151 void set( const key_type& k, const ValueType& v );
152
153 void set( const self_type& m );
154
155 template<typename ValueType>
156 bool exists( const key_type& k ) const;
157
158 std::size_t size() const;
159
160 template<typename ValueType>
161 typename iterator<ValueType>::type begin();
162
163 template<typename ValueType>
164 typename iterator<ValueType>::type end();
165
166 template<typename ValueType>
167 typename iterator<ValueType>::const_type begin() const;
168
169 template<typename ValueType>
170 typename iterator<ValueType>::const_type end() const;
171
172 private:
174 container_type m_data;
175
176 }; // class multi_type_map
177
178} // namespace claw
179
180#include <claw/impl/multi_type_map.tpp>
181
182#endif // __CLAW_MULTI_TYPE_MAP_HPP__
This class can associate values of different types to a key.
This class provides types and methods to allow the call of methods recursively along the inherintance...
This class provides types and methods to allow the call of methods for a given type in the inheritanc...
This class can associate values of different types to a key.
This is the main namespace.
Definition algorithm.hpp:34
An empty class not considered as a effective type.
Use this class to make a list of types.
Definition type_list.hpp:60
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.
Template classes for lists of types.