C++ main module for emicrom Package  1.0
CORE_SharedPointersArray.h
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersArray_H
2 #define CORE_SharedPointersArray_H
3 
4 #include "boost/shared_ptr.hpp"
5 #include "boost/weak_ptr.hpp"
6 
7 #include "CORE_Object.h"
8 
11 template <class T>
13  //ATTRIBUTES
14 
15  //size of the array
17 
18  //capacity of the array
20 
21  //capacity factor for reallocation
23 
24  //array of boost pointer
25  boost::shared_ptr<T> *mValues;
26 
27  //ASSOCIATION
28 
29 public:
30 
31  //CONSTRUCTORS
38  template<class Q>
40  // DESTRUCTORS
41 
42 public:
45  virtual ~CORE_SharedPointersArray();
46  // OPERATORS
47 
51  inline const boost::shared_ptr<T>& operator[](const tUIndex & i) const {
52  ASSERT_IN(i<mSize);
53  return mValues[i];
54  };
58  inline boost::shared_ptr<T>& operator[](const tUIndex & i) {
59  ASSERT_IN(i<mSize);
60  return mValues[i];
61  };
65  inline const T& operator()(const tUIndex & i) const {
66  ASSERT_IN(i<mSize);
67  ASSERT_IN(mValues[i].get()!=null);
68  return *(mValues[i].get());
69  };
73  inline T& operator()(const tUIndex & i) {
74  ASSERT_IN(i<mSize);
75  ASSERT_IN(mValues[i].get()!=null);
76  return *(mValues[i].get());
77  };
78 
79  // New
82  static inline boost::shared_ptr<CORE_SharedPointersArray<T> > New() {
83  boost::shared_ptr<CORE_SharedPointersArray<T> > p(new CORE_SharedPointersArray<T>(),
85  return p;
86  };
87  //COPY
91  template<class Q>
92  void copy(const CORE_SharedPointersArray<Q>& cpy);
93 
94  // SET
95 public:
98  void resize(const tUIndex & cap);
99 
100 public:
103  void fit();
106  inline void clear(){
107  mSize=0;
108  };
111  void setSize(const tUIndex& n) {
112  if (mCapacity>=n) mSize=n;
113  else {
114  resize(n);
115  mSize=n;
116  }
117  };
120  inline void setCapacityFactor(const tFlag& cap) {
121  mCapacityFactor=cap;
122  }
123 
126  void set(const tUIndex& i,boost::shared_ptr<T> obj);
129  inline void set(const tUIndex& i,T& obj) {
130  boost::shared_ptr<T> p;
131  obj.getSharedPointer(p);
132  set(i,p);
133  };
136  inline void set(const tUIndex & i,T* obj) {
137  boost::shared_ptr<T> p;
138  if (obj!=null) obj->getSharedPointer(p);
139  set(i,p);
140  };
141 
145  void insert(const tUIndex& i,boost::shared_ptr<T> obj);
146 
150  inline void insert(const tUIndex & i,T* obj) {
151  boost::shared_ptr<T> p;
152  if (obj!=null) obj->getSharedPointer(p);
153  insert(i,p);
154  };
158  inline void insert(const tUIndex& i,T& obj) {
159  boost::shared_ptr<T> p;
160  obj.getSharedPointer(p);
161  insert(i,p);
162  };
163 
164 
167  void add(boost::shared_ptr<T> obj) {
168  setSize(mSize+1);
169  mValues[mSize-1]=obj;
170  };
173  void add(T& obj) {
174  boost::shared_ptr<T> p;
175  obj.getSharedPointer(p);
176  add(p);
177  };
180  void add(T* obj) {
181  boost::shared_ptr<T> p;
182  if (obj!=null) obj->getSharedPointer(p);
183  add(p);
184  };
185 
186 
192  tBoolean remove(boost::shared_ptr<T> obj) {
193  if (obj.get()==null) return false;
194  return remove(obj.get());
195  };
196 
202  tBoolean remove(const T& obj);
208  tBoolean remove(const T* obj);
209 
212  tBoolean removeAtIndex(const tUIndex& i);
213 
214 
217  inline tBoolean remove() {
218  if (mSize==0) return false;
219  return remove(mSize-1);
220  };
221 
222 
223  // GET
224 
227  inline T* getLastElement() {
228  return (mSize==0)?null:mValues[mSize-1].get();
229  };
232  inline const T* getLastElement() const {
233  return (mSize==0)?null:mValues[mSize-1].get();
234  };
235 
240  inline const T* get(const tUIndex& i) const {
241  return (i>=mSize) ? null:mValues[i].get();
242  };
243 
247  inline T* get(const tUIndex& i) {
248  return (i>=mSize) ? null:mValues[i].get();
249  };
250 
251 
252 
254  inline const tUIndex& getSize() const {
255  return mSize;
256  };
257 
258 
261  tBoolean exists(const T& obj) const;
262 
265  tBoolean exists(const T* obj) const;
266 
267 
268 
269 
270 
271 
272 };
274 #endif
static boost::shared_ptr< CORE_SharedPointersArray< T > > New()
New constructor of a shared pointers list.
Definition: CORE_SharedPointersArray.h:82
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_SharedPointersArray.h:51
void copy(const CORE_SharedPointersArray< Q > &cpy)
New copy constructor of a shared pointers list.
Definition: CORE_SharedPointersArray.hpp:33
void add(T &obj)
add an element at the end
Definition: CORE_SharedPointersArray.h:173
tBoolean removeAtIndex(const tUIndex &i)
remove the pointer at index i
Definition: CORE_SharedPointersArray.hpp:166
const T * getLastElement() const
get last element pointer
Definition: CORE_SharedPointersArray.h:232
tUIndex mSize
Definition: CORE_SharedPointersArray.h:16
void resize(const tUIndex &cap)
resize the array
Definition: CORE_SharedPointersArray.hpp:47
void add(T *obj)
add an element at the end
Definition: CORE_SharedPointersArray.h:180
void 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_SharedPointersArray.hpp:122
T * getLastElement()
get last element pointer
Definition: CORE_SharedPointersArray.h:227
void insert(const tUIndex &i, T *obj)
insert the pointer at index i the old element i become the element i+1
Definition: CORE_SharedPointersArray.h:150
#define tBoolean
Definition: types.h:139
boost::shared_ptr< T > * mValues
Definition: CORE_SharedPointersArray.h:25
tFlag mCapacityFactor
Definition: CORE_SharedPointersArray.h:22
const tUIndex & getSize() const
return the size of the array
Definition: CORE_SharedPointersArray.h:254
#define null
Definition: types.h:144
virtual ~CORE_SharedPointersArray()
destroy an array of T*
Definition: CORE_SharedPointersArray.hpp:23
boost::shared_ptr< T > & operator[](const tUIndex &i)
get the i-th element shared pointer ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_SharedPointersArray.h:58
void insert(const tUIndex &i, T &obj)
insert the pointer at index i the old element i become the element i+1
Definition: CORE_SharedPointersArray.h:158
T & operator()(const tUIndex &i)
get the i-th element ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_SharedPointersArray.h:73
void clear()
clear the array
Definition: CORE_SharedPointersArray.h:106
CORE_SharedPointersArray()
internal constructor of a shared pointers list
Definition: CORE_SharedPointersArray.hpp:8
tUIndex mCapacity
Definition: CORE_SharedPointersArray.h:19
void fit()
fit the capacity to size
Definition: CORE_SharedPointersArray.hpp:81
const T & operator()(const tUIndex &i) const
get the i-th element ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_SharedPointersArray.h:65
#define tUIndex
Definition: types.h:126
abstract base class for most classes.
Definition: CORE_Object.h:53
void setSize(const tUIndex &n)
set the size of the shared pointers list
Definition: CORE_SharedPointersArray.h:111
void add(boost::shared_ptr< T > obj)
add an element at the end
Definition: CORE_SharedPointersArray.h:167
void setCapacityFactor(const tFlag &cap)
set the capcity factor
Definition: CORE_SharedPointersArray.h:120
tBoolean exists(const T &obj) const
exists
Definition: CORE_SharedPointersArray.hpp:192
class CORE_SharedPointersArray is a list of shared pointers
Definition: CORE_SharedPointersArray.h:12
#define ASSERT_IN(a)
Definition: types.h:196
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
#define tFlag
Definition: types.h:74