C++ main module for emicrom Package  1.0
CORE_Map.h
Go to the documentation of this file.
1 #ifndef CORE_Map_H
2 #define CORE_Map_H
3 
4 #include "CORE_Object.h"
5 #include <vector>
6 #include "CORE_Vector.h"
7 #include "CORE_Array.h"
8 
9 using namespace std;
16 template <class Key,class Value>
17 
18  class CORE_Map :public CORE_Object {
19 
20 
21  private:
22 
23  map<Key,Value> mMap;
24 
25 
26 
27 
28  public:
29 
30  // CONSTRUCTORS
31 
32 
37  CORE_Map();
38 
43  CORE_Map(const CORE_Map<Key,Value>& m);
44 
45 
46  // DESTRUCTORS
49  virtual ~CORE_Map();
50 
51 
52 
53  public:
54 
55  // OPERATORS
56 public:
60  void getSharedPointer(boost::shared_ptr<CORE_Map<Key,Value> >& p){
61  SP::CORE_Object r;
63  p=boost::dynamic_pointer_cast<CORE_Map<Key,Value> >(r);
64  };
67  void getSharedPointer( boost::shared_ptr<const CORE_Map<Key,Value> >& p) const{
68  SPC::CORE_Object r;
70  p=boost::dynamic_pointer_cast<const CORE_Map<Key,Value> >(r);
71  };
72 private:
75  inline boost::shared_ptr<CORE_Map<Key,Value> > getThis() {
76  boost::shared_ptr<CORE_Map<Key,Value> > p;
77  getSharedPointer(p);
78  return p;
79  };
82  inline boost::shared_ptr<const CORE_Map<Key,Value> > getThis() const {
83  boost::shared_ptr<const CORE_Map<Key,Value> > p;
84  getSharedPointer(p);
85  return p;
86  };
87 
88 public:
92  static inline boost::shared_ptr<CORE_Map<Key,Value> > New() {
93  boost::shared_ptr<CORE_Map<Key,Value> > p(new CORE_Map<Key,Value>(),
95  p->setThis(p);
96  return p;
97  };
98 
99 public:
104  inline const Value& operator[](const Key& k) const {
105  typename map<Key,Value>::const_iterator iter=mMap.find(k);
106  if (iter==mMap.end())
107  throw CORE_Exception("common/core","CORE_Map[]","key does not exists !");
108  return iter->second;
109  };
110 
115  inline Value& operator[](const Key& k) {
116  typename map<Key,Value>::iterator iter=mMap.find(k);
117  if (iter==mMap.end())
118  throw CORE_Exception("common/core","CORE_Map[]","key does not exists !");
119  return iter->second;
120 
121  };
122 
123  // get METHODS
124 
129  tBoolean exists(const Key& k) const;
130 
134  const Value* get(const Key& k) const;
135 
139  Value* get(const Key& k);
140 
142  inline tUIndex size() const{return (tUIndex) mMap.size();};
143 
145  inline tUIndex getSize() const{return (tUIndex) mMap.size();};
148  inline void values(CORE_Vector<Value>& vals) const {
149  getValues(vals);
150  };
151 
154  void getValues(CORE_Vector<Value>& vals) const;
157  void getValues(CORE_Array<Value>& vals) const;
160  void getValues(vector<Value>& vals) const;
161 
164  inline void keys(CORE_Vector<Key>& ks) const {
165  getKeys(ks);
166  };
167 
170  void getKeys(vector<Key>& ks) const;
171 
174  void getKeys(CORE_Vector<Key>& ks) const;
177  void getKeys(CORE_Array<Key>& ks) const;
178 
179  // set METHODS
180 
183  template<class K2,class V2>
184  void copy(const CORE_Map<K2,V2>& mapCpy);
185 
189  inline void put(const Key& k,const Value& v) {
190  mMap[k]=v;
191  };
195  inline void add(const Value& v) {
196  mMap[(Key)v]=v;
197  };
198 
199 
200 
206  tBoolean remove(const Key& k);
207 
213  tBoolean removeValue(const Value& k);
214 
215 
216 
218  inline void clear() {
219  mMap.clear();
220  };
221 
222 
223 
227  inline typename map<Key,Value>::iterator begin() {
228  return mMap.begin();
229  }
233  inline typename map<Key,Value>::const_iterator begin() const {
234  return mMap.begin();
235  }
239  inline typename map<Key,Value>::iterator end() {
240  return mMap.end();
241  }
242 
243 
247  inline typename map<Key,Value>::const_iterator end() const {
248  return mMap.end();
249  }
250 
251 
252 
255  void merge(const CORE_Map<Key,Value>& m);
256 
257 
258 
259  // other METHODS
260 
261 
262  };
263 
264 #include "CORE_Map.hpp"
265 
272 
273 
274 
275 #endif
void add(const Value &v)
set the value at the index k
Definition: CORE_Map.h:195
CORE_Map< tString, SP::CORE_Object > CORE_StringObjectMap
Definition: CORE_Map.h:268
this class describes an array
Definition: CORE_Vector.h:19
void keys(CORE_Vector< Key > &ks) const
return an array of keys
Definition: CORE_Map.h:164
boost::shared_ptr< CORE_Map< Key, Value > > getThis()
return the shared pointer this
Definition: CORE_Map.h:75
map< Key, Value > mMap
Definition: CORE_Map.h:23
#define tBoolean
Definition: types.h:139
void values(CORE_Vector< Value > &vals) const
return an array of values
Definition: CORE_Map.h:148
Value & operator[](const Key &k)
get object corresponding to k
Definition: CORE_Map.h:115
tUIndex getSize() const
return the size of the array
Definition: CORE_Map.h:145
map< Key, Value >::iterator begin()
get the begin iterator
Definition: CORE_Map.h:227
TYPEDEF_SPTR(CORE_StringRealMap)
void getSharedPointer(boost::shared_ptr< CORE_Map< Key, Value > > &p)
return the shared pointer corresponding to the class with casting
Definition: CORE_Map.h:60
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
void put(const Key &k, const Value &v)
set the value at the index k
Definition: CORE_Map.h:189
map< Key, Value >::iterator end()
get the end iterator
Definition: CORE_Map.h:239
this class describes a map
Definition: CORE_Map.h:18
this class describes an array
Definition: CORE_Array.h:19
static boost::shared_ptr< CORE_Map< Key, Value > > New()
return a CORE_Array shared pointer
Definition: CORE_Map.h:92
void clear()
clear the map
Definition: CORE_Map.h:218
const Value & operator[](const Key &k) const
get object corresponding to k
Definition: CORE_Map.h:104
void getSharedPointer(SP::CORE_Object &p)
get the shared pointer of this class into p
Definition: CORE_Object.h:97
#define tUIndex
Definition: types.h:126
abstract base class for most classes.
Definition: CORE_Object.h:53
CORE_Map< tString, int > CORE_StringIntMap
Definition: CORE_Map.h:267
void getSharedPointer(boost::shared_ptr< const CORE_Map< Key, Value > > &p) const
return the shared pointer corresponding to the class whith casting
Definition: CORE_Map.h:67
CORE_Map< tString, tReal > CORE_StringRealMap
Definition: CORE_Map.h:266
map< Key, Value >::const_iterator begin() const
get the begin iterator
Definition: CORE_Map.h:233
map< Key, Value >::const_iterator end() const
get the end iterator
Definition: CORE_Map.h:247
tUIndex size() const
return the size of the array
Definition: CORE_Map.h:142
boost::shared_ptr< const CORE_Map< Key, Value > > getThis() const
return the shared pointer this
Definition: CORE_Map.h:82
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141