4
4
CLAW is a free library without any particular aim but being useful to
7
Copyright (C) 2005-2008 Julien Jorge
7
Copyright (C) 2005-2010 Julien Jorge
9
9
This library is free software; you can redistribute it and/or
10
10
modify it under the terms of the GNU Lesser General Public
30
30
#ifndef __CLAW_MULTI_TYPE_MAP_HPP__
31
31
#define __CLAW_MULTI_TYPE_MAP_HPP__
33
#include <claw/meta.hpp>
33
#include <claw/meta/no_type.hpp>
34
#include <claw/meta/type_list.hpp>
38
template<typename ReturnType, typename Map>
40
* \brief This class provides types and methods to allow the call of methods
41
* recursively along the inherintance hierarchy.
42
* \remark This class is to be used internally.
44
* Suppose we have defined the following variable
46
* <tt>multi_type_map<int, type_list<std::string, type_list<int, no_type> > >
49
* The call <tt>int i = my_map.get<int>( 24 );</tt> doesn't match the type
50
* of the end class. So the call is repercuted on the parent class until the
51
* types match. Then, we can get the values in m_data.
53
* \b Template \b parameters
54
* - \a ValueType is the type of the values on which the action is done.
55
* - \a Map is the type of the map in which the action is done.
57
* \author Julien Jorge
59
template<typename ValueType, typename Map>
39
60
class multi_type_map_wrapper;
58
79
* \author Julien Jorge
60
81
template<typename Key, typename TypeList>
62
: public multi_type_map<Key, typename TypeList::queue_type>
85
* \brief Partial specialization, to stop the inheritance recursivity.
87
template<typename Key>
88
class multi_type_map<Key, meta::no_type>
91
}; // class multi_type_map
94
* Here is the interface of multi_type_map
96
template<typename Key, typename Head, typename Tail>
97
class multi_type_map< Key, meta::type_list<Head, Tail> >:
98
public multi_type_map<Key, Tail>
65
101
typedef Key key_type;
66
typedef typename TypeList::head_type value_type;
67
typedef multi_type_map<Key, TypeList> self_type;
68
typedef multi_type_map<Key, typename TypeList::queue_type> super;
102
typedef Head value_type;
103
typedef meta::type_list<Head, Tail> value_type_list;
104
typedef multi_type_map< Key, meta::type_list<Head, Tail> > self_type;
69
105
typedef std::map<key_type, value_type> container_type;
72
struct multi_type_map_wrapper< value_type,
73
multi_type_map<key_type,
74
TypeList> >::last_call;
106
typedef multi_type_map<Key, Tail> super;
108
friend struct multi_type_map_wrapper<value_type, self_type>;
110
/** \brief This structure is used to create an iterator on the values of a
112
template<typename ValueType>
115
/** \brief The type of the iterator. */
116
typedef typename std::map<key_type, ValueType>::iterator type;
118
/** \brief The type of the const_iterator. */
120
typename std::map<key_type, ValueType>::const_iterator const_type;
121
}; // struct iterator
124
typedef typename iterator<value_type>::type iterator_type;
125
typedef typename iterator<value_type>::const_type const_iterator_type;
77
128
template<typename ValueType>
83
134
template<typename ValueType>
84
135
bool exists( const key_type& k ) const;
137
template<typename ValueType>
138
typename iterator<ValueType>::type begin();
140
template<typename ValueType>
141
typename iterator<ValueType>::type end();
143
template<typename ValueType>
144
typename iterator<ValueType>::const_type begin() const;
146
template<typename ValueType>
147
typename iterator<ValueType>::const_type end() const;
87
150
/** \brief Data stored for the first type of the list. */
88
151
container_type m_data;
90
153
}; // class multi_type_map
93
* \brief Partial specialization, to stop the inheritance recursivity.
95
template<typename Key>
96
class multi_type_map<Key, meta::no_type>
99
}; // class multi_type_map
101
155
} // namespace claw
103
157
#include <claw/impl/multi_type_map.tpp>