C++ main module for emicrom 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 tUIndex size() const{return mMap.size();};
92 
94  inline tUIndex getSize() const{return 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  if (k!=null) return removeValue(*k);
236  return false;
237  }
238 
244  tBoolean removeValue(const Value& k);
245 
251  tBoolean removeValue(boost::shared_ptr<Value>& k) {
252  return removeValue(k.get());
253  }
254 
255 
256 
258  inline void clear() {
259  mMap.clear();
260  };
261 
262 
263 
264 
265 
266 
269  template <class K,class V>
270  void merge(const CORE_SharedPointersVMap<K,V>& m);
271 
272 
273 
274  public:
275  virtual tString toString() const;
276 };
278 #endif
tBoolean exists(const Key &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersVMap.hpp:52
map< Key, boost::shared_ptr< Value > >::iterator mIterator
Definition: CORE_SharedPointersVMap.h:18
const boost::shared_ptr< Value > operator[](const Key &k) const
get object corresponding to key
Definition: CORE_SharedPointersVMap.h:43
void getValues(CORE_Vector< Value *> &vals) const
return an array of values
Definition: CORE_SharedPointersVMap.hpp:100
void next(Key &k, boost::shared_ptr< Value > &v)
has next
Definition: CORE_SharedPointersVMap.h:151
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:19
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 Value & operator()(const Key &k) const
get object corresponding to key
Definition: CORE_SharedPointersVMap.h:61
boost::shared_ptr< Value > currentValue()
current value
Definition: CORE_SharedPointersVMap.h:176
map< Key, boost::shared_ptr< Value > > mMap
Definition: CORE_SharedPointersVMap.h:17
#define tBoolean
Definition: types.h:139
#define null
Definition: types.h:144
void nextElement()
next element
Definition: CORE_SharedPointersVMap.h:158
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
const Key & currentKey() const
current key
Definition: CORE_SharedPointersVMap.h:165
this class describes an array
Definition: CORE_Array.h:19
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersVMap.hpp:39
tBoolean removeValue(boost::shared_ptr< Value > &k)
remove the value
Definition: CORE_SharedPointersVMap.h:251
tUIndex size() const
return the size of the array
Definition: CORE_SharedPointersVMap.h:91
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:162
tBoolean put(const Key &k, Value &v)
set the value at the index k
Definition: CORE_SharedPointersVMap.h:199
#define tUIndex
Definition: types.h:126
void clear()
clear the map
Definition: CORE_SharedPointersVMap.h:258
abstract base class for most classes.
Definition: CORE_Object.h:53
tBoolean removeValue(const Value *k)
remove the value
Definition: CORE_SharedPointersVMap.h:234
Value & operator()(const Key &k)
get object corresponding to key
Definition: CORE_SharedPointersVMap.h:66
#define tString
Definition: types.h:135
tBoolean hasNext() const
had next
Definition: CORE_SharedPointersVMap.h:133
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
void getKeys(vector< Key > &ks) const
return a vector of keys
Definition: CORE_SharedPointersVMap.hpp:131
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
tUIndex getSize() const
return the size of the array
Definition: CORE_SharedPointersVMap.h:94
const boost::shared_ptr< Value > currentValue() const
current value
Definition: CORE_SharedPointersVMap.h:171