Claw  1.7.3
impl/multi_type_map_visitor.tpp
Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2011 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien.jorge@gamned.org
00024 */
00031 namespace claw
00032 {
00038   template<typename Type>
00039   class multi_type_map_visitor_process
00040   {
00041   public:
00042     template<typename Key, typename TailType, typename Function>
00043     void execute
00044     ( multi_type_map< Key, claw::meta::type_list<Type, TailType> >& m,
00045       Function f )
00046     {
00047       typedef claw::meta::type_list<Type, TailType> type_list_type;
00048       typedef multi_type_map<Key, type_list_type> map_type;
00049       typedef typename map_type::template iterator<Type>::type iterator_type;
00050 
00051       iterator_type it( m.template begin<Type>() );
00052       const iterator_type eit( m.template end<Type>() );
00053 
00054       while ( it!=eit )
00055         {
00056           iterator_type current(it);
00057           ++it;
00058           f(current->first, current->second);
00059         }
00060     } // execute()
00061 
00062   }; // class multi_type_map_visitor_process
00063 
00069   template<typename Key, typename TypeList>
00070   class multi_type_map_visitor_rec;
00071 
00076   template<typename Key>
00077   class multi_type_map_visitor_rec<Key, claw::meta::no_type>
00078   {
00079   public:
00080     template<typename Function>
00081     void execute( multi_type_map<Key, claw::meta::no_type>& vars, Function f )
00082     {
00083       // nothing to do.
00084     } // execute()
00085 
00086   }; // class multi_type_map_visitor
00087 
00093   template<typename KeyType, typename HeadType, typename TailType>
00094   class multi_type_map_visitor_rec
00095   < KeyType, claw::meta::type_list<HeadType, TailType> >
00096   {
00097   public:
00098     template<typename Function>
00099     void execute
00100     ( multi_type_map< KeyType, claw::meta::type_list<HeadType, TailType> >& m,
00101       Function f )
00102     {
00103       multi_type_map_visitor_process<HeadType> process;
00104       multi_type_map_visitor_rec<KeyType, TailType> rec_call;
00105 
00106       process.execute( m, f );
00107       rec_call.execute( m, f );
00108     } // execute()
00109 
00110   }; // class multi_type_map_visitor_rec
00111 
00112 } // namespce claw
00113 
00114 /*----------------------------------------------------------------------------*/
00120 template<typename Key, typename TypeList, typename Function>
00121 void claw::multi_type_map_visitor::run
00122 ( multi_type_map<Key, TypeList>& m, Function f ) const
00123 {
00124   multi_type_map_visitor_rec<Key, TypeList> rec_call;
00125   rec_call.execute( m, f );
00126 } // multi_type_map_visitor::run()