C++ main module for emicrom Package  1.0
CORE_SharedPointersListVMap.hpp
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersListVMap_CPP
2 #define CORE_SharedPointersListVMap_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  this();
18  copy(m);
19 }
20 
21 
22 template<class Key,class Value>
24  clear();
25 }
26 
27 template<class Key,class Value>
28 template<class K,class V>
30  clear();
31  vector<K> keys;
32  m.getKeys(keys);
33  int n=keys.size();
34  for (int i=0;i<n;i++) {
35  boost::shared_ptr<CORE_SharedPointersList<Value> > &listAtK=m[keys[i]];
36  boost::shared_ptr<CORE_SharedPointersList<Value> > copyList=CORE_SharedPointersList<Value>::New();
37  copyList.copy(listAtK);
38  put((Key)keys[i],copyList);
39  }
40 }
41 
42 
43 template<class Key,class Value>
45  vector<Key> ks;
46  getKeys(ks);
47  int n=ks.size();
48  tString ret=CORE_Object::toString()+"\n";
49  tString strK;
50  for (int i=0;i<n;i++) {
51  const CORE_SharedPointersList<Value>& listAtK=*get(ks[i]);
52  int p=listAtK.getSize();
53  strK=CORE_String::toString(ks[i]);
54  for (int j=0;j<p;j++) {
55  ret+="\t"+strK+"["+CORE_Integer::toString(j)+"]="+listAtK[j]->toString()+"\n";
56  }
57  }
58  return ret;
59 }
60 
61 
62 template<class Key,class Value>
64  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator iter=mMap.find(k);
65  if (iter==mMap.end()) return false;
66  return true;
67 }
68 
69 template<class Key,class Value>
71 
72  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::iterator iter=mMap.find(k);
73  if (iter!=mMap.end()) {
74  boost::shared_ptr<CORE_SharedPointersList<Value> > &listAtK=iter->second;
75  listAtK->clear();
76  }
77 };
78 template<class Key,class Value>
79 tBoolean CORE_SharedPointersListVMap<Key,Value>::put(const Key& k,boost::shared_ptr<Value> v,const tBoolean& ifNotExists) {
80  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::iterator iter=mMap.find(k);
81  if (iter==mMap.end()) {
82  boost::shared_ptr<CORE_SharedPointersList<Value> > listAtK=CORE_SharedPointersList<Value>::New();
83  mMap[k]=listAtK;
84  listAtK->add(v);
85  } else {
86  boost::shared_ptr<CORE_SharedPointersList<Value> > &listAtK=iter->second;
87  if (ifNotExists) {
88  if (!listAtK->exists(v)) listAtK->add(v);
89  } else listAtK->add(v);
90  }
91  return true;
92 };
93 
94 template<class Key,class Value>
96  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator iter=mMap.find(k);
97  if (iter==mMap.end()) return null;
98  return iter->second.get();
99 }
100 
101 template<class Key,class Value>
103  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::iterator iter=mMap.find(k);
104  if (iter==mMap.end()) return null;
105  return iter->second.get();
106 }
107 
108 
109 
110 
111 template<class Key,class Value>
113  int nbKeys=mMap.size();
114  keys.resize(nbKeys);
115  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator iter=mMap.begin();
116  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator end=mMap.end();
117  int i=0;
118  while (iter!=end) {
119  keys[i]=iter->first;
120  iter++;
121  i++;
122  }
123 }
124 
125 template<class Key,class Value>
127  keys.clear();
128  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator iter=mMap.begin();
129  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator end=mMap.end();
130  int i=0;
131  while (iter!=end) {
132  keys.add(iter->first);
133  iter++;
134  i++;
135  }
136 }
137 template<class Key,class Value>
139  keys.clear();
140  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator iter=mMap.begin();
141  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator end=mMap.end();
142  int i=0;
143  while (iter!=end) {
144  keys.add(iter->first);
145  iter++;
146  i++;
147  }
148 }
149 
150 template<class Key,class Value>
152  typename map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > >::const_iterator exists=mMap.find(k);
153  if (exists!=mMap.end()) {
154  mMap.erase(k);
155  return true;
156  };
157  return false;
158 };
159 
160 template<class Key,class Value>
162  tBoolean ret=false;
163  vector<Key> ks;
164  getKeys(ks);
165  int n=ks.size();
166  for (int i=0;i<n;i++) {
167  if ((*this)[ks[i]]->exists(v)) ret=remove(ks[i]);
168  }
169  return ret;
170 };
171 
172 template<class Key,class Value>
174  tBoolean ret=false;
175  vector<Key> ks;
176  getKeys(ks);
177  int n=ks.size();
178  for (int i=0;i<n;i++) {
179  if ((*this)[ks[i]]->exists(v)) ret=remove(ks[i]);
180  }
181  return ret;
182 };
183 
184 template<class Key,class Value>
186  tBoolean ret=false;
187  vector<Key> ks;
188  getKeys(ks);
189  int n=ks.size();
190  for (int i=0;i<n;i++) {
191  if ((*this)[ks[i]]->exists(v)) ret=remove(ks[i]);
192  }
193  return ret;
194 };
195 
196 
197 #endif
tUIndex getSize() const
return the size of the array
Definition: CORE_SharedPointersList.h:258
tBoolean exists(const Key &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersListVMap.hpp:63
virtual void clear()
clear the array : desallocate the array
Definition: CORE_Array.h:300
map< Key, boost::shared_ptr< CORE_SharedPointersList< Value > > > mMap
Definition: CORE_SharedPointersListVMap.h:20
this class describes an array
Definition: CORE_Vector.h:19
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
static boost::shared_ptr< CORE_SharedPointersList< T > > New()
New constructor of a shared pointers list.
Definition: CORE_SharedPointersList.h:72
CORE_SharedPointersListVMap()
Definition: CORE_SharedPointersListVMap.hpp:7
void copy(const CORE_SharedPointersListVMap< K, V > &mapCpy)
copy a map
Definition: CORE_SharedPointersListVMap.hpp:29
virtual ~CORE_SharedPointersListVMap()
destroy a map
Definition: CORE_SharedPointersListVMap.hpp:23
#define tBoolean
Definition: types.h:139
This class describes a map: primitive type of Key -> shared pointer of list of Value.
Definition: CORE_SharedPointersListVMap.h:17
tBoolean remove(const Key &k)
remove the key
Definition: CORE_SharedPointersListVMap.hpp:151
virtual tString toString() const
return the string associated to the string
Definition: CORE_String.h:223
void clear()
clear the map
Definition: CORE_SharedPointersListVMap.h:233
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:106
#define null
Definition: types.h:144
tBoolean put(const Key &k, boost::shared_ptr< CORE_SharedPointersList< Value > > v)
set the value at the index k
Definition: CORE_SharedPointersListVMap.h:129
this class describes an array
Definition: CORE_Array.h:19
void add(const CORE_Vector< T > &u, const CORE_Vector< T > &v)
init the value to this=u-v
Definition: CORE_Vector.h:439
tBoolean removeValue(const Value *k)
remove the value
Definition: CORE_SharedPointersListVMap.hpp:185
void add(const tReal &alpha, const CORE_Array< Q > &Y, const tReal &beta)
This=alpha.Y+beta.This.
Definition: CORE_Array.h:582
void keys(CORE_Vector< Key > &ks) const
return an array of keys
Definition: CORE_SharedPointersListVMap.h:102
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
const CORE_SharedPointersList< Value > * get(const Key &k) const
get the value at key k
Definition: CORE_SharedPointersListVMap.hpp:95
void getKeys(vector< Key > &ks) const
return a vector of keys
Definition: CORE_SharedPointersListVMap.hpp:112
void clear()
clear the array
Definition: CORE_Vector.h:248
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersListVMap.hpp:44