C++ main module for emicrom 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  typename vector<boost::shared_ptr<K> >::iterator iKeys=keys.begin();
32  while (iKeys!=keys.end()) {
33  put(boost::dynamic_pointer_cast<Key>(*iKeys),boost::dynamic_pointer_cast<Value> (m[*iKeys]));
34  iKeys++;
35  }
36 }
37 
38 
39 
40 template<class K,class V>
43  getKeys(ks);
44  tUIndex n=ks.size();
45  tString ret=CORE_Object::toString()+"\n";
46  for (tUIndex i=0;i<n;i++) {
47  ret+="\t"+ks[i]->toString()+"-->"+get(ks[i])->toString()+"\n";
48  }
49  return ret;
50 }
51 
52 
53 
54 
55 template<class Key,class Value>
56 tBoolean CORE_SharedPointersKVMap<Key,Value>::exists(const boost::shared_ptr<Key>& k) const {
57  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
58  if (iter==mMap.end()) return false;
59  return true;
60 }
61 
62 template<class Key,class Value>
63 const Value* CORE_SharedPointersKVMap<Key,Value>::get(const boost::shared_ptr<Key>& k) const {
64  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
65  if (iter==mMap.end()) return null;
66  return iter->second.get();
67 }
68 
69 template<class Key,class Value>
70 Value* CORE_SharedPointersKVMap<Key,Value>::get(const boost::shared_ptr<Key>& k) {
71  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::iterator iter=mMap.find(k);
72  if (iter==mMap.end()) return null;
73  return iter->second.get();
74 }
75 
76 template<class Key,class Value>
78  tUIndex n=mMap.size();
79  vals.clear();
80  vals.setSize(n);
81  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
82  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
83  tUIndex i=0;
84  while (iter!=end) {
85  vals.set(i++,iter->second);
86  iter++;
87  }
88 }
89 template<class Key,class Value>
91  tUIndex n=mMap.size();
92  vals.clear();
93  vals.setSize(n);
94  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
95  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
96  tUIndex i=0;
97  while (iter!=end) {
98  vals[i++]=iter->second.get();
99  iter++;
100  }
101 }
102 template<class Key,class Value>
103 void CORE_SharedPointersKVMap<Key,Value>::getValues(vector<Value*>& vals) const {
104  tUIndex n=mMap.size();
105  vals.clear();
106  vals.resize(n);
107  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
108  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
109  tUIndex i=0;
110  while (iter!=end) {
111  vals[i++]=iter->second.get();
112  iter++;
113  }
114 }
115 
116 
117 
118 template<class Key,class Value>
120  keys.resize(mMap.size());
121  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
122  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
123  typename vector<Key*>::iterator iKeys=keys.begin();
124  while (iter!=end) {
125  *iKeys=iter->first;
126  iter++;
127  i++;
128  iKeys++;
129  }
130 }
131 
132 template<class Key,class Value>
134  tUIndex i,nbKeys=mMap.size();
135  keys.setSize(nbKeys);
136  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
137  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
138  i=0;
139  while (iter!=end) {
140  keys[i]=iter->first;
141  iter++;
142  i++;
143  }
144 }
145 
146 
147 template<class Key,class Value>
149  keys.clear();
150  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
151  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
152  tUIndex i=0;
153  while (iter!=end) {
154  keys.add(iter->first);
155  iter++;
156  i++;
157  }
158 }
159 
160 template<class Key,class Value>
161 template<class K,class V>
164  m.getKeys(ks);
165  tUIndex i,nbKeys=ks.size();
166  for (i=0;i<nbKeys;i++) {
167  put(boost::dynamic_pointer_cast<Key>(ks[i]),boost::dynamic_pointer_cast<Value>(m[ks[i]]));
168  }
169 }
170 
171 template<class Key,class Value>
172 tBoolean CORE_SharedPointersKVMap<Key,Value>::remove(const boost::shared_ptr<Key>& k) {
173  typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator exists=mMap.find(k);
174  if (exists!=mMap.end()) {
175  mMap.erase(k);
176  return true;
177  };
178  return false;
179 };
180 
181 template<class Key,class Value>
183  tBoolean ret=false;
185  getKeys(ks);
186  tUIndex n=ks.size();
187  for (tUIndex i=0;i<n;i++) {
188  if ((*this)[ks[i]]==v) ret=remove(ks[i]);
189  }
190  return ret;
191 };
192 
193 template<class Key,class Value>
195  tBoolean ret=false;
197  getKeys(ks);
198  tUIndex n=ks.size();
199  for (tUIndex i=0;i<n;i++) {
200  if (get(ks[i])==v) ret=remove(ks[i]);
201  }
202  return ret;
203 };
204 template<class Key,class Value>
206  tBoolean ret=false;
208  getKeys(ks);
209  tUIndex i,n=ks.size();
210  for (i=0;i<n;i++) {
211  if (get(ks[i])==v) ret=remove(ks[i]);
212  }
213  return ret;
214 };
215 
216 #endif
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersKVMap.hpp:41
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 set(const tUIndex &i, boost::shared_ptr< T > obj)
set the pointer at the index i
Definition: CORE_SharedPointersList.hpp:95
this class describes an array
Definition: CORE_Vector.h:19
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:205
void clear()
clear the array
Definition: CORE_SharedPointersList.h:221
void keys(CORE_SharedPointersList< Key > &ks) const
return an array of keys
Definition: CORE_SharedPointersKVMap.h:106
void getKeys(CORE_SharedPointersList< Key > &ks) const
return an array of keys
Definition: CORE_SharedPointersKVMap.hpp:148
void clear()
clear the map
Definition: CORE_SharedPointersKVMap.h:197
void add(boost::shared_ptr< T > obj)
add an element at the end
Definition: CORE_SharedPointersList.h:134
This class describes a map: shared pointer of Key -> shared pointer of Value.
Definition: CORE_SharedPointersKVMap.h:16
map< boost::shared_ptr< Key >, boost::shared_ptr< Value > > mMap
Definition: CORE_SharedPointersKVMap.h:18
void copy(const CORE_SharedPointersKVMap< K, V > &mapCpy)
copy a map
Definition: CORE_SharedPointersKVMap.hpp:27
#define tBoolean
Definition: types.h:139
void merge(const CORE_SharedPointersKVMap< K, V > &m)
merge the map
Definition: CORE_SharedPointersKVMap.hpp:162
#define null
Definition: types.h:144
void setSize(const tUIndex &n)
set the size of the vector
Definition: CORE_Vector.h:255
const Value * get(const boost::shared_ptr< Key > &k) const
get the value at key k
Definition: CORE_SharedPointersKVMap.hpp:63
void getValues(CORE_Vector< Value *> &vals) const
return an array of values
Definition: CORE_SharedPointersKVMap.hpp:90
#define tUIndex
Definition: types.h:126
abstract base class for most classes.
Definition: CORE_Object.h:53
#define tString
Definition: types.h:135
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.h:326
tBoolean remove(const boost::shared_ptr< Key > &k)
remove the key
Definition: CORE_SharedPointersKVMap.hpp:172
tUIndex size() const
return the size of the array
Definition: CORE_SharedPointersList.h:255
virtual ~CORE_SharedPointersKVMap()
destroy a map
Definition: CORE_SharedPointersKVMap.hpp:20
const T & get(const tUIndex &i) const
get the value at index i
Definition: CORE_Vector.h:376
void setSize(const tUIndex &n)
set the size of the shared pointers list
Definition: CORE_SharedPointersList.h:87
void clear()
clear the array
Definition: CORE_Vector.h:248
tBoolean exists(const boost::shared_ptr< Key > &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersKVMap.hpp:56