fw4spl
ArrayMapper.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_MAPPER_ARRAYMAPPER_HPP__
8 #define __FWCAMP_MAPPER_ARRAYMAPPER_HPP__
9 
10 #include <set>
11 
12 #include <camp/valuemapper.hpp>
13 #include <camp/type.hpp>
14 #include <camp/camptype.hpp>
15 
16 namespace camp_ext
17 {
18 /*
19  * Specialization of ArrayMapper for std::set
20  */
21 template <typename T>
22 struct ArrayMapper<std::set<T> >
23 {
24  typedef T ElementType;
25 
26  static bool dynamic()
27  {
28  return true;
29  }
30 
31  static std::size_t size(const std::set<T>& arr)
32  {
33  return arr.size();
34  }
35 
36  static const T& get(const std::set<T>& arr, std::size_t index)
37  {
38  typename std::set<T>::const_iterator cIt = arr.begin();
39  for(int i = 0; i < index; i++)
40  {
41  ++cIt;
42  }
43  return *cIt;
44  }
45 
46  static void set(std::set<T>& arr, std::size_t index, const T& value)
47  {
48  }
49 
50  static void insert(std::set<T>& arr, std::size_t before, const T& value)
51  {
52  arr.insert(value);
53  }
54 
55  static void remove(std::set<T>& arr, std::size_t index)
56  {
57  typename std::set<T>::const_iterator cIt = arr.begin();
58  for(int i = 0; i < index; ++i)
59  {
60  ++cIt;
61  }
62  arr.erase(cIt);
63  }
64 };
65 
66 
67 } //camp_ext
68 
69 
70 #endif /* __FWCAMP_MAPPER_ARRAYMAPPER_HPP__ */
STL namespace.