1 #ifndef CORE_SharedPointersKVMap_CPP
2 #define CORE_SharedPointersKVMap_CPP
6 template<
class K,
class V>
13 template<
class Key,
class Value>
14 template<
class K,
class V>
19 template<
class Key,
class Value>
25 template<
class Key,
class Value>
26 template<
class K,
class V>
29 vector<boost::shared_ptr<K> > keys;
33 put(boost::dynamic_pointer_cast<Key>(keys[i]),boost::dynamic_pointer_cast<Value> (m[keys[i]]));
38 template<
class K,
class V>
44 for (
int i=0;i<n;i++) {
45 ret+=
"\t"+ks[i]->
toString()+
"-->"+
get(ks[i])->toString()+
"\n";
53 template<
class Key,
class Value>
55 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
56 if (iter==mMap.end())
return false;
60 template<
class Key,
class Value>
62 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.find(k);
63 if (iter==mMap.end())
return null;
64 return iter->second.get();
67 template<
class Key,
class Value>
69 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::iterator iter=mMap.find(k);
70 if (iter==mMap.end())
return null;
71 return iter->second.get();
74 template<
class Key,
class Value>
79 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
80 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
83 vals.
set(i++,iter->second);
87 template<
class Key,
class Value>
92 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
93 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
96 vals[i++]=iter->second.
get();
100 template<
class Key,
class Value>
105 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
106 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
109 vals[i++]=iter->second.get();
116 template<
class Key,
class Value>
118 int nbKeys=mMap.size();
120 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
121 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
130 template<
class Key,
class Value>
132 int nbKeys=mMap.size();
134 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
135 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
144 template<
class Key,
class Value>
147 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator iter=mMap.begin();
148 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator end=mMap.end();
151 keys.
add(iter->first);
156 template<
class Key,
class Value>
157 template<
class K,
class V>
161 int nbKeys=ks.
size();
162 for (
int i=0;i<nbKeys;i++) {
163 put(boost::dynamic_pointer_cast<Key>(ks[i]),boost::dynamic_pointer_cast<Value>(m[ks[i]]));
167 template<
class Key,
class Value>
169 typename map<boost::shared_ptr<Key>,boost::shared_ptr<Value> >::const_iterator exists=mMap.find(k);
170 if (exists!=mMap.end()) {
177 template<
class Key,
class Value>
183 for (
int i=0;i<n;i++) {
184 if ((*
this)[ks[i]]==v) ret=
remove(ks[i]);
189 template<
class Key,
class Value>
195 for (
int i=0;i<n;i++) {
196 if (
get(ks[i])==v) ret=
remove(ks[i]);
200 template<
class Key,
class Value>
206 for (
int i=0;i<n;i++) {
207 if (
get(ks[i])==v) ret=
remove(ks[i]);
tBoolean exists(const boost::shared_ptr< Key > &k) const
exists return true if the key exists in map
Definition: CORE_SharedPointersKVMap.hpp:54
this class describes an array
Definition: CORE_Vector.h:18
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:201
void clear()
clear the array
Definition: CORE_SharedPointersList.h:206
void add(boost::shared_ptr< T > obj)
add an element at the end
Definition: CORE_SharedPointersList.h:141
This class describes a map: shared pointer of Key -> shared pointer of Value.
Definition: CORE_SharedPointersKVMap.h:16
void copy(const CORE_SharedPointersKVMap< K, V > &mapCpy)
copy a map
Definition: CORE_SharedPointersKVMap.hpp:27
#define tBoolean
Definition: types.h:35
void getKeys(CORE_SharedPointersList< Key > &ks) const
return an array of keys
Definition: CORE_SharedPointersKVMap.hpp:145
void setSize(const int &n)
set the size of the shared pointers list
Definition: CORE_SharedPointersList.h:94
void merge(const CORE_SharedPointersKVMap< K, V > &m)
merge the map
Definition: CORE_SharedPointersKVMap.hpp:158
const Value * get(const boost::shared_ptr< Key > &k) const
get the value at key k
Definition: CORE_SharedPointersKVMap.hpp:61
#define null
Definition: types.h:13
void getValues(CORE_Vector< Value * > &vals) const
return an array of values
Definition: CORE_SharedPointersKVMap.hpp:88
int size() const
return the size of the array
Definition: CORE_SharedPointersList.h:247
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:36
tBoolean remove(const boost::shared_ptr< Key > &k)
remove the key
Definition: CORE_SharedPointersKVMap.hpp:168
const T & get(int i) const
get the pointer at index i ASSERT_IN(i>-1); ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_Vector.h:367
void setSize(const int &n)
set the size of the array
Definition: CORE_Vector.h:162
virtual ~CORE_SharedPointersKVMap()
destroy a map
Definition: CORE_SharedPointersKVMap.hpp:20
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.cpp:101
tBoolean set(const int &i, const boost::shared_ptr< T > &obj)
set the pointer at the index i
Definition: CORE_SharedPointersList.hpp:127
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersKVMap.hpp:39
void clear()
clear the array
Definition: CORE_Vector.h:350
#define tInteger
Definition: types.h:32