2 CLAW - a C++ Library Absolutely Wonderful
4 CLAW is a free library without any particular aim but being useful to
7 Copyright (C) 2005-2011 Julien Jorge
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.
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.
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
23 contact: julien.jorge@gamned.org
26 * \file multi_type_map_visitor.tpp
27 * \brief Implementation of the claw::multi_type_map_visitor class.
28 * \author Julien Jorge
34 * \brief This class goes through all entries of a given type in a
35 * multi_type_map and apply a function to them.
36 * \author Julien Jorge
38 template<typename Type>
39 class multi_type_map_visitor_process
42 template<typename Key, typename TailType, typename Function>
44 ( multi_type_map< Key, claw::meta::type_list<Type, TailType> >& m,
47 typedef claw::meta::type_list<Type, TailType> type_list_type;
48 typedef multi_type_map<Key, type_list_type> map_type;
49 typedef typename map_type::template iterator<Type>::type iterator_type;
51 iterator_type it( m.template begin<Type>() );
52 const iterator_type eit( m.template end<Type>() );
56 iterator_type current(it);
58 f(current->first, current->second);
62 }; // class multi_type_map_visitor_process
65 * \brief This class goes through all entries in a multi_type_map and apply a
67 * \author Julien Jorge
69 template<typename Key, typename TypeList>
70 class multi_type_map_visitor_rec;
73 * \brief Specialization of multi_type_map_visitor_rec for an empty type list.
74 * \author Julien Jorge
76 template<typename Key>
77 class multi_type_map_visitor_rec<Key, claw::meta::no_type>
80 template<typename Function>
81 void execute( multi_type_map<Key, claw::meta::no_type>& vars, Function f )
86 }; // class multi_type_map_visitor
89 * \brief Specialization of multi_type_map_visitor_rec for a non empty type
91 * \author Julien Jorge
93 template<typename KeyType, typename HeadType, typename TailType>
94 class multi_type_map_visitor_rec
95 < KeyType, claw::meta::type_list<HeadType, TailType> >
98 template<typename Function>
100 ( multi_type_map< KeyType, claw::meta::type_list<HeadType, TailType> >& m,
103 multi_type_map_visitor_process<HeadType> process;
104 multi_type_map_visitor_rec<KeyType, TailType> rec_call;
106 process.execute( m, f );
107 rec_call.execute( m, f );
110 }; // class multi_type_map_visitor_rec
114/*----------------------------------------------------------------------------*/
116 * \brief Execute the visitor.
117 * \param m The map to visit.
118 * \param f The function to apply to the entries.
120template<typename Key, typename TypeList, typename Function>
121void claw::multi_type_map_visitor::run
122( multi_type_map<Key, TypeList>& m, Function f ) const
124 multi_type_map_visitor_rec<Key, TypeList> rec_call;
125 rec_call.execute( m, f );
126} // multi_type_map_visitor::run()