fw4spl
MapMapper.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWCAMP_CAMP_MAPMAPPER_HPP__
8 #define __FWCAMP_CAMP_MAPMAPPER_HPP__
9 
10 #include <boost/utility/enable_if.hpp>
11 #include "fwCamp/camp/traits.hpp"
12 
13 namespace camp_ext
14 {
15 
16 template <typename T, typename C = void>
17 struct MapMapper
18 {
19 };
20 
21 template <typename MAP>
22 struct MapMapper< MAP, typename boost::enable_if_c<camp::isMapping<MAP>::value>::type >
23 {
24  typedef MAP MapType;
25  typedef typename MapType::value_type ValueType;
26  typedef typename MapType::key_type KeyType;
27  typedef typename MapType::mapped_type MappedType;
28 
29 
30  static std::size_t size(const MapType& map)
31  {
32  return map.size();
33  }
34 
35  static const ValueType& get(const MapType& map, std::size_t index)
36  {
37  typename MapType::const_iterator it = map.begin();
38  std::advance(it, index);
39  return *it;
40  }
41 
42  static void set(MapType& map, const KeyType & key, const MappedType& value)
43  {
44  map[key] = value;
45  }
46 };
47 
48 } // namespace camp_ext
49 
50 
51 
52 
53 #endif /* __FWCAMP_CAMP_MAPMAPPER_HPP__ */