C++ main module for mmsd Package  1.0
LAP_ConstVector.h
Go to the documentation of this file.
1 #ifndef LAP_ConstVector_H
2 #define LAP_ConstVector_H
3 
4 #include "LAP_Object.h"
5 #include "LAP_View.h"
6 
13 template<class T>
14 class LAP_ConstVector: public virtual LAP_Object {
15 
16  private:
17 
18  // capacity of the mValues
19  tLVectorIndex mCapacity;
20 
21  // values of vector
22  const T* mValues;
23 
24  //view of the vector
25  LAP_View mView;
26 
27  // booelan than indicates if the mValues & mCvector must be destroyed at reallocation or deleting
28  tBoolean mIsVectorReference;
29 
30 
31  // METHODS
32 
33 
34  protected:
35  // CONSTRUCTORS
36 
40 
41 
42 
43 
44  // DESTRUCTORS
47  virtual ~LAP_ConstVector() {
48  deleteVector();
49  };
50 
51  private:
52  void deleteVector() {
53  if (!mIsVectorReference) {
54  if (mValues!=null) {
55  delete[] mValues;
56  mValues=null;
57  mCapacity=0;
58  mView.reset();
59  }
60  }
61  }
62 
63  // -----------------------
64  // shared pointer operator
65  // ------------------------
66  public:
69  void getSharedPointer(boost::shared_ptr<LAP_ConstVector<T> >& p){
70  SP::CORE_Object r;
72  p=boost::dynamic_pointer_cast<LAP_ConstVector<T> >(r);
73  };
76  void getSharedPointer( boost::shared_ptr<const LAP_ConstVector<T> >& p) const{
77  SPC::CORE_Object r;
79  p=boost::dynamic_pointer_cast<const LAP_ConstVector<T> >(r);
80  };
81  private:
84  inline boost::shared_ptr<LAP_ConstVector<T> > getThis() {
85  boost::shared_ptr<LAP_ConstVector<T> > p;
87  return p;
88  };
91  inline boost::shared_ptr<const LAP_ConstVector<T> > getThis() const {
92  boost::shared_ptr<const LAP_ConstVector<T> > p;
94  return p;
95  };
96 
97  public:
98  //ACCESSOR Operators
99  //==================
100 
101  // operators get the i-th element : the view is not taken into account
104  inline const T& operator[](const tLVectorIndex& i) const {
105  ASSERT_IN(i<mCapacity);
106  return mValues[i];
107  };
108 
109  // operators get the i-th element taking into account the view
112  inline const T& operator()(const tLVectorIndex& i) const {
113  return (*this)[mView.getStart()+mView.getIncrement()*i];
114  };
115 
116 
117  //SET
121  inline tBoolean setView(const tLVectorIndex& start,const tLVectorIndex& end,const tLVectorIncrement& increment) {
122  if (increment==0) return false;
123  if (end<start) return false;
124  if (end>mCapacity) return false;
125  if (end-increment>mCapacity) return false;
126  mView.setView(start,end,increment);
127  return true;
128  }
129 
130  /* \brief set the values to values of size n
131  * if isReferenced is true the vector is not destroyed with the class
132  * otherwise it is destroyed
133  */
134  inline void setValues(const tLVectorIndex& n,
135  const T*& values,
136  const tBoolean& isReferenced) {
137 
138  //delete the old values
139  deleteVector();
140  //make the pointer to the new values
141  mValues=values;
142  //set the capacity of the vector to n
143  mCapacity=n;
144  //set the the values pointer is referenced by another object
145  mIsVectorReference=isReferenced;
146 
147  //update the view
148  mView.setView(0,n,1);
149  };
150 
151 
152  // GET
153 
154 
155 
156  public:
157 
161  virtual const T* getValues() const {
162  return mValues;
163  };
164 
165 
166 
167  public:
170  inline tLVectorIndex getSize() const {
171  return mView.getSize();
172  }
175  inline const tLVectorIncrement& getIncrement() const {
176  return mView.getIncrement();
177  }
180  inline const tLVectorIndex& getStart() const {
181  return mView.getStart();
182  }
185  inline const tLVectorIndex& getEnd() const {
186  return mView.getStart();
187  }
190  virtual const T& get(const tLVectorIndex& i) const {
191  return (*this)(i);
192  };
193 
194 
195 
196 
197 
198 
199 };
200 
201 #include "LAP_ConstVector.hpp"
202 
203 #endif
This class is a view of a pointer.
Definition: LAP_View.h:14
void getSharedPointer(boost::shared_ptr< const LAP_ConstVector< T > > &p) const
return the shared pointer corresponding to the class whith casting
Definition: LAP_ConstVector.h:76
const tLVectorIndex & getStart() const
get the start of the vector
Definition: LAP_ConstVector.h:180
tLVectorIndex getSize() const
get the size of the vector
Definition: LAP_ConstVector.h:170
#define tBoolean
Definition: types.h:48
const tLVectorIndex & getStart() const
get the start index of the first element in [start,end[
Definition: LAP_View.h:130
void setView(const tLVectorIndex &start, const tLVectorIndex &end, const tLVectorIndex &inc)
set the the view the element considered are in [start,end[ with increment inc
Definition: LAP_View.h:88
#define null
Definition: types.h:13
virtual ~LAP_ConstVector()
destroy a vector
Definition: LAP_ConstVector.h:47
const tLVectorIncrement & getIncrement() const
get increment
Definition: LAP_View.h:125
void getSharedPointer(boost::shared_ptr< LAP_ConstVector< T > > &p)
return the shared pointer corresponding to the class with casting
Definition: LAP_ConstVector.h:69
This class is the base class of all lapack objects.
Definition: LAP_Object.h:17
LAP_ConstVector()
build a vector
Definition: LAP_ConstVector.hpp:8
void reset()
reset
Definition: LAP_View.h:114
void setValues(const tLVectorIndex &n, const T *&values, const tBoolean &isReferenced)
Definition: LAP_ConstVector.h:134
void getSharedPointer(SP::CORE_Object &p)
get the shared pointer of this class into p
Definition: CORE_Object.h:65
#define tLVectorIndex
Definition: lapack_types.h:13
const tLVectorIncrement & getIncrement() const
get the increment of the vector
Definition: LAP_ConstVector.h:175
virtual const T * getValues() const
get the values for reading the size of used vector is return by getSize();
Definition: LAP_ConstVector.h:161
const T & operator()(const tLVectorIndex &i) const
get the value for reading only
Definition: LAP_ConstVector.h:112
const T & operator[](const tLVectorIndex &i) const
get the value for reading only
Definition: LAP_ConstVector.h:104
const tLVectorIndex & getEnd() const
get the end of the vector
Definition: LAP_ConstVector.h:185
#define tLVectorIncrement
Definition: lapack_types.h:16
tBoolean setView(const tLVectorIndex &start, const tLVectorIndex &end, const tLVectorIncrement &increment)
set the view of the vector
Definition: LAP_ConstVector.h:121
this class describes a vector of const double
Definition: LAP_ConstVector.h:14
tLVectorIndex getSize() const
Definition: LAP_View.h:141
#define ASSERT_IN(a)
Definition: types.h:96