C++ main module for gpm Package  1.0
CORE_SharedPointersMatrix.h
Go to the documentation of this file.
1 #ifndef CORE_SharedPointersMatrix_H
2 #define CORE_SharedPointersMatrix_H
3 
8 template <class T>
10 
11  //ATTRIBUTES
12  vector<CORE_SharedPointersList<T> > mVector;
13 
14 
15  //ASSOCIATION
16 
17  public:
18 
19  //CONSTRUCTORS
26  template<class Q>
28  // DESTRUCTORS
29 
30  public:
33  virtual ~CORE_SharedPointersMatrix();
34 
35  // NEW
38  inline boost::shared_ptr<CORE_SharedPointersMatrix<T> > New() {
39  boost::shared_ptr<CORE_SharedPointersMatrix<T> > p(new CORE_SharedPointersMatrix<T>,
41  p->setThis(p);
42  return p;
43  };
44 
45  // OPERATORS
46 
52  inline const CORE_SharedPointersList<T>& operator[](const int& i) const {
53  ASSERT_IN(i>-1);
54  ASSERT_IN(i<((int)mVector.size()));
55  return mVector[(int)i];
56  };
60  inline CORE_SharedPointersList<T>& operator[](const int& i) {
61  ASSERT_IN(i>-1);
62  ASSERT_IN(i<((int)mVector.size()));
63  return mVector[(int)i];
64  };
65 
66  //COPY
70  template<class Q>
71  void copy(const CORE_SharedPointersMatrix<Q>& cpy);
72 
73  // SET
74 
77  inline void setSize(const int& n) {
78  mVector.resize(n);
79 
80  };
83  inline void setSize(const int& n,const int& p) {
84  mVector.resize(n);
85  for (int i=0;i<n;i++) mVector[i].setSize(p);
86 
87  };
90  inline void setRowSize(const int& i,const int& r) {
91  mVector[i].setSize(r);
92  };
93 
96  tBoolean set(const int& i,const int& j,
97  const boost::shared_ptr<T>& obj) {
98  return mVector[i].set(j,obj);
99  }
100 
104  inline tBoolean insert(const int& i,const int& j,
105  const boost::shared_ptr<T>& obj) {
106  return mVector[i].insert(j,obj);
107  };
108 
109 
112  void add(const int& i,
113  const boost::shared_ptr<T>& obj) {
114  mVector[i].add(obj);
115  };
116 
117 
118 
119 
120 
126  inline tBoolean removeAtIndex(const int& i,
127  const int& j) {
128  int n=mVector.size();
129  if ((j>-1) && (j<n)) return mVector[i].removeAtIndex(j);
130  return false;
131  }
132 
138  inline tBoolean remove(const boost::shared_ptr<T>& obj) {
139  int n=mVector.size();
140  tBoolean ret=false;
141  for (int i=0;i<n;i++) if (mVector[i].remove(obj)) ret=true;
142  return ret;
143  }
144 
150  inline tBoolean remove(const T& obj) {
151  int n=mVector.size();
152  tBoolean ret=false;
153  for (int i=0;i<n;i++) if (mVector[i].remove(obj)) ret=true;
154  return ret;
155  }
156 
162  tBoolean remove(const T* obj) {
163  tBoolean ret=false;
164  int n=mVector.size();
165  for (int i=0;i<n;i++) if (mVector[i].remove(obj)) ret=true;
166  return ret;
167  }
168 
169 
172  inline void removeLine(const int& i) {
173  mVector.erase(i);
174  }
175 
176 
177 
180  inline void clear(){
181  setSize(0,0);
182  mVector.clear();
183  };
184 
185  // GET
186 
187 
188 
193  inline const T* get(const int& i,const int& j) const {
194  ASSERT_IN(i>-1);
195  ASSERT_IN(i<((int)mVector.size()));
196  ASSERT_IN(j>-1);
197  ASSERT_IN(j<((int)mVector[i].size()));
198 
199  return mVector[i][j].get();
200  };
201 
206  inline T* get(const int& i,const int& j) {
207  ASSERT_IN(i>-1);
208  ASSERT_IN(i<((int)mVector.size()));
209  ASSERT_IN(j>-1);
210  ASSERT_IN(j<((int)mVector[i].size()));
211  return mVector[i][j].get();
212  };
213 
215  inline int rows() const {return mVector.size();};
218  inline int getRowSize(const int& i) const {return mVector[i].size();};
219 
221  inline int getSize() const {return mVector.size();};
222 
223 
226  inline tBoolean exists(const boost::shared_ptr<T>& obj) const {
227  int n=mVector.size();
228  for (int i=0;i<n;i++) if (mVector[i].exists(obj)) return true;
229  return false;
230  }
233  tBoolean exists(const T& obj) const {
234  int n=mVector.size();
235  for (int i=0;i<n;i++) if (mVector[i].exists(obj)) return true;
236  return false;
237  }
238 
241  tBoolean exists(const T* obj) const {
242  int n=mVector.size();
243  for (int i=0;i<n;i++) if (mVector[i].exists(obj)) return true;
244  return false;
245  }
246 
247 
248  // OTHERS
249 
250 
251 };
253 
254 
255 
256 #endif
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
tBoolean exists(const T &obj) const
exists
Definition: CORE_SharedPointersMatrix.h:233
int getRowSize(const int &i) const
return the size of row at index i
Definition: CORE_SharedPointersMatrix.h:218
tBoolean exists(const T *obj) const
exists
Definition: CORE_SharedPointersMatrix.h:241
void add(const int &i, const boost::shared_ptr< T > &obj)
add an element at the end
Definition: CORE_SharedPointersMatrix.h:112
tBoolean removeAtIndex(const int &i, const int &j)
remove the element at index i and j
Definition: CORE_SharedPointersMatrix.h:126
boost::shared_ptr< CORE_SharedPointersMatrix< T > > New()
create a shared pointer of CORE_SharedPointersMatrix
Definition: CORE_SharedPointersMatrix.h:38
#define tBoolean
Definition: types.h:35
tBoolean exists(const boost::shared_ptr< T > &obj) const
exists
Definition: CORE_SharedPointersMatrix.h:226
void clear()
clear the array
Definition: CORE_SharedPointersMatrix.h:180
void setSize(const int &n)
set the size of the matrix of shared pointers
Definition: CORE_SharedPointersMatrix.h:77
tBoolean set(const int &i, const int &j, const boost::shared_ptr< T > &obj)
set the pointer at the index i
Definition: CORE_SharedPointersMatrix.h:96
CORE_SharedPointersMatrix()
create the shared pointers matrix
Definition: CORE_SharedPointersMatrix.hpp:7
CORE_SharedPointersList< T > & operator[](const int &i)
get the share pointers list of line i
Definition: CORE_SharedPointersMatrix.h:60
void setSize(const int &n, const int &p)
set the size of an rectangular matrix
Definition: CORE_SharedPointersMatrix.h:83
void setRowSize(const int &i, const int &r)
set size of the row
Definition: CORE_SharedPointersMatrix.h:90
abstract base class for most classes.
Definition: CORE_Object.h:30
tBoolean insert(const int &i, const int &j, const boost::shared_ptr< T > &obj)
insert the pointer at index i the old element i become the element i+1
Definition: CORE_SharedPointersMatrix.h:104
int getSize() const
return the size of the array
Definition: CORE_SharedPointersMatrix.h:221
void removeLine(const int &i)
remove the line at index i
Definition: CORE_SharedPointersMatrix.h:172
class CORE_SharedPointersMatrix is a matrix of shared pointers Matrix is a vector of shared pointer o...
Definition: CORE_SharedPointersMatrix.h:9
const CORE_SharedPointersList< T > & operator[](const int &i) const
get the i-th line
Definition: CORE_SharedPointersMatrix.h:52
virtual ~CORE_SharedPointersMatrix()
destroy an array of T*
Definition: CORE_SharedPointersMatrix.hpp:18
void copy(const CORE_SharedPointersMatrix< Q > &cpy)
copy the shared pointers matrix cpy
Definition: CORE_SharedPointersMatrix.hpp:25
#define ASSERT_IN(a)
Definition: types.h:82
int rows() const
return the number of rows
Definition: CORE_SharedPointersMatrix.h:215
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:106