C++ main module for gpm Package  1.0
CORE_SharedPointersKVMap.h
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersKVMap_H
2 #define CORE_SharedPointersKVMap_H
3 
4 #include "boost/shared_ptr.hpp"
5 #include "boost/weak_ptr.hpp"
6 #include "CORE_Object.h"
7 #include "CORE_Pointers.h"
9 #include "CORE_Map.h"
15 template <class Key,class Value>
17  //ATTRIBUTES
18  map<boost::shared_ptr<Key>,boost::shared_ptr<Value> > mMap;
19  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::iterator mIterator;
20  //ASSOCIATION
21 
22  public:
23 
24  //CONSTRUCTORS
26 
31  template <class K,class Q>
33 
34  // DESTRUCTORS
37  virtual ~CORE_SharedPointersKVMap();
38 
39  //OPERATORS
42  inline const boost::shared_ptr<Value>& operator[](const boost::shared_ptr<Key>& k) const {
43  ASSERT_IN(exists(k));
44  return mMap.find(k)->second;
45  };
48  inline boost::shared_ptr<Value>& operator[](const boost::shared_ptr<Key>& k) {
49  ASSERT_IN(exists(k));
50  return mMap.find(k)->second;
51  };
52 
53 
54 
55  // get METHODS
56 
61  tBoolean exists(const boost::shared_ptr<Key>& k) const;
62 
66  const Value* get(const boost::shared_ptr<Key>& k) const;
67 
71  Value* get(const boost::shared_ptr<Key>& k);
72 
74  inline int size() const{return (int) mMap.size();};
75 
77  inline int getSize() const{return (int) mMap.size();};
78 
81  inline void values(CORE_SharedPointersList<Value>& vals) const {
82  getValues(vals);
83  };
84 
87  inline void values(CORE_Vector<Value*>& vals) const {
88  getValues(vals);
89  };
90 
93  void getValues(CORE_Vector<Value*>& vals) const;
96  void getValues(vector<Value*>& vals) const;
97 
100  void getValues(CORE_SharedPointersList<Value>& vals) const;
101 
102 
103 
106  inline void keys(CORE_SharedPointersList<Key>& ks) const {
107  getKeys(ks);
108  };
109 
112  void getKeys(CORE_SharedPointersList<Key>& ks) const;
113 
116  void getKeys(vector<Key*>& ks) const;
117 
120  void getKeys(CORE_Vector<Key*>& ks) const;
121 
124  inline void begin() {
125  mIterator=mMap.begin();
126  }
129  inline tBoolean hasNext() const {
130  return (mIterator!=mMap.end());
131  };
132 
135  inline void next(Key*& k,Value*& v) {
136  v=mIterator->second.get();
137  k=mIterator->first.get();
138  mIterator++;
139  };
140 
141 
142  // set METHODS
143 
146  template<class K,class V>
147  void copy(const CORE_SharedPointersKVMap<K,V>& mapCpy);
148 
152  inline void put(const boost::shared_ptr<const Key>& k,
153  const boost::shared_ptr<const Value>& v) {
154  mMap[k]=v;
155  };
159  inline void put(const boost::shared_ptr<Key>& k,const boost::shared_ptr<Value>& v) {
160  mMap[k]=v;
161  };
162 
163 
164 
165 
171  tBoolean remove(const boost::shared_ptr<Key>& k);
172 
178  tBoolean removeValue(const Value* k);
179 
185  tBoolean removeValue(const Value& k);
186 
192  tBoolean removeValue(boost::shared_ptr<Value>& k);
193 
194 
195 
197  inline void clear() {
198  mMap.clear();
199  };
200 
201 
202 
203 
204 
205 
208  template <class K,class V>
209  void merge(const CORE_SharedPointersKVMap<K,V>& m);
210 
211 
212 
213  public:
214  virtual tString toString() const;
215 };
217 #endif
void values(CORE_SharedPointersList< Value > &vals) const
return an array of values
Definition: CORE_SharedPointersKVMap.h:81
boost::shared_ptr< Value > & operator[](const boost::shared_ptr< Key > &k)
get object corresponding to key
Definition: CORE_SharedPointersKVMap.h:48
tBoolean exists(const boost::shared_ptr< Key > &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersKVMap.hpp:54
void put(const boost::shared_ptr< const Key > &k, const boost::shared_ptr< const Value > &v)
set the value at the index k
Definition: CORE_SharedPointersKVMap.h:152
tBoolean hasNext() const
had next
Definition: CORE_SharedPointersKVMap.h:129
void keys(CORE_SharedPointersList< Key > &ks) const
return an array of keys
Definition: CORE_SharedPointersKVMap.h:106
this class describes an array
Definition: CORE_Vector.h:18
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
CORE_SharedPointersKVMap()
Definition: CORE_SharedPointersKVMap.hpp:7
tBoolean removeValue(const Value *k)
remove the value
Definition: CORE_SharedPointersKVMap.hpp:201
const boost::shared_ptr< Value > & operator[](const boost::shared_ptr< Key > &k) const
get object corresponding to key
Definition: CORE_SharedPointersKVMap.h:42
void clear()
clear the map
Definition: CORE_SharedPointersKVMap.h:197
This class describes a map: shared pointer of Key -> shared pointer of Value.
Definition: CORE_SharedPointersKVMap.h:16
void copy(const CORE_SharedPointersKVMap< K, V > &mapCpy)
copy a map
Definition: CORE_SharedPointersKVMap.hpp:27
#define tBoolean
Definition: types.h:35
void getKeys(CORE_SharedPointersList< Key > &ks) const
return an array of keys
Definition: CORE_SharedPointersKVMap.hpp:145
void merge(const CORE_SharedPointersKVMap< K, V > &m)
merge the map
Definition: CORE_SharedPointersKVMap.hpp:158
void next(Key *&k, Value *&v)
had next
Definition: CORE_SharedPointersKVMap.h:135
void getValues(CORE_Vector< Value * > &vals) const
return an array of values
Definition: CORE_SharedPointersKVMap.hpp:88
int getSize() const
return the size of the array
Definition: CORE_SharedPointersKVMap.h:77
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:36
void put(const boost::shared_ptr< Key > &k, const boost::shared_ptr< Value > &v)
set the value at the index k
Definition: CORE_SharedPointersKVMap.h:159
virtual ~CORE_SharedPointersKVMap()
destroy a map
Definition: CORE_SharedPointersKVMap.hpp:20
int size() const
return the size of the array
Definition: CORE_SharedPointersKVMap.h:74
void begin()
begin
Definition: CORE_SharedPointersKVMap.h:124
void values(CORE_Vector< Value * > &vals) const
return an array of values
Definition: CORE_SharedPointersKVMap.h:87
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersKVMap.hpp:39
#define ASSERT_IN(a)
Definition: types.h:82