C++ main module for emicrom Package  1.0
CORE_ArrayList.h
Go to the documentation of this file.
1 #ifndef CORE_ArrayList_H
2 #define CORE_ArrayList_H
3 
4 
5 #include "CORE_Array.h"
6 
11 template <class T>
12 class CORE_ArrayList : public CORE_Array<T> , public CORE_List {
13 
14 
15 private:
16 
17 
18  // capacity factor: the multiplicator factor for reallocation for list operator
19  // if 1 : no multiplication
22 
23  // CONSTRUCTORS
24 public:
28  mCapacityFactor=2;
29  mOrder=CORE_List::NO_ORDER;
30  }
35  mCapacityFactor=c.getCapacityfactor();
36  mOrder=CORE_List::NO_ORDER;
37  }
41  CORE_ArrayList(const tUIndex& n):CORE_Array<T>(n) {
42  mCapacityFactor=2;
43  mOrder=CORE_List::NO_ORDER;
44  }
45 
46 
47 
48 
49  // DESTRUCTORS
52  virtual ~CORE_ArrayList() {
53  }
54 
55 
56 
57  // -----------------------
58  // shared pointer operator
59  // ------------------------
60 public:
65  void getSharedPointer(boost::shared_ptr<CORE_ArrayList<T> >& p){
66  SP::CORE_Object r;
68  p=boost::dynamic_pointer_cast<CORE_ArrayList<T> >(r);
69  };
73  void getSharedPointer( boost::shared_ptr<const CORE_ArrayList<T> >& p) const{
74  SPC::CORE_Object r;
76  p=boost::dynamic_pointer_cast<const CORE_ArrayList<T> >(r);
77  };
78 private:
82  inline boost::shared_ptr<CORE_ArrayList<T> > getThis() {
83  boost::shared_ptr<CORE_ArrayList<T> > p;
85  return p;
86  };
90  inline boost::shared_ptr<const CORE_ArrayList<T> > getThis() const {
91  boost::shared_ptr<const CORE_ArrayList<T> > p;
93  return p;
94  };
95 
96  // ----------------
97  // New constructors
98  // ----------------
99 public:
103  static inline boost::shared_ptr<CORE_ArrayList<T> > New() {
104  boost::shared_ptr<CORE_ArrayList<T> > p(new CORE_ArrayList<T>(),
106  p->setThis(p);
107  return p;
108  };
112  static inline boost::shared_ptr<CORE_ArrayList<T> > New(const tUIndex& n) {
113  boost::shared_ptr<CORE_ArrayList<T> > p(new CORE_ArrayList<T>(n),
115  p->setThis(p);
116  return p;
117  };
118  // ---------------------------
119  // Accessor & basic operators
120  // ---------------------------
121 
125  template<class Q>
126  CORE_ArrayList<T>& operator=(const CORE_ArrayList<Q>& f) {
127  copy(f);
128  return (*this);
129  };
133  template<class Q>
134  inline CORE_ArrayList<T>& operator=(const Q& f) {
136  return (*this);
137  };
138 
142  template<class Q>
143  void copy(const CORE_Array<Q>& f) {
145  const CORE_ArrayList<Q>* lf=dynamic_cast<const CORE_ArrayList<Q>* >(&f);
146  if (lf!=null) {
148  setOrder(lf->getOrder());
149  }
150  }
151 public:
152 
153 
154 
155 
156  // SET & GET Methods
157  // ==================
161  inline void setCapacityFactor(const tFlag& n) {
162  mCapacityFactor=n;
163  };
166  inline const tFlag& getCapacityFactor() const {return mCapacityFactor;};
167 
170  inline void setOrder(const tFlag& order) {
171  mOrder=order;
172  }
175  inline const tFlag& getOrder() const {
176  return mOrder;
177  }
178  //LIST Manipulations
179  //===================
182  virtual void clear() {
184  }
185 
186  /* \brief add an element to the array
187  * @param v: value to add
188  */
189  template<class Q>
190  void push_back(const Q& v);
191 
192 
199  void insertAtIndex(const tUIndex& i,const T& v);
200 
204  tUIndex insert(const T& v);
205 
206 
210  tBoolean remove(const T& v);
211 
215  void removeAtIndex(const tUIndex& i);
216 
220  void contractToLastElements(const tUIndex& n);
221 
222 
223 
228  inline tBoolean exists(const T& obj) const {
229  const T* values=CORE_Array<T>::getValues();
230  const tUIndex& n=CORE_Array<T>::getSize();
231  for (tUIndex i=0;i<n;i++) {
232  if (*values==obj) {
233  return true;
234  }
235  values++;
236  }
237  return false;
238  }
239 
242  void reverse();
243 
244 
245 
248  void append(const CORE_ArrayList<T>& array);
249 
250 public:
251  // -----------------
252  // SORTING Methods
253  // -----------------
254 
258  inline void sort(const tFlag& order) {
259  mOrder=order;
260  sort(&(*this)[0],CORE_Array<T>::getSize(),order);
261  };
264  inline void sort() {
265  //if no order is specified, order in increasing list by default
267  sort(mOrder);
268  };
269 
272  static void sort(T* items,
273  const tUIndex& N,
274  const tFlag& order);
275 
276 
285  static tBoolean search(const T* values, const tUIndex& n,const tFlag& order,
286  const T& value,
287  tUIndex& index);
288 
294  inline tBoolean search(const T& value,tUIndex& index) {
297  getOrder(),value,index);
298 
299  }
300 
301 
302 
303 
304 
305 };
306 
307 #include "CORE_ArrayList.hpp"
308 
325 
326 
340 
353 #endif
void reverse()
reverse the array
Definition: CORE_ArrayList.hpp:248
CORE_ArrayList< tReal > CORE_RealArrayList
Definition: CORE_ArrayList.h:313
const tUIndex & getSize() const
return the size of the array for reading
Definition: CORE_Array.h:1018
virtual void clear()
clear the array : desallocate the array
Definition: CORE_Array.h:300
static boost::shared_ptr< CORE_ArrayList< T > > New()
return a CORE_Array shared pointer
Definition: CORE_ArrayList.h:103
tFlag mOrder
Definition: CORE_ArrayList.h:21
CORE_ArrayList< tChar > CORE_CharArrayList
Definition: CORE_ArrayList.h:310
tBoolean exists(const T &obj) const
return rtur if the value obj exists
Definition: CORE_ArrayList.h:228
void getSharedPointer(boost::shared_ptr< const CORE_ArrayList< T > > &p) const
return the shared pointer corresponding to the class whith casting
Definition: CORE_ArrayList.h:73
TYPEDEF_SPTR(CORE_DoubleArrayList)
tBoolean search(const T &value, tUIndex &index)
search the value in values vector ordered in order
Definition: CORE_ArrayList.h:294
CORE_ArrayList< tFlag > CORE_FlagArrayList
Definition: CORE_ArrayList.h:316
this class describes a list interface
Definition: CORE_List.h:12
void contractToLastElements(const tUIndex &n)
keep only the last n elements of the array and set its capacity also to n
Definition: CORE_ArrayList.hpp:94
const tFlag & getOrder() const
get the oder
Definition: CORE_ArrayList.h:175
CORE_ArrayList< tUIndex > CORE_UIndexArrayList
Definition: CORE_ArrayList.h:323
void setCapacityFactor(const tFlag &n)
set the capacity factor
Definition: CORE_ArrayList.h:161
CORE_ArrayList< tBoolean > CORE_BooleanArrayList
Definition: CORE_ArrayList.h:312
#define tBoolean
Definition: types.h:139
static tBoolean search(const T *values, const tUIndex &n, const tFlag &order, const T &value, tUIndex &index)
search the value in values array ordered in order
Definition: CORE_ArrayList.hpp:273
CORE_ArrayList()
build an array of T*
Definition: CORE_ArrayList.h:27
boost::shared_ptr< CORE_ArrayList< T > > getThis()
return the shared pointer this
Definition: CORE_ArrayList.h:82
void insertAtIndex(const tUIndex &i, const T &v)
insert the object at index i
Definition: CORE_ArrayList.hpp:122
virtual ~CORE_ArrayList()
destroy an array of T*
Definition: CORE_ArrayList.h:52
#define null
Definition: types.h:144
CORE_ArrayList< tLInt > CORE_LongArrayList
Definition: CORE_ArrayList.h:322
void push_back(const Q &v)
Definition: CORE_ArrayList.hpp:11
CORE_ArrayList< tDComplex > CORE_DoubleComplexArrayList
Definition: CORE_ArrayList.h:315
CORE_ArrayList< T > & operator=(const Q &f)
operator =
Definition: CORE_ArrayList.h:134
void copy(const CORE_Array< Q > &f)
copy the array list f
Definition: CORE_ArrayList.h:143
void append(const CORE_ArrayList< T > &array)
add the arry list at the end
Definition: CORE_ArrayList.hpp:328
void removeAtIndex(const tUIndex &i)
remove the element at index
Definition: CORE_ArrayList.hpp:66
CORE_ArrayList< tComplex > CORE_ComplexArrayList
Definition: CORE_ArrayList.h:314
CORE_ArrayList(const CORE_Array< T > &c)
build an array by a copy of c
Definition: CORE_ArrayList.h:34
this class describes an array
Definition: CORE_Array.h:19
void setOrder(const tFlag &order)
set the oder
Definition: CORE_ArrayList.h:170
const T * getValues() const
get the values of the array for reading
Definition: CORE_Array.h:930
void getSharedPointer(boost::shared_ptr< CORE_ArrayList< T > > &p)
return the shared pointer corresponding to the class with casting
Definition: CORE_ArrayList.h:65
void getSharedPointer(SP::CORE_Object &p)
get the shared pointer of this class into p
Definition: CORE_Object.h:97
CORE_ArrayList< tUSInt > CORE_USIntArrayList
Definition: CORE_ArrayList.h:319
#define tUIndex
Definition: types.h:126
void sort()
sort the array in an increasing order obj[i-1] is obj[i] with respect to getOrder ...
Definition: CORE_ArrayList.h:264
static boost::shared_ptr< CORE_ArrayList< T > > New(const tUIndex &n)
return a CORE_Array shared pointer
Definition: CORE_ArrayList.h:112
CORE_ArrayList< tInt > CORE_IntArrayList
Definition: CORE_ArrayList.h:311
CORE_ArrayList(const tUIndex &n)
build an array of size n
Definition: CORE_ArrayList.h:41
CORE_ArrayList< tSInt > CORE_SIntArrayList
Definition: CORE_ArrayList.h:318
tUIndex insert(const T &v)
insert the element in the array with respect to the order of the list
Definition: CORE_ArrayList.hpp:166
CORE_ArrayList< double > CORE_DoubleArrayList
Definition: CORE_ArrayList.h:309
Definition: CORE_ArrayList.h:12
CORE_ArrayList< tSInt > CORE_ShortArrayList
Definition: CORE_ArrayList.h:317
CORE_ArrayList< tIndex > CORE_IndexArrayList
Definition: CORE_ArrayList.h:324
TYPEDEF_SVPTR(CORE_BooleanArrayList)
CORE_ArrayList< tInteger > CORE_IntegerArrayList
Definition: CORE_ArrayList.h:320
virtual void clear()
clear the array
Definition: CORE_ArrayList.h:182
static const tFlag LT
=
Definition: CORE_List.h:23
CORE_ArrayList< T > & operator=(const CORE_ArrayList< Q > &f)
operator =
Definition: CORE_ArrayList.h:126
tFlag mCapacityFactor
Definition: CORE_ArrayList.h:20
CORE_ArrayList< tUInteger > CORE_UIntegerArrayList
Definition: CORE_ArrayList.h:321
void sort(const tFlag &order)
sort the array in an increasing order obj[i-1] is obj[i] with respect to order
Definition: CORE_ArrayList.h:258
boost::shared_ptr< const CORE_ArrayList< T > > getThis() const
return the shared pointer const this
Definition: CORE_ArrayList.h:90
static const tFlag NO_ORDER
Definition: CORE_List.h:20
void initArray(const Q &f)
init the array to uniform value
Definition: CORE_Array.h:316
void copy(const CORE_Array< Q > &f)
copy the array
Definition: CORE_Array.hpp:16
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141
#define tFlag
Definition: types.h:74
const tFlag & getCapacityFactor() const
get the capacity factor
Definition: CORE_ArrayList.h:166