C++ main module for emicrom 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 
51  inline const CORE_SharedPointersList<T>& operator[](const tUIndex& i) const {
52  ASSERT_IN(i<mVector.size());
53  return mVector[(int)i];
54  };
59  ASSERT_IN(i<mVector.size());
60  return mVector[(int)i];
61  };
62 
63  //COPY
67  template<class Q>
68  void copy(const CORE_SharedPointersMatrix<Q>& cpy);
69 
70  // SET
71 
74  inline void setSize(const tUIndex& n) {
75  mVector.resize(n);
76 
77  };
80  inline void setSize(const tUIndex& n,const tUIndex& p) {
81  mVector.resize(n);
82  for (tUIndex i=0;i<n;i++) mVector[i].setSize(p);
83 
84  };
87  inline void setRowSize(const tUIndex& i,const tUIndex& r) {
88  mVector[i].setSize(r);
89  };
90 
93  tBoolean set(const tUIndex& i,const tUIndex& j,
94  const boost::shared_ptr<T>& obj) {
95  return mVector[i].set(j,obj);
96  }
97 
101  inline tBoolean insert(const tUIndex& i,const tUIndex& j,
102  const boost::shared_ptr<T>& obj) {
103  return mVector[i].insert(j,obj);
104  };
105 
106 
109  void add(const tUIndex& i,
110  const boost::shared_ptr<T>& obj) {
111  mVector[i].add(obj);
112  };
113 
114 
115 
116 
117 
123  inline tBoolean removeAtIndex(const tUIndex& i,
124  const tUIndex& j) {
125  tUIndex n=mVector.size();
126  if (j<n) return mVector[i].removeAtIndex(j);
127  return false;
128  }
129 
135  inline tBoolean remove(const boost::shared_ptr<T>& obj) {
136  tUIndex n=mVector.size();
137  tBoolean ret=false;
138  for (tUIndex i=0;i<n;i++) if (mVector[i].remove(obj)) ret=true;
139  return ret;
140  }
141 
147  inline tBoolean remove(const T& obj) {
148  tUIndex n=mVector.size();
149  tBoolean ret=false;
150  for (tUIndex i=0;i<n;i++) if (mVector[i].remove(obj)) ret=true;
151  return ret;
152  }
153 
159  tBoolean remove(const T* obj) {
160  tBoolean ret=false;
161  tUIndex n=mVector.size();
162  for (tUIndex i=0;i<n;i++) if (mVector[i].remove(obj)) ret=true;
163  return ret;
164  }
165 
166 
169  inline void removeLine(const tUIndex& i) {
170  mVector.erase(i);
171  }
172 
173 
174 
177  inline void clear(){
178  setSize(0,0);
179  mVector.clear();
180  };
181 
182  // GET
183 
184 
185 
189  inline const T* get(const tUIndex& i,const tUIndex& j) const {
190  ASSERT_IN(i<mVector.size());
191  ASSERT_IN(j<mVector[i].size());
192 
193  return mVector[i][j].get();
194  };
195 
199  inline T* get(const tUIndex& i,const tUIndex& j) {
200  ASSERT_IN(i<mVector.size());
201  ASSERT_IN(j<mVector[i].size());
202  return mVector[i][j].get();
203  };
204 
206  inline tUIndex rows() const {return mVector.size();};
209  inline tUIndex getRowSize(const tUIndex& i) const {return mVector[i].size();};
210 
212  inline tUIndex getSize() const {return mVector.size();};
213 
214 
217  inline tBoolean exists(const boost::shared_ptr<T>& obj) const {
218  tUIndex n=mVector.size();
219  for (tUIndex i=0;i<n;i++) if (mVector[i].exists(obj)) return true;
220  return false;
221  }
224  tBoolean exists(const T& obj) const {
225  tUIndex n=mVector.size();
226  for (tUIndex i=0;i<n;i++) if (mVector[i].exists(obj)) return true;
227  return false;
228  }
229 
232  tBoolean exists(const T* obj) const {
233  tUIndex n=mVector.size();
234  for (tUIndex i=0;i<n;i++) if (mVector[i].exists(obj)) return true;
235  return false;
236  }
237 
238 
239  // OTHERS
240 
241 
242 };
244 
245 
246 
247 #endif
CORE_SharedPointersList< T > & operator[](const tUIndex &i)
get the share pointers list of line i
Definition: CORE_SharedPointersMatrix.h:58
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
void add(const tUIndex &i, const boost::shared_ptr< T > &obj)
add an element at the end
Definition: CORE_SharedPointersMatrix.h:109
void setSize(const tUIndex &n, const tUIndex &p)
set the size of an rectangular matrix
Definition: CORE_SharedPointersMatrix.h:80
tBoolean exists(const boost::shared_ptr< T > &obj) const
exists
Definition: CORE_SharedPointersMatrix.h:217
boost::shared_ptr< CORE_SharedPointersMatrix< T > > New()
create a shared pointer of CORE_SharedPointersMatrix
Definition: CORE_SharedPointersMatrix.h:38
tBoolean insert(const tUIndex &i, const tUIndex &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:101
#define tBoolean
Definition: types.h:139
tUIndex getRowSize(const tUIndex &i) const
return the size of row at index i
Definition: CORE_SharedPointersMatrix.h:209
tBoolean exists(const T &obj) const
exists
Definition: CORE_SharedPointersMatrix.h:224
vector< CORE_SharedPointersList< T > > mVector
Definition: CORE_SharedPointersMatrix.h:12
void clear()
clear the array
Definition: CORE_SharedPointersMatrix.h:177
void setSize(const tUIndex &n)
set the size of the matrix of shared pointers
Definition: CORE_SharedPointersMatrix.h:74
tUIndex rows() const
return the number of rows
Definition: CORE_SharedPointersMatrix.h:206
CORE_SharedPointersMatrix()
create the shared pointers matrix
Definition: CORE_SharedPointersMatrix.hpp:7
tBoolean removeAtIndex(const tUIndex &i, const tUIndex &j)
remove the element at index i and j
Definition: CORE_SharedPointersMatrix.h:123
#define tUIndex
Definition: types.h:126
void removeLine(const tUIndex &i)
remove the line at index i
Definition: CORE_SharedPointersMatrix.h:169
abstract base class for most classes.
Definition: CORE_Object.h:53
class CORE_SharedPointersMatrix is a matrix of shared pointers Matrix is a vector of shared pointer o...
Definition: CORE_SharedPointersMatrix.h:9
tUIndex getSize() const
return the size of the array
Definition: CORE_SharedPointersMatrix.h:212
tBoolean exists(const T *obj) const
exists
Definition: CORE_SharedPointersMatrix.h:232
const CORE_SharedPointersList< T > & operator[](const tUIndex &i) const
get the i-th line
Definition: CORE_SharedPointersMatrix.h:51
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:196
void setRowSize(const tUIndex &i, const tUIndex &r)
set size of the row
Definition: CORE_SharedPointersMatrix.h:87
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141