C++ main module for gpm Package  1.0
CORE_SharedPointersKVMap.hpp
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersKVMap_CPP
2 #define CORE_SharedPointersKVMap_CPP
3 
5 
6 template<class K,class V>
8 }
9 
13 template<class Key,class Value>
14 template<class K,class V>
16  this();
17  copy(m);
18 }
19 template<class Key,class Value>
21  clear();
22 }
23 
24 
25 template<class Key,class Value>
26 template<class K,class V>
28  clear();
29  vector<boost::shared_ptr<K> > keys;
30  m.getKeys(keys);
31  int n=keys.size();
32  for (int i=0;i<n;i++)
33  put(boost::dynamic_pointer_cast<Key>(keys[i]),boost::dynamic_pointer_cast<Value> (m[keys[i]]));
34 }
35 
36 
37 
38 template<class K,class V>
41  getKeys(ks);
42  int n=ks.size();
43  tString ret=CORE_Object::toString()+"\n";
44  for (int i=0;i<n;i++) {
45  ret+="\t"+ks[i]->toString()+"-->"+get(ks[i])->toString()+"\n";
46  }
47  return ret;
48 }
49 
50 
51 
52 
53 template<class Key,class Value>
54 tBoolean CORE_SharedPointersKVMap<Key,Value>::exists(const boost::shared_ptr<Key>& k) const {
55  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
56  if (iter==mMap.end()) return false;
57  return true;
58 }
59 
60 template<class Key,class Value>
61 const Value* CORE_SharedPointersKVMap<Key,Value>::get(const boost::shared_ptr<Key>& k) const {
62  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
63  if (iter==mMap.end()) return null;
64  return iter->second.get();
65 }
66 
67 template<class Key,class Value>
68 Value* CORE_SharedPointersKVMap<Key,Value>::get(const boost::shared_ptr<Key>& k) {
69  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::iterator iter=mMap.find(k);
70  if (iter==mMap.end()) return null;
71  return iter->second.get();
72 }
73 
74 template<class Key,class Value>
76  tInteger n=mMap.size();
77  vals.clear();
78  vals.setSize(n);
79  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
80  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
81  tInteger i=0;
82  while (iter!=end) {
83  vals.set(i++,iter->second);
84  iter++;
85  }
86 }
87 template<class Key,class Value>
89  tInteger n=mMap.size();
90  vals.clear();
91  vals.setSize(n);
92  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
93  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
94  tInteger i=0;
95  while (iter!=end) {
96  vals[i++]=iter->second.get();
97  iter++;
98  }
99 }
100 template<class Key,class Value>
101 void CORE_SharedPointersKVMap<Key,Value>::getValues(vector<Value*>& vals) const {
102  tInteger n=mMap.size();
103  vals.clear();
104  vals.resize(n);
105  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
106  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
107  tInteger i=0;
108  while (iter!=end) {
109  vals[i++]=iter->second.get();
110  iter++;
111  }
112 }
113 
114 
115 
116 template<class Key,class Value>
117 void CORE_SharedPointersKVMap<Key,Value>::getKeys(vector<Key*>& keys) const {
118  int nbKeys=mMap.size();
119  keys.resize(nbKeys);
120  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
121  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
122  int i=0;
123  while (iter!=end) {
124  keys[i]=iter->first;
125  iter++;
126  i++;
127  }
128 }
129 
130 template<class Key,class Value>
132  int nbKeys=mMap.size();
133  keys.setSize(nbKeys);
134  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
135  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
136  int i=0;
137  while (iter!=end) {
138  keys[i]=iter->first;
139  iter++;
140  i++;
141  }
142 }
143 
144 template<class Key,class Value>
146  keys.clear();
147  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
148  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
149  int i=0;
150  while (iter!=end) {
151  keys.add(iter->first);
152  iter++;
153  i++;
154  }
155 }
156 template<class Key,class Value>
157 template<class K,class V>
160  m.getKeys(ks);
161  int nbKeys=ks.size();
162  for (int i=0;i<nbKeys;i++) {
163  put(boost::dynamic_pointer_cast<Key>(ks[i]),boost::dynamic_pointer_cast<Value>(m[ks[i]]));
164  }
165 }
166 
167 template<class Key,class Value>
168 tBoolean CORE_SharedPointersKVMap<Key,Value>::remove(const boost::shared_ptr<Key>& k) {
169  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator exists=mMap.find(k);
170  if (exists!=mMap.end()) {
171  mMap.erase(k);
172  return true;
173  };
174  return false;
175 };
176 
177 template<class Key,class Value>
179  tBoolean ret=false;
181  getKeys(ks);
182  int n=ks.size();
183  for (int i=0;i<n;i++) {
184  if ((*this)[ks[i]]==v) ret=remove(ks[i]);
185  }
186  return ret;
187 };
188 
189 template<class Key,class Value>
191  tBoolean ret=false;
193  getKeys(ks);
194  int n=ks.size();
195  for (int i=0;i<n;i++) {
196  if (get(ks[i])==v) ret=remove(ks[i]);
197  }
198  return ret;
199 };
200 template<class Key,class Value>
202  tBoolean ret=false;
204  getKeys(ks);
205  int n=ks.size();
206  for (int i=0;i<n;i++) {
207  if (get(ks[i])==v) ret=remove(ks[i]);
208  }
209  return ret;
210 };
211 
212 #endif
tBoolean exists(const boost::shared_ptr< Key > &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersKVMap.hpp:54
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
void clear()
clear the array
Definition: CORE_SharedPointersList.h:206
void add(boost::shared_ptr< T > obj)
add an element at the end
Definition: CORE_SharedPointersList.h:141
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 setSize(const int &n)
set the size of the shared pointers list
Definition: CORE_SharedPointersList.h:94
void merge(const CORE_SharedPointersKVMap< K, V > &m)
merge the map
Definition: CORE_SharedPointersKVMap.hpp:158
const Value * get(const boost::shared_ptr< Key > &k) const
get the value at key k
Definition: CORE_SharedPointersKVMap.hpp:61
#define null
Definition: types.h:13
void getValues(CORE_Vector< Value * > &vals) const
return an array of values
Definition: CORE_SharedPointersKVMap.hpp:88
int size() const
return the size of the array
Definition: CORE_SharedPointersList.h:247
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:36
tBoolean remove(const boost::shared_ptr< Key > &k)
remove the key
Definition: CORE_SharedPointersKVMap.hpp:168
const T & get(int i) const
get the pointer at index i ASSERT_IN(i>-1); ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_Vector.h:367
void setSize(const int &n)
set the size of the array
Definition: CORE_Vector.h:162
virtual ~CORE_SharedPointersKVMap()
destroy a map
Definition: CORE_SharedPointersKVMap.hpp:20
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.cpp:101
tBoolean set(const int &i, const boost::shared_ptr< T > &obj)
set the pointer at the index i
Definition: CORE_SharedPointersList.hpp:127
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersKVMap.hpp:39
void clear()
clear the array
Definition: CORE_Vector.h:350
#define tInteger
Definition: types.h:32