multi_type_map.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-2008 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@yahoo.fr
00024 */
00030 #include <claw/assert.hpp>
00031 
00032 namespace claw
00033 {
00049   template<typename ValueType, typename Map>
00050   class multi_type_map_wrapper
00051   {
00052   public:
00057     class last_call
00058     {
00059     public:
00060       const ValueType&
00061       get( const Map& self, const typename Map::key_type& k ) const;
00062       void set( Map& self, const typename Map::key_type& k,
00063     const ValueType& v ) const;
00064       bool exists( const Map& self, const typename Map::key_type& k ) const;
00065 
00066     }; // class last_call
00067 
00072     class recursive_call
00073     {
00074     public:
00075       const ValueType&
00076       get( const Map& self, const typename Map::key_type& k ) const;
00077       void set( Map& self, const typename Map::key_type& k,
00078     const ValueType& v ) const;
00079       bool exists( const Map& self, const typename Map::key_type& k ) const;
00080 
00081     }; // class recursive_call
00082     
00083   public:
00088     typedef typename meta::if_then_else
00089     < meta::same_type<ValueType, typename Map::value_type>::result,
00090       last_call, recursive_call >::result method_type;
00091 
00092   }; // class multi_type_map_wrapper
00093 
00094 } // namespace claw
00095 
00096 
00097 
00098 
00099 /*----------------------------------------------------------------------------*/
00105 template<typename ValueType, typename Map>
00106 const ValueType& claw::multi_type_map_wrapper<ValueType, Map>::last_call::get
00107 ( const Map& self, const typename Map::key_type& k ) const
00108 {
00109   CLAW_PRECOND( exists(self, k) );
00110 
00111   return self.m_data.find(k)->second;
00112 } // multi_type_map_wrapper::last_call::get()
00113 
00114 /*----------------------------------------------------------------------------*/
00121 template<typename ValueType, typename Map>
00122 void claw::multi_type_map_wrapper<ValueType, Map>::last_call::set
00123 ( Map& self, const typename Map::key_type& k, const ValueType& v ) const
00124 {
00125   self.m_data[k] = v;
00126 } // multi_type_map_wrapper::last_call::set()
00127 
00128 /*----------------------------------------------------------------------------*/
00134 template<typename ValueType, typename Map>
00135 bool claw::multi_type_map_wrapper<ValueType, Map>::last_call::exists
00136 ( const Map& self, const typename Map::key_type& k ) const
00137 {
00138   return self.m_data.find(k) != self.m_data.end();
00139 } // multi_type_map_wrapper::last_call::exists()
00140 
00141 
00142 
00143 
00144 /*----------------------------------------------------------------------------*/
00150 template<typename ValueType, typename Map>
00151 const ValueType&
00152 claw::multi_type_map_wrapper<ValueType, Map>::recursive_call::get
00153 ( const Map& self, const typename Map::key_type& k ) const
00154 {
00155   typename
00156     multi_type_map_wrapper<ValueType, typename Map::super>::method_type w;
00157   const typename Map::super& m = self;
00158 
00159   return w.get( m, k );
00160 } // multi_type_map_wrapper::recursive_call::get()
00161 
00162 /*----------------------------------------------------------------------------*/
00169 template<typename ValueType, typename Map>
00170 void claw::multi_type_map_wrapper<ValueType, Map>::recursive_call::set
00171 ( Map& self, const typename Map::key_type& k, const ValueType& v ) const
00172 {
00173   typename
00174     multi_type_map_wrapper<ValueType, typename Map::super>::method_type w;
00175   typename Map::super& m = self;
00176 
00177   w.set( m, k, v );
00178 } // multi_type_map_wrapper::recursive_call::set()
00179 
00180 /*----------------------------------------------------------------------------*/
00186 template<typename ValueType, typename Map>
00187 bool claw::multi_type_map_wrapper<ValueType, Map>::recursive_call::exists
00188 ( const Map& self, const typename Map::key_type& k ) const
00189 {
00190   typename
00191     multi_type_map_wrapper<ValueType, typename Map::super>::method_type w;
00192   const typename Map::super& m = self;
00193 
00194   return w.exists( m, k );
00195 } // multi_type_map_wrapper::recursive_call::exists()
00196 
00197 
00198 
00199 
00200 
00201 /*----------------------------------------------------------------------------*/
00206 template<typename Key, typename TypeList>
00207 template<typename ValueType>
00208 const ValueType&
00209 claw::multi_type_map<Key, TypeList>::get( const key_type& k ) const
00210 {
00211   typename multi_type_map_wrapper<ValueType, self_type>::method_type w;
00212   return w.get( *this, k );
00213 } // multi_type_map::get()
00214 
00215 /*----------------------------------------------------------------------------*/
00221 template<typename Key, typename TypeList>
00222 template<typename ValueType>
00223 void claw::multi_type_map<Key, TypeList>::set
00224 ( const key_type& k, const ValueType& v )
00225 {
00226   typename multi_type_map_wrapper<ValueType, self_type>::method_type w;
00227   w.set( *this, k, v);
00228 } // multi_type_map::set()
00229 
00230 /*----------------------------------------------------------------------------*/
00235 template<typename Key, typename TypeList>
00236 template<typename ValueType>
00237 bool claw::multi_type_map<Key, TypeList>::exists( const key_type& k ) const
00238 {
00239   typename multi_type_map_wrapper<ValueType, self_type>::method_type w;
00240   return w.exists( *this, k );
00241 } // multi_type_map::exists()

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1