fw4spl
Map.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 __FWATOMS_MAP_HPP__
8 #define __FWATOMS_MAP_HPP__
9 
10 #include "fwAtoms/Base.hpp"
11 #include "fwAtoms/config.hpp"
12 #include "fwAtoms/factory/new.hpp"
13 #include "fwAtoms/Object.hpp"
14 
15 #include <map>
16 #include <string>
17 
18 namespace fwAtoms
19 {
20 
31 class FWATOMS_CLASS_API Map : public Base
32 {
33 public:
34  fwCoreClassDefinitionsWithFactoryMacro( (Map)(::fwAtoms::Base), (()), ::fwAtoms::factory::New< Map >);
35 
36  typedef std::map<std::string, Base::sptr> MapType;
37 
38  typedef MapType::key_type KeyType;
39  typedef MapType::mapped_type MappedType;
40  typedef MapType::value_type ValueType;
41  typedef MapType::iterator IteratorType;
42  typedef MapType::const_iterator ConstIteratorType;
43  typedef MapType::reverse_iterator ReverseIteratorType;
44  typedef MapType::const_reverse_iterator ConstReverseIteratorType;
45  typedef MapType::size_type SizeType;
46 
49  typedef MapType::key_type key_type;
50  typedef MapType::mapped_type mapped_type;
51  typedef MapType::value_type value_type;
52  typedef MapType::iterator iterator;
53  typedef MapType::const_iterator const_iterator;
54  typedef MapType::reverse_iterator reverse_iterator;
55  typedef MapType::const_reverse_iterator const_reverse_iterator;
56  typedef MapType::size_type size_type;
58 
64  {
65  }
66 
70  virtual ~Map()
71  {
72  }
73 
79  std::pair<IteratorType, bool> insert(const std::string& key, const Base::sptr& value)
80  {
81  return m_value.insert( ValueType(key, value) );
82  }
83 
88  size_t size() const
89  {
90  return m_value.size();
91  }
92 
97  IteratorType begin()
98  {
99  return m_value.begin();
100  }
101 
106  ConstIteratorType begin() const
107  {
108  return m_value.begin();
109  }
110 
114  IteratorType end()
115  {
116  return m_value.end();
117  }
118 
122  ConstIteratorType end() const
123  {
124  return m_value.end();
125  }
126 
128  void clear()
129  {
130  m_value.clear();
131  }
132 
137  bool empty() const
138  {
139  return m_value.empty();
140  }
141 
145  const MapType& getValue() const
146  {
147  return m_value;
148  }
149 
156  MapType::const_iterator find(const std::string& key) const
157  {
158  return m_value.find(key);
159  }
160 
167  Base::sptr operator[](const std::string& key)
168  {
169  return m_value[key];
170  }
171 
175  FWATOMS_API virtual Base::sptr clone() const override;
176 
180  ::fwAtoms::Base::AtomType type() const override
181  {
182  return ::fwAtoms::Base::MAP;
183  }
184 
185 protected:
186  MapType m_value;
187 };
188 
189 }
190 
191 #endif /* __FWATOMS_MAP_HPP__ */
192 
MapType::const_iterator const_iterator
Definition: Map.hpp:53
fwAtoms contains basic objects to represent any other kind of object
MapType::iterator iterator
Definition: Map.hpp:52
Base::sptr operator[](const std::string &key)
Access to a member with [].
Definition: Map.hpp:167
MapType::const_iterator find(const std::string &key) const
find an element in the map
Definition: Map.hpp:156
Map(::fwAtoms::Base::Key key)
Constructor.
Definition: Map.hpp:63
MapType::reverse_iterator reverse_iterator
Definition: Map.hpp:54
const MapType & getValue() const
returns atom&#39;s map
Definition: Map.hpp:145
void clear()
clear the map
Definition: Map.hpp:128
ConstIteratorType end() const
Return a const iterator after the last element in the map.
Definition: Map.hpp:122
Map is a container for mapping representation.
Definition: Map.hpp:31
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
std::pair< IteratorType, bool > insert(const std::string &key, const Base::sptr &value)
Insert a new value in the map.
Definition: Map.hpp:79
MapType::mapped_type mapped_type
Definition: Map.hpp:50
MapType::const_reverse_iterator const_reverse_iterator
Definition: Map.hpp:55
IteratorType begin()
Provide an iterator on the first element.
Definition: Map.hpp:97
::fwAtoms::Base::AtomType type() const override
returns Atom type
Definition: Map.hpp:180
size_t size() const
retrieve size of map
Definition: Map.hpp:88
MapType::key_type key_type
Definition: Map.hpp:49
bool empty() const
test if the map is empty
Definition: Map.hpp:137
ConstIteratorType begin() const
Provide a const iterator on the first element.
Definition: Map.hpp:106
MapType::value_type value_type
Definition: Map.hpp:51
MapType::size_type size_type
Definition: Map.hpp:56
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
Base class for all Atom classes.
IteratorType end()
Return an iterator after the last element in the map.
Definition: Map.hpp:114
virtual ~Map()
Destructor.
Definition: Map.hpp:70