C++ main module for gpm Package  1.0
CORE_SharedPointersVMap.h
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersVMap_H
2 #define CORE_SharedPointersVMap_H
3 
4 #include "boost/shared_ptr.hpp"
5 #include "boost/weak_ptr.hpp"
6 #include "CORE_Object.h"
8 #include "CORE_Map.h"
14 template <class Key,class Value>
16  //ATTRIBUTES
17  map<Key,boost::shared_ptr<Value> > mMap;
18  typename map<Key,boost::shared_ptr<Value> >::iterator mIterator;
19 
20 
21  //ASSOCIATION
22 
23  public:
24 
25  //CONSTRUCTORS
27 
32  template <class K,class Q>
34 
35  // DESTRUCTORS
38  virtual ~CORE_SharedPointersVMap();
39 
40  //OPERATORS
43  inline const boost::shared_ptr<Value> operator[](const Key& k) const {
44  const boost::shared_ptr<Value> ret;
45  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
46  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
47  if (iter!=end) return iter->second;
48  return ret;
49  };
52  inline boost::shared_ptr<Value> operator[](const Key& k) {
53  boost::shared_ptr<Value> ret;
54  typename map<Key,boost::shared_ptr<Value> >::iterator iter=mMap.find(k);
55  if (iter!=mMap.end()) return iter->second;
56  return ret;
57 
58  };
61  inline const Value& operator()(const Key& k) const {
62  return *(*this)[k].get();
63  };
66  inline Value& operator()(const Key& k) {
67  return *(*this)[k].get();
68  };
69 
70 
71 
72  // get METHODS
73 
78  tBoolean exists(const Key& k) const;
79 
83  const Value* get(const Key& k) const;
84 
88  Value* get(const Key& k);
89 
91  inline int size() const{return (int) mMap.size();};
92 
94  inline int getSize() const{return (int) mMap.size();};
95 
96 
99  void getValues(CORE_Vector<Value*>& vals) const;
100 
103  void getValues(vector<Value*>& vals) const;
104 
111 
112 
115  void getKeys(vector<Key>& ks) const;
116 
119  void getKeys(CORE_Vector<Key>& ks) const;
120 
123  void getKeys(CORE_Array<Key>& ks) const;
124 
125 
128  inline void begin() {
129  mIterator=mMap.begin();
130  }
133  inline tBoolean hasNext() const {
134  return (mIterator!=mMap.end());
135  };
138  inline tBoolean hasNextElement() const {
139  return (mIterator!=mMap.end());
140  };
141 
144  inline void next(Key& k,Value*& v) {
145  v=mIterator->second.get();
146  k=mIterator->first;
147  mIterator++;
148  };
151  inline void next(Key& k,boost::shared_ptr<Value>& v) {
152  v=mIterator->second;
153  k=mIterator->first;
154  mIterator++;
155  };
158  inline void nextElement() {
159  mIterator++;
160  };
161 
162 
165  inline const Key& currentKey() const {
166  return mIterator->first;
167  };
168 
171  inline const boost::shared_ptr<Value> currentValue() const {
172  return mIterator->second;
173  };
176  inline boost::shared_ptr<Value> currentValue() {
177  return mIterator->second;
178  };
179 
180 
181  // set METHODS
182 
185  template<class K,class V>
186  void copy(const CORE_SharedPointersVMap<K,V>& mapCpy);
187 
188 
192  inline tBoolean put(const Key& k,const boost::shared_ptr<Value>& v) {
193  mMap[k]=v;
194  return true;
195  };
199  inline tBoolean put(const Key& k,Value& v) {
200  boost::shared_ptr<Value> p_v;
201  v.getSharedPointer(p_v);
202  mMap[k]=p_v;
203  return true;
204  };
208  inline tBoolean put(const Key& k,Value* v) {
209  boost::shared_ptr<Value> p_v;
210  if (v!=null) {
211  v->getSharedPointer(p_v);
212  mMap[k]=p_v;
213  return true;
214  }
215  return false;
216  };
217 
218 
219 
220 
221 
227  tBoolean remove(const Key& k);
228 
234  tBoolean removeValue(const Value* k);
235 
241  tBoolean removeValue(const Value& k);
242 
248  tBoolean removeValue(boost::shared_ptr<Value>& k);
249 
250 
251 
253  inline void clear() {
254  mMap.clear();
255  };
256 
257 
258 
259 
260 
261 
264  template <class K,class V>
265  void merge(const CORE_SharedPointersVMap<K,V>& m);
266 
267 
268 
269  public:
270  virtual tString toString() const;
271 };
273 #endif
tBoolean exists(const Key &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersVMap.hpp:52
const Key & currentKey() const
current key
Definition: CORE_SharedPointersVMap.h:165
void next(Key &k, boost::shared_ptr< Value > &v)
has next
Definition: CORE_SharedPointersVMap.h:151
int getSize() const
return the size of the array
Definition: CORE_SharedPointersVMap.h:94
void copy(const CORE_SharedPointersVMap< K, V > &mapCpy)
copy a map
Definition: CORE_SharedPointersVMap.hpp:28
this class describes an array
Definition: CORE_Vector.h:18
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
tBoolean hasNextElement() const
had next element
Definition: CORE_SharedPointersVMap.h:138
void next(Key &k, Value *&v)
has next
Definition: CORE_SharedPointersVMap.h:144
const boost::shared_ptr< Value > currentValue() const
current value
Definition: CORE_SharedPointersVMap.h:171
boost::shared_ptr< Value > currentValue()
current value
Definition: CORE_SharedPointersVMap.h:176
#define tBoolean
Definition: types.h:35
void getKeys(vector< Key > &ks) const
return a vector of keys
Definition: CORE_SharedPointersVMap.hpp:129
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersVMap.hpp:39
void getValues(CORE_Vector< Value * > &vals) const
return an array of values
Definition: CORE_SharedPointersVMap.hpp:100
#define null
Definition: types.h:13
void nextElement()
next element
Definition: CORE_SharedPointersVMap.h:158
const Value & operator()(const Key &k) const
get object corresponding to key
Definition: CORE_SharedPointersVMap.h:61
This class describes a map: primitive type of Key -> shared pointer of Value.
Definition: CORE_SharedPointersVMap.h:15
virtual ~CORE_SharedPointersVMap()
destroy a map
Definition: CORE_SharedPointersVMap.hpp:22
this class describes an array
Definition: CORE_Array.h:18
boost::shared_ptr< Value > operator[](const Key &k)
get object corresponding to key
Definition: CORE_SharedPointersVMap.h:52
void merge(const CORE_SharedPointersVMap< K, V > &m)
merge the map
Definition: CORE_SharedPointersVMap.hpp:169
tBoolean put(const Key &k, Value &v)
set the value at the index k
Definition: CORE_SharedPointersVMap.h:199
int size() const
return the size of the array
Definition: CORE_SharedPointersVMap.h:91
const boost::shared_ptr< Value > operator[](const Key &k) const
get object corresponding to key
Definition: CORE_SharedPointersVMap.h:43
void clear()
clear the map
Definition: CORE_SharedPointersVMap.h:253
abstract base class for most classes.
Definition: CORE_Object.h:30
tBoolean removeValue(const Value *k)
remove the value
Definition: CORE_SharedPointersVMap.hpp:212
Value & operator()(const Key &k)
get object corresponding to key
Definition: CORE_SharedPointersVMap.h:66
#define tString
Definition: types.h:36
tBoolean put(const Key &k, Value *v)
set the value at the index k
Definition: CORE_SharedPointersVMap.h:208
void begin()
begin
Definition: CORE_SharedPointersVMap.h:128
CORE_SharedPointersVMap()
Definition: CORE_SharedPointersVMap.hpp:7
tBoolean put(const Key &k, const boost::shared_ptr< Value > &v)
set the value at the index k
Definition: CORE_SharedPointersVMap.h:192
tBoolean hasNext() const
had next
Definition: CORE_SharedPointersVMap.h:133