C++ main module for gpm Package  1.0
CORE_SharedPointersVMap.hpp
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersVMap_CPP
2 #define CORE_SharedPointersVMap_CPP
3 
5 
6 template<class K,class V>
8 
9 }
10 
14 template<class Key,class Value>
15 template<class K,class V>
17  copy(m);
18 }
19 
20 
21 template<class Key,class Value>
23  clear();
24 }
25 
26 template<class Key,class Value>
27 template<class K,class V>
29  clear();
30  vector<K> keys;
31  m.getKeys(keys);
32  int n=keys.size();
33  for (int i=0;i<n;i++)
34  put((Key)keys[i],boost::dynamic_pointer_cast<Value>(m[keys[i]]));
35 }
36 
37 
38 template<class K,class V>
40  vector<K> ks;
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"+CORE_String::toString(ks[i])+"-->"+get(ks[i])->toString()+"\n";
46  }
47  return ret;
48 }
49 
50 
51 template<class Key,class Value>
53  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
54  if (iter==mMap.end()) return false;
55  return true;
56 }
57 
58 template<class Key,class Value>
59 const Value* CORE_SharedPointersVMap<Key,Value>::get(const Key& k) const {
60  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
61  if (iter==mMap.end()) return null;
62  return iter->second.get();
63 }
64 
65 template<class Key,class Value>
67  typename map<Key,boost::shared_ptr<Value> >::iterator iter=mMap.find(k);
68  if (iter==mMap.end()) return null;
69  return iter->second.get();
70 }
71 
72 template<class Key,class Value>
74  tInteger n=mMap.size();
75  vals.clear();
76  vals.setSize(n);
77  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
78  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
79  tInteger i=0;
80  while (iter!=end) {
81  vals.set(i++,iter->second);
82  iter++;
83  }
84 }
85 template<class Key,class Value>
87  tInteger n=mMap.size();
88  vals.clear();
89  vals.setSize(n);
90  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
91  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
92  tInteger i=0;
93  while (iter!=end) {
94  vals.set(i++,iter->second);
95  iter++;
96  }
97 }
98 
99 template<class Key,class Value>
101  tInteger n=mMap.size();
102  vals.clear();
103  vals.setSize(n);
104  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
105  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
106  tInteger i=0;
107  while (iter!=end) {
108  vals[i++]=iter->second.get();
109  iter++;
110  }
111 }
112 template<class Key,class Value>
113 void CORE_SharedPointersVMap<Key,Value>::getValues(vector<Value*>& vals) const {
114  tInteger n=mMap.size();
115  vals.clear();
116  vals.resize(n);
117  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
118  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
119  tInteger i=0;
120  while (iter!=end) {
121  vals[i++]=iter->second.get();
122  iter++;
123  }
124 }
125 
126 
127 
128 template<class Key,class Value>
129 void CORE_SharedPointersVMap<Key,Value>::getKeys(vector<Key>& keys) const {
130  int nbKeys=mMap.size();
131  keys.resize(nbKeys);
132  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
133  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
134  int i=0;
135  while (iter!=end) {
136  keys[i]=iter->first;
137  iter++;
138  i++;
139  }
140 }
141 
142 template<class Key,class Value>
144  keys.clear();
145  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
146  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
147  int i=0;
148  while (iter!=end) {
149  keys.add(iter->first);
150  iter++;
151  i++;
152  }
153 }
154 template<class Key,class Value>
156  keys.clear();
157  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
158  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
159  int i=0;
160  while (iter!=end) {
161  keys.add(iter->first);
162  iter++;
163  i++;
164  }
165 }
166 
167 template<class Key,class Value>
168 template<class K,class V>
170  vector<K> ks;
171  m.getKeys(ks);
172  int nbKeys=ks.size();
173  for (int i=0;i<nbKeys;i++) {
174  put((Key)ks[i],boost::dynamic_pointer_cast<Value>(m[ks[i]]));
175  }
176 }
177 
178 template<class Key,class Value>
180  typename map<Key,boost::shared_ptr<Value> >::const_iterator exists=mMap.find(k);
181  if (exists!=mMap.end()) {
182  mMap.erase(k);
183  return true;
184  };
185  return false;
186 };
187 
188 template<class Key,class Value>
190  tBoolean ret=false;
191  vector<Key> ks;
192  getKeys(ks);
193  int n=ks.size();
194  for (int i=0;i<n;i++) {
195  if ((*this)[ks[i]]==v) ret=remove(ks[i]);
196  }
197  return ret;
198 };
199 
200 template<class Key,class Value>
202  tBoolean ret=false;
203  vector<Key> ks;
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 template<class Key,class Value>
213  tBoolean ret=false;
214  vector<Key> ks;
215  getKeys(ks);
216  int n=ks.size();
217  for (int i=0;i<n;i++) {
218  if (get(ks[i])==v) ret=remove(ks[i]);
219  }
220  return ret;
221 };
222 
223 
224 #endif
tBoolean exists(const Key &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersVMap.hpp:52
virtual void clear()
clear the array
Definition: CORE_Array.h:489
tString toString() const
return the string associated to the string
Definition: CORE_String.h:150
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
void clear()
clear the array
Definition: CORE_SharedPointersList.h:206
tBoolean remove(const Key &k)
remove the key
Definition: CORE_SharedPointersVMap.hpp:179
#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
void add(const CORE_Vector< T > &v)
init the value to v
Definition: CORE_Vector.h:206
void setSize(const int &n)
set the size of the shared pointers list
Definition: CORE_SharedPointersList.h:94
#define null
Definition: types.h:13
void add(const T &obj)
add an element at the end re-allocate the array if capacity too small
Definition: CORE_Array.hpp:157
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
void merge(const CORE_SharedPointersVMap< K, V > &m)
merge the map
Definition: CORE_SharedPointersVMap.hpp:169
const Value * get(const Key &k) const
get the value at key k
Definition: CORE_SharedPointersVMap.hpp:59
abstract base class for most classes.
Definition: CORE_Object.h:30
tBoolean removeValue(const Value *k)
remove the value
Definition: CORE_SharedPointersVMap.hpp:212
#define tString
Definition: types.h:36
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
CORE_SharedPointersVMap()
Definition: CORE_SharedPointersVMap.hpp:7
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
void clear()
clear the array
Definition: CORE_Vector.h:350
#define tInteger
Definition: types.h:32