C++ main module for emicrom 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  tUIndex i,n=keys.size();
33  for (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  tUIndex i,n=ks.size();
43  tString ret=CORE_Object::toString()+"\n";
44  for (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  tUIndex 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  tUIndex i=0;
80  while (iter!=end) {
81  vals.set(i++,iter->second);
82  iter++;
83  }
84 }
85 template<class Key,class Value>
87  tUIndex 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  tUIndex i=0;
93  while (iter!=end) {
94  vals.set(i++,iter->second);
95  iter++;
96  }
97 }
98 
99 template<class Key,class Value>
101  tUIndex 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  typename vector<Value*>::iterator iVals=vals.begin();
107  while (iter!=end) {
108  *iVals=iter->second.get();
109  iter++;
110  iVals++;
111  }
112 }
113 template<class Key,class Value>
114 void CORE_SharedPointersVMap<Key,Value>::getValues(vector<Value*>& vals) const {
115  tUIndex n=mMap.size();
116  vals.clear();
117  vals.resize(n);
118  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
119  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
120  typename vector<Value>::iterator iVals=vals.begin();
121  while (iter!=end) {
122  *iVals=iter->second.get();
123  iter++;
124  iVals++;
125  }
126 }
127 
128 
129 
130 template<class Key,class Value>
131 void CORE_SharedPointersVMap<Key,Value>::getKeys(vector<Key>& keys) const {
132  tUIndex nbKeys=mMap.size();
133  keys.resize(nbKeys);
134  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
135  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
136  typename vector<Key>::iterator iKeys=keys.begin();
137  while (iter!=end) {
138  *iKeys=iter->first;
139  iter++;
140  iKeys++;
141  }
142 }
143 
144 
145 template<class Key,class Value>
147  tUIndex nbKeys=mMap.size();
148  keys.setSize(nbKeys);
149  typename map<Key,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
150  typename map<Key,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
151  typename vector<Key>::iterator iKeys=keys.begin();
152  while (iter!=end) {
153  *iKeys=iter->first;
154  iter++;
155  iKeys++;
156  }
157 }
158 
159 
160 template<class Key,class Value>
161 template<class K,class V>
163  vector<K> ks;
164  m.getKeys(ks);
165  typename vector<K>::iterator iks=ks.begin();
166  while (iks!=ks.end()) {
167  put((Key)*iks,boost::dynamic_pointer_cast<Value>(m[*iks]));
168  iks++;
169  }
170 }
171 
172 template<class Key,class Value>
174  typename map<Key,boost::shared_ptr<Value> >::const_iterator exists=mMap.find(k);
175  if (exists!=mMap.end()) {
176  mMap.erase(k);
177  return true;
178  };
179  return false;
180 };
181 
182 template<class Key,class Value>
184  tBoolean ret=false;
185  vector<Key> ks;
186  getKeys(ks);
187  typename vector<Key>::iterator iks=ks.begin();
188  while (iks!=ks.end()) {
189  if (get(*iks)==v) ret=remove(*iks);
190  iks++;
191  }
192  return ret;
193 };
194 
195 
196 #endif
tBoolean exists(const Key &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersVMap.hpp:52
void getValues(CORE_Vector< Value *> &vals) const
return an array of values
Definition: CORE_SharedPointersVMap.hpp:100
void copy(const CORE_SharedPointersVMap< K, V > &mapCpy)
copy a map
Definition: CORE_SharedPointersVMap.hpp:28
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
void clear()
clear the array
Definition: CORE_SharedPointersList.h:221
tBoolean remove(const Key &k)
remove the key
Definition: CORE_SharedPointersVMap.hpp:173
const Value * get(const Key &k) const
get the value at key k
Definition: CORE_SharedPointersVMap.hpp:59
map< Key, boost::shared_ptr< Value > > mMap
Definition: CORE_SharedPointersVMap.h:17
#define tBoolean
Definition: types.h:139
virtual tString toString() const
return the string associated to the string
Definition: CORE_String.h:223
#define null
Definition: types.h:144
This class describes a map: primitive type of Key -> shared pointer of Value.
Definition: CORE_SharedPointersVMap.h:15
void setSize(const tUIndex &n)
set the size of the vector
Definition: CORE_Vector.h:255
virtual ~CORE_SharedPointersVMap()
destroy a map
Definition: CORE_SharedPointersVMap.hpp:22
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersVMap.hpp:39
void merge(const CORE_SharedPointersVMap< K, V > &m)
merge the map
Definition: CORE_SharedPointersVMap.hpp:162
#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
#define tString
Definition: types.h:135
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.h:326
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
vector< T >::const_iterator begin() const
get iterator
Definition: CORE_Vector.h:331
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