Claw 1.7.0
|
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 */ 00030 #ifndef __CLAW_MULTI_TYPE_MAP_HPP__ 00031 #define __CLAW_MULTI_TYPE_MAP_HPP__ 00032 00033 #include <claw/meta/no_type.hpp> 00034 #include <claw/meta/type_list.hpp> 00035 #include <map> 00036 00037 namespace claw 00038 { 00059 template<typename ValueType, typename Map> 00060 class multi_type_map_wrapper; 00061 00067 template<typename Map> 00068 class multi_type_map_helper; 00069 00089 template<typename Key, typename TypeList> 00090 class multi_type_map; 00091 00095 template<typename Key> 00096 class multi_type_map<Key, meta::no_type> 00097 { 00098 00099 }; // class multi_type_map 00100 00105 template<typename Key, typename Head, typename Tail> 00106 class multi_type_map< Key, meta::type_list<Head, Tail> >: 00107 public multi_type_map<Key, Tail> 00108 { 00109 public: 00110 typedef Key key_type; 00111 typedef Head value_type; 00112 typedef meta::type_list<Head, Tail> value_type_list; 00113 typedef multi_type_map< Key, meta::type_list<Head, Tail> > self_type; 00114 typedef std::map<key_type, value_type> container_type; 00115 typedef multi_type_map<Key, Tail> super; 00116 00117 friend struct multi_type_map_wrapper<value_type, self_type>; 00118 friend struct multi_type_map_helper<self_type>; 00119 00122 template<typename ValueType> 00123 struct iterator 00124 { 00126 typedef typename std::map<key_type, ValueType>::iterator type; 00127 00129 typedef 00130 typename std::map<key_type, ValueType>::const_iterator const_type; 00131 }; // struct iterator 00132 00133 private: 00134 typedef typename iterator<value_type>::type iterator_type; 00135 typedef typename iterator<value_type>::const_type const_iterator_type; 00136 00137 public: 00138 template<typename ValueType> 00139 void erase( typename iterator<ValueType>::type it ); 00140 00141 template<typename ValueType> 00142 std::size_t erase( const key_type& k ); 00143 00144 template<typename ValueType> 00145 const ValueType& get( const key_type& k ) const; 00146 00147 template<typename ValueType> 00148 ValueType& get( const key_type& k ); 00149 00150 template<typename ValueType> 00151 void set( const key_type& k, const ValueType& v ); 00152 00153 void set( const self_type& m ); 00154 00155 template<typename ValueType> 00156 bool exists( const key_type& k ) const; 00157 00158 std::size_t size() const; 00159 00160 template<typename ValueType> 00161 typename iterator<ValueType>::type begin(); 00162 00163 template<typename ValueType> 00164 typename iterator<ValueType>::type end(); 00165 00166 template<typename ValueType> 00167 typename iterator<ValueType>::const_type begin() const; 00168 00169 template<typename ValueType> 00170 typename iterator<ValueType>::const_type end() const; 00171 00172 private: 00174 container_type m_data; 00175 00176 }; // class multi_type_map 00177 00178 } // namespace claw 00179 00180 #include <claw/impl/multi_type_map.tpp> 00181 00182 #endif // __CLAW_MULTI_TYPE_MAP_HPP__