C++ main module for emicrom Package  1.0
CORE_Map.hpp
Go to the documentation of this file.
1 #ifndef CORE_Map_CPP
2 #define CORE_Map_CPP
3 
4 #include "CORE_Map.h"
5 #include "CORE_String.h"
6 
7 
8 
9 template<class Key,class Value>
11 }
12 
13 
14 
15 template<class Key,class Value>
17  this();
18 
19  typename map<Key,Value>::const_iterator iter;
20  typename map<Key,Value>::const_iterator em=m.end();
21  for (iter=m.begin();iter!=em;iter++) {
22  mMap[iter->first]=iter->second;
23  }
24 }
25 
26 
27 
28 template<class Key,class Value>
30  clear();
31 }
32 
33 template<class Key,class Value>
34 template<class K2, class V2>
36  if (this==&copyMap) return;
37  typename map<K2,V2>::const_iterator iter;
38  typename map<K2,V2>::const_iterator em=copyMap.end();
39  for (iter=copyMap.begin();iter!=em;iter++) {
40  mMap[(Key)iter->first]=(Value)iter->second;
41  }
42 }
43 template<class Key,class Value>
45  typename map<Key,Value>::const_iterator iter=mMap.find(k);
46  if (iter==mMap.end()) return false;
47  return true;
48 }
49 
50 template<class Key,class Value>
51 const Value* CORE_Map<Key,Value>::get(const Key& k) const {
52  typename map<Key,Value>::const_iterator iter=mMap.find(k);
53  if (iter==mMap.end()) return null;
54  return &(iter->second);
55 }
56 template<class Key,class Value>
57 Value* CORE_Map<Key,Value>::get(const Key& k) {
58  typename map<Key,Value>::iterator iter=mMap.find(k);
59  if (iter==mMap.end()) return null;
60  return &(iter->second);
61 }
62 
63 template<class Key,class Value>
65  tUIndex i=0,n=mMap.size();
66  vals.clear();
67  vals.setSize(n);
68  typename map<Key,Value>::const_iterator iter=mMap.begin();
69  typename map<Key,Value>::const_iterator end=mMap.end();
70  while (iter!=end) {
71  vals.set(i++,iter->second);
72  iter++;
73  }
74 }
75 template<class Key,class Value>
77  tUIndex i=0,n=mMap.size();
78  vals.clear();
79  vals.setSize(n);
80  typename map<Key,Value>::const_iterator iter=mMap.begin();
81  typename map<Key,Value>::const_iterator end=mMap.end();
82  while (iter!=end) {
83  vals.set(i++,iter->second);
84  iter++;
85  }
86 }
87 template<class Key,class Value>
88 void CORE_Map<Key,Value>::getValues(vector<Value>& vals) const {
89  tUIndex i=0,n=mMap.size();
90  vals.clear();
91  vals.resize(n);
92  typename map<Key,Value>::const_iterator iter=mMap.begin();
93  typename map<Key,Value>::const_iterator end=mMap.end();
94  while (iter!=end) {
95  vals[i++]=iter->second;
96  iter++;
97  }
98 }
99 
100 
101 
102 template<class Key,class Value>
103 void CORE_Map<Key,Value>::getKeys(vector<Key>& keys) const {
104  tUIndex i=0,nbKeys=mMap.size();
105  keys.resize(nbKeys);
106  typename map<Key,Value>::const_iterator iter=mMap.begin();
107  typename map<Key,Value>::const_iterator end=mMap.end();
108  i=0;
109  while (iter!=end) {
110  keys[i]=iter->first;
111  iter++;
112  i++;
113  }
114 }
115 
116 template<class Key,class Value>
118  keys.clear();
119  typename map<Key,Value>::const_iterator iter=mMap.begin();
120  typename map<Key,Value>::const_iterator end=mMap.end();
121  while (iter!=end) {
122  keys.add(iter->first);
123  iter++;
124  }
125 }
126 template<class Key,class Value>
128  keys.clear();
129  typename map<Key,Value>::const_iterator iter=mMap.begin();
130  typename map<Key,Value>::const_iterator end=mMap.end();
131  while (iter!=end) {
132  keys.add(iter->first);
133  iter++;
134  }
135 }
136 template<class Key,class Value>
138  typename map<Key,Value>::const_iterator iter=m.begin();
139  typename map<Key,Value>::const_iterator end=m.end();
140  while (iter!=end) {
141  mMap[iter->first]=iter->second;
142  iter++;
143  }
144 }
145 
146 template<class Key,class Value>
148  typename map<Key,Value>::iterator iter=mMap.find(k);
149  if (iter!=mMap.end()) {
150  mMap.erase(iter);
151  return true;
152  };
153  return false;
154 };
155 
156 template<class Key,class Value>
158  tBoolean succeeds=false;
159  typename map<Key,Value>::iterator iter=mMap.begin();
160  while (iter!=mMap.end()) {
161  if (iter->second==v) {
162  succeeds=true;
163  mMap.erase(iter);
164  iter=mMap.begin();
165  } else {
166  iter++;
167  }
168  }
169  return succeeds;
170 };
171 
172 #endif
173 
virtual void clear()
clear the array : desallocate the array
Definition: CORE_Array.h:300
tBoolean remove(const Key &k)
remove the key
Definition: CORE_Map.hpp:147
void merge(const CORE_Map< Key, Value > &m)
merge the map
Definition: CORE_Map.hpp:137
this class describes an array
Definition: CORE_Vector.h:19
void keys(CORE_Vector< Key > &ks) const
return an array of keys
Definition: CORE_Map.h:164
void set(const tUIndex &i, const T &v)
set value at indx i
Definition: CORE_Vector.h:293
map< Key, Value > mMap
Definition: CORE_Map.h:23
tBoolean removeValue(const Value &k)
remove the value
Definition: CORE_Map.hpp:157
#define tBoolean
Definition: types.h:139
void setSize(const tUIndex &n)
set the size
Definition: CORE_Array.h:292
#define null
Definition: types.h:144
const Value * get(const Key &k) const
get the value at key k
Definition: CORE_Map.hpp:51
void getValues(CORE_Vector< Value > &vals) const
return an array of values
Definition: CORE_Map.hpp:64
map< Key, Value >::iterator begin()
get the begin iterator
Definition: CORE_Map.h:227
void getKeys(vector< Key > &ks) const
return a vector of keys
Definition: CORE_Map.hpp:103
void setSize(const tUIndex &n)
set the size of the vector
Definition: CORE_Vector.h:255
map< Key, Value >::iterator end()
get the end iterator
Definition: CORE_Map.h:239
this class describes a map
Definition: CORE_Map.h:18
this class describes an array
Definition: CORE_Array.h:19
void clear()
clear the map
Definition: CORE_Map.h:218
virtual ~CORE_Map()
destroy a map
Definition: CORE_Map.hpp:29
void add(const CORE_Vector< T > &u, const CORE_Vector< T > &v)
init the value to this=u-v
Definition: CORE_Vector.h:439
void add(const tReal &alpha, const CORE_Array< Q > &Y, const tReal &beta)
This=alpha.Y+beta.This.
Definition: CORE_Array.h:582
#define tUIndex
Definition: types.h:126
abstract base class for most classes.
Definition: CORE_Object.h:53
tBoolean exists(const Key &k) const
exists return true if the key exists in map
Definition: CORE_Map.hpp:44
void set(const tUIndex &i, const T &v)
set the value of the array at index i
Definition: CORE_Array.h:504
void copy(const CORE_Map< K2, V2 > &mapCpy)
copy a map
Definition: CORE_Map.hpp:35
CORE_Map()
build a map
Definition: CORE_Map.hpp:10
void clear()
clear the array
Definition: CORE_Vector.h:248