C++ main module for gpm 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>
112 void CORE_SharedPointersListVMap<Key,Value>::getKeys(vector<Key>& keys) const {
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
virtual void clear()
clear the array
Definition: CORE_Array.h:489
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersListVMap.hpp:44
tString toString() const
return the string associated to the string
Definition: CORE_String.h:150
this class describes an array
Definition: CORE_Vector.h:18
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:79
CORE_SharedPointersListVMap()
Definition: CORE_SharedPointersListVMap.hpp:7
const CORE_SharedPointersList< Value > * get(const Key &k) const
get the value at key k
Definition: CORE_SharedPointersListVMap.hpp:95
tBoolean exists(const Key &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersListVMap.hpp:63
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:35
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
void add(const CORE_Vector< T > &v)
init the value to v
Definition: CORE_Vector.h:206
void clear()
clear the map
Definition: CORE_SharedPointersListVMap.h:233
#define null
Definition: types.h:13
tBoolean put(const Key &k, boost::shared_ptr< CORE_SharedPointersList< Value > > v)
set the value at the index k
Definition: CORE_SharedPointersListVMap.h:129
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 an array
Definition: CORE_Array.h:18
tBoolean removeValue(const Value *k)
remove the value
Definition: CORE_SharedPointersListVMap.hpp:185
int getSize() const
return the size of the array
Definition: CORE_SharedPointersList.h:250
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:142
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:36
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.cpp:101
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:350