C++ main module for gpm 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  typename map<Key,Value>::iterator mIterator;
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:
59  void getSharedPointer(boost::shared_ptr<CORE_Map<Key,Value> >& p){
60  SP::CORE_Object r;
62  p=boost::dynamic_pointer_cast<CORE_Map<Key,Value> >(r);
63  };
66  void getSharedPointer( boost::shared_ptr<const CORE_Map<Key,Value> >& p) const{
67  SPC::CORE_Object r;
69  p=boost::dynamic_pointer_cast<const CORE_Map<Key,Value> >(r);
70  };
71 private:
74  inline boost::shared_ptr<CORE_Map<Key,Value> > getThis() {
75  boost::shared_ptr<CORE_Map<Key,Value> > p;
76  getSharedPointer(p);
77  return p;
78  };
81  inline boost::shared_ptr<const CORE_Map<Key,Value> > getThis() const {
82  boost::shared_ptr<const CORE_Map<Key,Value> > p;
83  getSharedPointer(p);
84  return p;
85  };
86 
87 public:
90  static inline boost::shared_ptr<CORE_Map<Key,Value> > New() {
91  boost::shared_ptr<CORE_Map<Key,Value> > p(new CORE_Map<Key,Value>(),
93  p->setThis(p);
94  return p;
95  };
96 
97 public:
100  inline const Value& operator[](const Key& k) const {
101  ASSERT_IN(exists(k));
102  return mMap.find(k)->second;
103  };
104 
107  inline Value& operator[](const Key& k) {
108  ASSERT_IN(exists(k));
109  return mMap.find(k)->second;
110  };
111 
112  // get METHODS
113 
118  tBoolean exists(const Key& k) const;
119 
123  const Value* get(const Key& k) const;
124 
128  Value* get(const Key& k);
129 
131  inline int size() const{return (int) mMap.size();};
132 
134  inline int getSize() const{return (int) mMap.size();};
137  inline void values(CORE_Vector<Value>& vals) const {
138  getValues(vals);
139  };
140 
143  void getValues(CORE_Vector<Value>& vals) const;
146  void getValues(CORE_Array<Value>& vals) const;
149  void getValues(vector<Value>& vals) const;
150 
153  inline void keys(CORE_Vector<Key>& ks) const {
154  getKeys(ks);
155  };
156 
159  void getKeys(vector<Key>& ks) const;
160 
163  void getKeys(CORE_Vector<Key>& ks) const;
166  void getKeys(CORE_Array<Key>& ks) const;
167 
168  // set METHODS
169 
172  template<class K2,class V2>
173  void copy(const CORE_Map<K2,V2>& mapCpy);
174 
178  inline void put(const Key& k,const Value& v) {
179  mMap[k]=v;
180  };
184  inline void add(const Value& v) {
185  mMap[(Key)v]=v;
186  };
187 
188 
189 
195  tBoolean remove(const Key& k);
196 
202  tBoolean removeValue(const Value& k);
203 
204 
205 
207  inline void clear() {
208  mMap.clear();
209  };
210 
211 
212 
215  inline void begin() {
216  mIterator=mMap.begin();
217  }
218 
221  inline tBoolean hasNext() const{
222  return (mIterator!=mMap.end());
223  };
224 
227  inline void next(Key& k,Value*& v) {
228  v=&(mIterator->second);
229  k=mIterator->first;
230  mIterator++;
231  };
232 
233 
234 
235 
236 
237 
240  void merge(const CORE_Map<Key,Value>& m);
241 
242 
243 
244  // other METHODS
245 
246 
247  };
248 
249 #include "CORE_Map.hpp"
250 
255 
256 
257 #endif
void values(CORE_Vector< Value > &vals) const
return an array of values
Definition: CORE_Map.h:137
void add(const Value &v)
set the value at the index k
Definition: CORE_Map.h:184
this class describes an array
Definition: CORE_Vector.h:18
void keys(CORE_Vector< Key > &ks) const
return an array of keys
Definition: CORE_Map.h:153
#define tBoolean
Definition: types.h:35
Value & operator[](const Key &k)
get object corresponding to key
Definition: CORE_Map.h:107
int getSize() const
return the size of the array
Definition: CORE_Map.h:134
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:59
int size() const
return the size of the array
Definition: CORE_Map.h:131
void put(const Key &k, const Value &v)
set the value at the index k
Definition: CORE_Map.h:178
this class describes a map
Definition: CORE_Map.h:18
this class describes an array
Definition: CORE_Array.h:18
static boost::shared_ptr< CORE_Map< Key, Value > > New()
return a CORE_Array shared pointer
Definition: CORE_Map.h:90
void clear()
clear the map
Definition: CORE_Map.h:207
tBoolean hasNext() const
had next
Definition: CORE_Map.h:221
void getSharedPointer(SP::CORE_Object &p)
get the shared pointer of this class into p
Definition: CORE_Object.h:65
void begin()
begin
Definition: CORE_Map.h:215
abstract base class for most classes.
Definition: CORE_Object.h:30
CORE_Map< tString, int > CORE_StringIntMap
Definition: CORE_Map.h:252
void next(Key &k, Value *&v)
had next
Definition: CORE_Map.h:227
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:66
CORE_Map< tString, tReal > CORE_StringRealMap
Definition: CORE_Map.h:251
const Value & operator[](const Key &k) const
get object corresponding to key
Definition: CORE_Map.h:100
#define ASSERT_IN(a)
Definition: types.h:82
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106