C++ main module for emicrom Package  1.0
CORE_SharedPointersList.h
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersList_H
2 #define CORE_SharedPointersList_H
3 
4 #include "boost/shared_ptr.hpp"
5 #include "boost/weak_ptr.hpp"
6 #include "CORE_Object.h"
7 
10 template <class T>
12  //ATTRIBUTES
13  vector<boost::shared_ptr<T> > mVector;
14 
15  //ASSOCIATION
16 
17 public:
18 
19  //CONSTRUCTORS
26  template<class Q>
28  // DESTRUCTORS
29 
30 public:
33  virtual ~CORE_SharedPointersList();
34  // OPERATORS
35 
39  inline const boost::shared_ptr<T>& operator[](const tUIndex & i) const {
40 
41  ASSERT_IN(i<(mVector.size()));
42  return mVector[i];
43  };
47  inline boost::shared_ptr<T>& operator[](const tUIndex & i) {
48 
49  ASSERT_IN(i<mVector.size());
50  return mVector[i];
51  };
55  inline const T& operator()(const tUIndex & i) const {
56 
57  ASSERT_IN(i<mVector.size());
58  ASSERT_IN(mVector[i].get()!=null);
59  return *mVector[i].get();
60  };
63  inline T& operator()(const tUIndex & i) {
64  ASSERT_IN(i<mVector.size());
65  ASSERT_IN(mVector[i].get()!=null);
66  return *mVector[i].get();
67  };
68 
69  // New
72  static inline boost::shared_ptr<CORE_SharedPointersList<T> > New() {
73  boost::shared_ptr<CORE_SharedPointersList<T> > p(new CORE_SharedPointersList<T>(),
75  return p;
76  };
77  //COPY
81  template<class Q>
82  void copy(const CORE_SharedPointersList<Q>& cpy);
83 
84  // SET
87  inline void setSize(const tUIndex& n) {
88  mVector.resize(n);
89  };
90 
93  tBoolean set(const tUIndex& i,boost::shared_ptr<T> obj);
96  inline tBoolean set(const tUIndex& i,T& obj) {
97  boost::shared_ptr<T> p;
98  obj.getSharedPointer(p);
99  return set(i,p);
100  };
103  inline tBoolean set(const tUIndex & i,T* obj) {
104  boost::shared_ptr<T> p;
105  if (obj!=null) obj->getSharedPointer(p);
106  return set(i,p);
107  };
108 
112  tBoolean insert(const tUIndex& i,boost::shared_ptr<T> obj);
113 
117  inline tBoolean insert(const tUIndex& i,T* obj) {
118  boost::shared_ptr<T> p;
119  if (obj!=null) obj->getSharedPointer(p);
120  return insert(i,p);
121  };
125  inline tBoolean insert(const tUIndex& i,T& obj) {
126  boost::shared_ptr<T> p;
127  obj.getSharedPointer(p);
128  return insert(i,p);
129  };
130 
131 
134  void add(boost::shared_ptr<T> obj) {
135  mVector.push_back(obj);
136  };
139  void add(T& obj) {
140  boost::shared_ptr<T> p;
141  obj.getSharedPointer(p);
142  mVector.push_back(p);
143  };
146  void add(T* obj) {
147  boost::shared_ptr<T> p;
148  if (obj!=null) obj->getSharedPointer(p);
149  mVector.push_back(p);
150  };
151 
152 
153 
154 
157  virtual void addInList(const boost::shared_ptr<T>& obj) {
158  add(obj);
159  };
160 
163  template<class Q>
164  void merge(const CORE_SharedPointersList<Q>& array);
165 
166 
172  inline tBoolean remove(boost::shared_ptr<T> obj) {
173  return remove(obj.get());
174  }
175 
181  tBoolean remove(const T& obj);
187  inline tBoolean remove(const T* obj) {
188  if (obj==null) return false;
189  return remove(*obj);
190  }
191 
194  tBoolean removeAtIndex(const tUIndex& i);
195 
196 
199  inline tBoolean remove() {
200  tUIndex n=size();
201  if (n==0) return false;
202  return remove(n-1);
203  };
207  if (mVector.size()==0) return false;
208  mVector.erase(mVector.begin());
209  return true;
210  };
213  inline tBoolean removeLast() {
214  if (mVector.size()==0) return false;
215  mVector.erase(mVector.begin()+size()-1);
216  return true;
217  };
218 
221  inline void clear(){
222  mVector.clear();
223  };
224 
225  // GET
226 
229  inline T* getLastElement() {
230  if (mVector.size()==0) return null;
231  return mVector[mVector.size()-1].get();
232  };
235  inline const T* getLastElement() const {
236  if (mVector.size()==0) return null;
237  return mVector[mVector.size()-1].get();
238  };
239 
242  inline const T* get(const tUIndex& i) const {
243  if (i>=mVector.size()) return null;
244  return mVector[i].get();
245  };
246 
249  inline T* get(const tUIndex& i) {
250  if (i>=mVector.size()) return null;
251  return mVector[i].get();
252  };
253 
255  inline tUIndex size() const {return mVector.size();};
256 
258  inline tUIndex getSize() const {return mVector.size();};
259 
260 
263  inline tBoolean exists(boost::shared_ptr<T> obj) const {
264  return exists(obj.get());
265  }
268  tBoolean exists(const T& obj) const;
269 
272  tBoolean exists(const T* obj) const {
273  if (obj==null) return false;
274  return exists(*obj);
275  }
276 
277 
278 
281  void getValues(vector<T*>& vs);
284  void getValues(vector<const T*>& vs) const;
285 
286 
287  // OTHERS
288 
289 
292  void permute(const tUIndex& i,const tUIndex& j);
293 
296  void reverse();
297 
300  inline typename vector<boost::shared_ptr<T> >::const_iterator begin() const {
301  return mVector.begin();
302  };
305  inline typename vector<boost::shared_ptr<T> >::iterator begin() {
306  return mVector.begin();
307  };
308 
311  inline typename vector<boost::shared_ptr<T> >::const_iterator end() const {
312  return mVector.end();
313  };
316  inline typename vector<boost::shared_ptr<T> >::iterator end() {
317  return mVector.end();
318  };
319 
320 
321 
322 };
324 #endif
void copy(const CORE_SharedPointersList< Q > &cpy)
New copy constructor of a shared pointers list.
Definition: CORE_SharedPointersList.hpp:26
tUIndex getSize() const
return the size of the array
Definition: CORE_SharedPointersList.h:258
vector< boost::shared_ptr< T > > mVector
Definition: CORE_SharedPointersList.h:13
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
tBoolean insert(const tUIndex &i, T &obj)
insert the pointer at index i the old element i become the element i+1
Definition: CORE_SharedPointersList.h:125
void clear()
clear the array
Definition: CORE_SharedPointersList.h:221
const T * getLastElement() const
get last element pointer
Definition: CORE_SharedPointersList.h:235
static boost::shared_ptr< CORE_SharedPointersList< T > > New()
New constructor of a shared pointers list.
Definition: CORE_SharedPointersList.h:72
void add(T &obj)
add an element at the end
Definition: CORE_SharedPointersList.h:139
tBoolean removeAtIndex(const tUIndex &i)
remove the pointer at index i
Definition: CORE_SharedPointersList.hpp:66
vector< boost::shared_ptr< T > >::const_iterator end() const
get iterator
Definition: CORE_SharedPointersList.h:311
void add(boost::shared_ptr< T > obj)
add an element at the end
Definition: CORE_SharedPointersList.h:134
tBoolean insert(const tUIndex &i, boost::shared_ptr< T > obj)
insert the pointer at index i the old element i become the element i+1
Definition: CORE_SharedPointersList.hpp:84
vector< boost::shared_ptr< T > >::iterator end()
get iterator
Definition: CORE_SharedPointersList.h:316
tBoolean exists(const T *obj) const
exists
Definition: CORE_SharedPointersList.h:272
#define tBoolean
Definition: types.h:139
void add(T *obj)
add an element at the end
Definition: CORE_SharedPointersList.h:146
tBoolean removeLast()
remove the first pointer
Definition: CORE_SharedPointersList.h:213
void merge(const CORE_SharedPointersList< Q > &array)
merge the array in this
Definition: CORE_SharedPointersList.hpp:118
virtual ~CORE_SharedPointersList()
destroy an array of T*
Definition: CORE_SharedPointersList.hpp:19
vector< boost::shared_ptr< T > >::const_iterator begin() const
get iterator
Definition: CORE_SharedPointersList.h:300
void reverse()
reverse the vector
Definition: CORE_SharedPointersList.hpp:105
#define null
Definition: types.h:144
void permute(const tUIndex &i, const tUIndex &j)
permute
Definition: CORE_SharedPointersList.hpp:76
const boost::shared_ptr< T > & operator[](const tUIndex &i) const
get the i-th element shared pointer ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_SharedPointersList.h:39
T & operator()(const tUIndex &i)
get the i-th element
Definition: CORE_SharedPointersList.h:63
CORE_SharedPointersList()
internal constructor of a shared pointers list
Definition: CORE_SharedPointersList.hpp:7
virtual void addInList(const boost::shared_ptr< T > &obj)
add a core object
Definition: CORE_SharedPointersList.h:157
void getValues(vector< T *> &vs)
get values
Definition: CORE_SharedPointersList.hpp:133
tBoolean insert(const tUIndex &i, T *obj)
insert the pointer at index i the old element i become the element i+1
Definition: CORE_SharedPointersList.h:117
#define tUIndex
Definition: types.h:126
tBoolean exists(boost::shared_ptr< T > obj) const
exists
Definition: CORE_SharedPointersList.h:263
boost::shared_ptr< T > & operator[](const tUIndex &i)
get the i-th element shared pointer ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_SharedPointersList.h:47
abstract base class for most classes.
Definition: CORE_Object.h:53
T * getLastElement()
get last element pointer
Definition: CORE_SharedPointersList.h:229
tUIndex size() const
return the size of the array
Definition: CORE_SharedPointersList.h:255
const T & operator()(const tUIndex &i) const
get the i-th element ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_SharedPointersList.h:55
void setSize(const tUIndex &n)
set the size of the shared pointers list
Definition: CORE_SharedPointersList.h:87
#define ASSERT_IN(a)
Definition: types.h:196
vector< boost::shared_ptr< T > >::iterator begin()
get iterator
Definition: CORE_SharedPointersList.h:305
tBoolean removeFirst()
remove the first pointer
Definition: CORE_SharedPointersList.h:206
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141