C++ main module for gpm Package  1.0
CORE_SharedPointersListVMap.h
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersListVMap_H
2 #define CORE_SharedPointersListVMap_H
3 
4 #include "boost/shared_ptr.hpp"
5 #include "boost/weak_ptr.hpp"
6 #include "CORE_Object.h"
8 #include "CORE_Map.h"
9 
16 template <class Key,class Value>
17  class CORE_SharedPointersListVMap : public CORE_Object { // begin class
18 
19  //ATTRIBUTES
20  map<Key,boost::shared_ptr<CORE_SharedPointersList<Value> > > mMap;
21 
22  //ASSOCIATION
23 
24  public:
25 
26  //CONSTRUCTORS
28 
33  template <class K,class Q>
35 
36  // DESTRUCTORS
40 
41  //OPERATORS
44  inline const boost::shared_ptr<CORE_SharedPointersList<Value> > operator[](const Key& k) const {
45  ASSERT_IN(exists(k));
46  return mMap.find(k)->second;
47  };
50  inline boost::shared_ptr<CORE_SharedPointersList<Value> > operator[](const Key& k) {
51  ASSERT_IN(exists(k));
52  return mMap.find(k)->second;
53  };
54 
55 
56 
57  // get METHODS
58 
63  tBoolean exists(const Key& k) const;
64 
68  const CORE_SharedPointersList<Value>* get(const Key& k) const;
69 
73  CORE_SharedPointersList<Value>* get(const Key& k);
74 
78  inline Value* get(const Key& k,const int& index) {
79  CORE_SharedPointersList<Value>* list=get(k);
80  if ((list!=null) && (list->getSize()>index)) return list->get(index);
81  else return null;
82  };
86  inline const Value* get(const Key& k,const int& index) const {
87  CORE_SharedPointersList<Value>* list=get(k);
88  if ((list!=null) && (list->getSize()>index)) return list->get(index);
89  else return null;
90  };
91 
93  inline int size() const{return (int) mMap.size();};
94 
96  inline int getSize() const{return (int) mMap.size();};
97 
98 
99 
102  inline void keys(CORE_Vector<Key>& ks) const {
103  getKeys(ks);
104  };
105 
108  void getKeys(vector<Key>& ks) const;
109 
112  void getKeys(CORE_Vector<Key>& ks) const;
113 
116  void getKeys(CORE_Array<Key>& ks) const;
117 
118  // set METHODS
119 
122  template<class K,class V>
123  void copy(const CORE_SharedPointersListVMap<K,V>& mapCpy);
124 
125 
129  inline tBoolean put(const Key& k,
130  boost::shared_ptr<CORE_SharedPointersList<Value> > v) {
131  mMap[k]=v;
132  return true;
133  };
134 
139  inline tBoolean put(const Key& k) {
140  boost::shared_ptr<CORE_SharedPointersList<Value> > v=CORE_SharedPointersList<Value>::New();
141  mMap[k]=v;
142  return true;
143  };
144 
151  tBoolean put(const Key& k,boost::shared_ptr<Value> v,const tBoolean& ifNotExists);
152 
159  inline tBoolean put(const Key& k,Value& v,const tBoolean& ifNotExists) {
160  boost::shared_ptr<Value> p_v;
161  v.getSharedPointer(p_v);
162  return put(k,p_v,ifNotExists);
163  };
164 
171  inline tBoolean put(const Key& k,Value* v,const tBoolean& ifNotExists) {
172  if (v!=null) return put(k,*v,ifNotExists);
173  return false;
174  };
175 
180  inline tBoolean put(const Key& k,Value* v) {return put(k,v,true);};
185  inline tBoolean put(const Key& k,Value& v) {return put(k,v,true);};
190  inline tBoolean put(const Key& k,boost::shared_ptr<Value>& v) {
191  return put(k,v,true);
192  };
193 
194 
195 
196 
197 
203  tBoolean remove(const Key& k);
204 
210  tBoolean removeValue(const Value* k);
211 
217  tBoolean removeValue(const Value& k);
218 
224  tBoolean removeValue(boost::shared_ptr<Value>& k);
225 
228  void clear(const Key& k);
229 
230 
233  inline void clear() {mMap.clear();};
234 
235  public:
236  virtual tString toString() const;
237 
238 
239  }; // end class
240 
242 #endif
tBoolean put(const Key &k, boost::shared_ptr< Value > &v)
add the value at the index k add only if the value v does not already exist at index k ...
Definition: CORE_SharedPointersListVMap.h:190
virtual tString toString() const
return the string representation of the object node
Definition: CORE_SharedPointersListVMap.hpp:44
boost::shared_ptr< CORE_SharedPointersList< Value > > operator[](const Key &k)
get object corresponding to key
Definition: CORE_SharedPointersListVMap.h:50
int getSize() const
return the size of the array
Definition: CORE_SharedPointersListVMap.h:96
this class describes an array
Definition: CORE_Vector.h:18
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
tBoolean put(const Key &k, Value *v)
add the value at the index k add only if the value v does not already exist at index k ...
Definition: CORE_SharedPointersListVMap.h:180
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
tBoolean put(const Key &k, Value &v, const tBoolean &ifNotExists)
add the value at the index k.
Definition: CORE_SharedPointersListVMap.h:159
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
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
this class describes an array
Definition: CORE_Array.h:18
tBoolean put(const Key &k)
put only the key k with no values
Definition: CORE_SharedPointersListVMap.h:139
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
void keys(CORE_Vector< Key > &ks) const
return an array of keys
Definition: CORE_SharedPointersListVMap.h:102
const T * get(const int &i) const
get the pointer at index i ASSERT_IN(i>-1); ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_SharedPointersList.h:230
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:36
int size() const
return the size of the array
Definition: CORE_SharedPointersListVMap.h:93
tBoolean put(const Key &k, Value &v)
add the value at the index k add only if the value v does not already exist at index k ...
Definition: CORE_SharedPointersListVMap.h:185
tBoolean put(const Key &k, Value *v, const tBoolean &ifNotExists)
add the value at the index k
Definition: CORE_SharedPointersListVMap.h:171
void getKeys(vector< Key > &ks) const
return a vector of keys
Definition: CORE_SharedPointersListVMap.hpp:112
const boost::shared_ptr< CORE_SharedPointersList< Value > > operator[](const Key &k) const
get object corresponding to key
Definition: CORE_SharedPointersListVMap.h:44
#define ASSERT_IN(a)
Definition: types.h:82