C++ main module for emicrom Package  1.0
CORE_MorseArray.h
Go to the documentation of this file.
1 #ifndef CORE_MorseArray_H
2 #define CORE_MorseArray_H
3 
4 #include "CORE_Object.h"
5 #include "CORE_Array.h"
6 
9 
30 template<class T>
31 class CORE_MorseArray : public CORE_Object {
32 
33 
34  // ATTRIBUTES
35 
36 public:
37 
38 
39 
40 private:
41 
42  //size of the array
44 
45  //values of the morse array
47 
48  //index of the first value for each element i in [0,mSize[
51 
52  //max number of values per element
54 
55  //increment of the indices array
57 
58  //number of packs
60 
61  //true if all the not null value is the same
63 
64 public:
65  // METHODS
66 
67  // CONSTRUCTORS
68 
72  mSize=0;
73  mLD=1;
74  mIncI=0;
75  mPacksNumber=1;
76  mIsConstant=false;
77  mIndices=CORE_UIndexArray::New();
78  mIsIndicesReferenced=false;
79  }
80 
81 
82 
83  // DESTRUCTORS
84 
85 
88  virtual ~CORE_MorseArray(void) {
89 
90  }
91 
92 
93 private:
94 
95 
96 
97 public:
98  // -------------------------
99  // shared pointer operator
100  // ------------------------
104  void getSharedPointer(boost::shared_ptr<CORE_MorseArray<T> >& p){
105  SP::CORE_Object r;
107  p=boost::dynamic_pointer_cast<CORE_MorseArray<T> >(r);
108  };
112  void getSharedPointer( boost::shared_ptr<const CORE_MorseArray<T> >& p) const{
113  SPC::CORE_Object r;
115  p=boost::dynamic_pointer_cast<const CORE_MorseArray<T> >(r);
116  };
117 private:
121  inline boost::shared_ptr<CORE_MorseArray<T> > getThis() {
122  boost::shared_ptr<CORE_MorseArray<T> > p;
123  getSharedPointer(p);
124  return p;
125  };
129  inline boost::shared_ptr<const CORE_MorseArray<T> > getThis() const {
130  boost::shared_ptr<const CORE_MorseArray<T> > p;
131  getSharedPointer(p);
132  return p;
133  };
134 
135 public:
136  // ----------------
137  // New constructors
138  // ----------------
139 public:
143  static inline boost::shared_ptr<CORE_MorseArray<T> > New() {
144  boost::shared_ptr<CORE_MorseArray<T> > p(new CORE_MorseArray<T>(),
146  p->setThis(p);
147  return p;
148  };
149 
150  // ACCESSORS
151  //==========
152 
156  inline T* operator[](const tUIndex& i) {
157  return &mValues[getIndex(i)];
158 
159  }
163  inline const T* operator[](const tUIndex& i) const {
164  return &mValues[getIndex(i)];
165  }
166 
167  //arithmetic operator
168  // ==================
169 
174  template<class Q>
175  inline CORE_MorseArray<T>& operator+=(const Q& f) {
176  mValues+=f;
177  return *this;
178  }
179 
184  template<class Q>
185  CORE_MorseArray<T>& operator-=(const Q& f) {
186  mValues-=f;
187  }
188 
189 
194  template<class Q>
195  inline CORE_MorseArray<T>& operator*=(const Q& f) {
196  mValues*=f;
197  return (*this);
198  }
203  template<class Q>
204  inline CORE_MorseArray<T>& operator/=(const Q& f) {
205  mValues/=f;
206  return (*this);
207  }
208 
209  //copy operator
210  // ============
211 
215  template<class Q>
216  CORE_MorseArray<T>& operator=(const CORE_MorseArray<Q>& f) {
217  copy(f);
218  return *this;
219  }
220 
221 
222  //iterators
223  //==========
224 
232  inline void begin(const tUIndex& start,
233  const tUInteger& iPack,
235  if (start>=mSize)
236  throw CORE_Exception("emicrom/core",
237  "CORE_MorseArray::begin(start,ipack,iter)",
238  CORE_Integer::toString(start)+" is too big (>="+CORE_Integer::toString(mSize)+")");
239  //get the index of the first value at index start
240  tUIndex &index=getIndices()[start+iPack];
241  //init the iterator from values at index*mLD (index is not supposed to be set)
242  //the index iterator to fill it at index start
243  iter.init(&getValues()[start*mLD],
244  &index,
245  mIncI);
246 
247  }
253  inline void begin(const tUIndex& start,
255  if (start>=mSize)
256  throw CORE_Exception("emicrom/core",
257  "CORE_MorseArray::begin(start,ipack,iter)",
258  CORE_Integer::toString(start)+" is too big (>="+CORE_Integer::toString(mSize)+")");
259  //get the index of the first value at index start
260  tUIndex &index=getIndices()[start];
261  //init the iterator from values at index*mLD (index is not supposed to be set)
262  //the index iterator to fill it
263  iter.init(&getValues()[index],
264  &index,
265  mIncI);
266 
267  }
268 
272  inline void begin(CORE_MorseArrayIterator<T>& iter ) {
273  begin(0,0,iter);
274  }
275 
280  inline void begin(const tUIndex& start, CORE_MorseArrayConstIterator<T>& iter) const {
281  tUIndex i=start*mIncI;
282  if (i>=mSize)
283  throw CORE_Exception("emicrom/core",
284  "CORE_MorseArray::begin(start,iter)",
285  CORE_Integer::toString(i)+" is too big (>="+CORE_Integer::toString(mSize)+")");
286 
287  const tUIndex &index=getIndices()[i];
288  iter.init(&getValues()[index],
289  &index,
290  mIncI);
291 
292  }
296  inline void begin(CORE_MorseArrayConstIterator<T>& iter) const {
297  begin(0,iter);
298  }
299 
300 
301  // SET methods
302  //============
303 
307  template<class Q>
308  void copy(const CORE_MorseArray<Q>& c) {
309  mIncI=c.getIndexIncrement();
310  mValues.copy(c.getValues());
311  mIndices->copy(c.getIndices());
313  mSize=c.getSize();
314  }
315 
318  inline void clear() {
319  mSize=0;
320  mIndices->clear();
321  mValues.clear();
322  mIncI=0;
323  }
328  inline void setUniformSize(const tUIndex& n,const tUIndex& ld) {
329  mLD=ld;
330  mSize=n;
331  mIndices->setSize(2);
332  mValues.setSize(mLD);
333  (*mIndices.get())[0]=0;
334  (*mIndices.get())[1]=mLD;
335  mIncI=0;
336  }
342  inline void setSize(const tUIndex& n,const tUIndex& m,const tUInteger& p) {
343  //size of each element
344  mLD=m;
345  //number of elements
346  mSize=n;
347  //set the size of the indices
348  mIndices->setSize(n+p);
349  //set the total number of values
350  mValues.setSize(n*mLD);
351  //increment of index array
352  mIncI=1;
353  //number of packs
354  mPacksNumber=p;
355  }
360  inline void setSize(const tUIndex& n,const tUIndex& m) {
361  setSize(n,m,1);
362  }
363 
368  mIndices=indices;
369  mIsIndicesReferenced=true;
370  }
371 
372 
376  void removeValue(const T& v);
377 
378 
381  inline void reset() {
382  mIndices->initArray(0);
383  mValues.initArray(0);
384 
385  }
386  // GET methods
387 
396  virtual tULLInt getMemorySize() const {
397  return mValues.getMemorySize()+((mIsIndicesReferenced)?0:mIndices->getMemorySize());
398 
399  }
400 
404  inline const tUIndex& getSize() const {
405  return mSize;
406  }
410  inline tUIndex getSize(const tUIndex& i) const {
411  const tUIndex *index=&(*mIndices.get())[i*mIncI];
412  return (tUIndex) ((*(index+1))-(*index));
413  }
414 
418  inline const tBoolean& getIndexIncrement() const {
419  return mIncI;
420  }
424  inline const tUIndex& getMaxValuesNumberPerElement() const {
425  return mLD;
426  }
427 
431  inline const tUInteger& getPacksNumber() const {
432  return mPacksNumber;
433  }
437  inline const CORE_Array<T>& getValues() const {
438  return mValues;
439  }
444  return mIndices;
445  }
449  inline const CORE_UIndexArray& getIndices() const {
450  return *mIndices.get();
451  }
452 
467  tBoolean saveToFile(const tString& fn) const;
468 
483  tBoolean loadFromFile(const tString& fn);
484 
485 
490  return mValues;
491  }
496  return *mIndices.get();
497  }
498 
499 
500 
505  inline const tUIndex& getIndex(const tUIndex& i) const {
506  return (*mIndices.get())[i*mIncI];
507  }
512  inline tUIndex& getIndex(const tUIndex& i) {
513  return (*mIndices.get())[i*mIncI];
514  }
515 
518  inline tBoolean isUniform() const {
519  return (mIncI==0) || (mIndices->getSize()==2);
520  }
523  inline const tBoolean& isConstant() const {
524  return mIsConstant;
525  }
526 
527 
530  inline void merge() {
531  MergeMorseArray(mPacksNumber,*mIndices.get(),mLD,mValues);
532  }
533 
536  inline void fitToSize() {
537  mValues.setSize((*mIndices.get())[mIndices->getSize()-1]);
538  mValues.fitToSize();
539  }
540 
541  // OTHERS methods
542 
543 
544 
545 public:
558  inline tBoolean uniformize() {
559  return uniformize(mIsConstant);
560  }
561 
562 private:
576 
577 public:
586  static void MergeMorseArrays(const tUInteger& nSubsets,
587  CORE_UIndexArray& indices,
588  const tUIndex& ld,
589  const vector<CORE_Array<T>* >& arrays);
590 
614  static void MergeMorseArray(const tUInteger& P,
615  CORE_UIndexArray& indices,
616  const tUIndex& ld,
617  CORE_Array<T>& array);
618 
621  virtual tString toString() const;
622 
623 
624 
625 
626 };
627 
628 #include "CORE_MorseArray.hpp"
629 
641 
653 
665 #endif
T * operator[](const tUIndex &i)
return the values for element at i
Definition: CORE_MorseArray.h:156
virtual void clear()
clear the array : desallocate the array
Definition: CORE_Array.h:300
const CORE_UIndexArray & getIndices() const
get the indices of the morse array for reading
Definition: CORE_MorseArray.h:449
static boost::shared_ptr< CORE_Array< tUIndex > > New()
return a CORE_Array shared pointer
Definition: CORE_Array.h:120
void init(T *values, tUIndex *index, const tBoolean &inc)
init the iterator to pointers
Definition: CORE_MorseArrayIterator.h:81
CORE_Array< tUIndex > CORE_UIndexArray
Definition: CORE_Array.h:1073
void copy(const CORE_MorseArray< Q > &c)
copy the morse array param c: the morse array to copy
Definition: CORE_MorseArray.h:308
CORE_UIndexArray & getIndices()
get the indices of the morse array for reading
Definition: CORE_MorseArray.h:495
void setUniformSize(const tUIndex &n, const tUIndex &ld)
set the morse array to be uniform of size n x ld
Definition: CORE_MorseArray.h:328
tUIndex mSize
Definition: CORE_MorseArray.h:43
tBoolean mIsConstant
Definition: CORE_MorseArray.h:62
boost::shared_ptr< CORE_MorseArray< T > > getThis()
return the shared pointer this for writing
Definition: CORE_MorseArray.h:121
CORE_MorseArray< tUIndex > CORE_UIndexMorseArray
Definition: CORE_MorseArray.h:633
#define tUInteger
Definition: types.h:91
const tBoolean & getIndexIncrement() const
get the index increment
Definition: CORE_MorseArray.h:418
CORE_MorseArray< tUSInt > CORE_USIntMorseArray
Definition: CORE_MorseArray.h:637
This class describes a general morse array of size N. A morse array is composed by.
Definition: CORE_MorseArray.h:31
const T * operator[](const tUIndex &i) const
return the values for element at i
Definition: CORE_MorseArray.h:163
CORE_MorseArray< T > & operator/=(const Q &f)
This/=f.
Definition: CORE_MorseArray.h:204
CORE_MorseArray< tReal > CORE_RealMorseArray
Definition: CORE_MorseArray.h:639
tBoolean loadFromFile(const tString &fn)
load the morse array from file
Definition: CORE_MorseArray.hpp:74
T & get(const tUIndex &i)
get the value of the array at index i
Definition: CORE_Array.h:555
virtual ~CORE_MorseArray(void)
destroy
Definition: CORE_MorseArray.h:88
void reset()
init the array to 0
Definition: CORE_MorseArray.h:381
void setIndicesByReference(SP::CORE_UIndexArray indices)
set the indices by reference
Definition: CORE_MorseArray.h:367
void fitToSize()
fit to size
Definition: CORE_MorseArray.h:536
const tUIndex & getMaxValuesNumberPerElement() const
get the max number of values per element
Definition: CORE_MorseArray.h:424
#define tBoolean
Definition: types.h:139
CORE_MorseArray()
create an array
Definition: CORE_MorseArray.h:71
static boost::shared_ptr< CORE_MorseArray< T > > New()
create a new shared pointer of CORE_MorseArray
Definition: CORE_MorseArray.h:143
CORE_MorseArray< tIndex > CORE_IndexMorseArray
Definition: CORE_MorseArray.h:634
void setSize(const tUIndex &n)
set the size
Definition: CORE_Array.h:292
tBoolean uniformize()
uniformize the array
Definition: CORE_MorseArray.h:558
tString toString() const
return the string associated to the integer
Definition: CORE_Integer.h:106
void begin(const tUIndex &start, CORE_MorseArrayConstIterator< T > &iter) const
create an iterator to index start for reading
Definition: CORE_MorseArray.h:280
SP::CORE_UIndexArray mIndices
Definition: CORE_MorseArray.h:49
CORE_MorseArray< tUChar > CORE_UCharMorseArray
Definition: CORE_MorseArray.h:636
tBoolean saveToFile(const tString &fn) const
save the morse array into file
Definition: CORE_MorseArray.hpp:16
void begin(CORE_MorseArrayConstIterator< T > &iter) const
create an iterator to index 0 fro reading
Definition: CORE_MorseArray.h:296
const tUInteger & getPacksNumber() const
get the number of packed
Definition: CORE_MorseArray.h:431
static void MergeMorseArrays(const tUInteger &nSubsets, CORE_UIndexArray &indices, const tUIndex &ld, const vector< CORE_Array< T > * > &arrays)
merge morse arrays
Definition: CORE_MorseArray.hpp:459
void merge()
merge the morse array built by P packs
Definition: CORE_MorseArray.h:530
CORE_MorseArray< T > & operator-=(const Q &f)
This+=f.
Definition: CORE_MorseArray.h:185
const CORE_Array< T > & getValues() const
get the values of the morse array
Definition: CORE_MorseArray.h:437
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
void removeValue(const T &v)
remove the value
Definition: CORE_MorseArray.hpp:237
tBoolean isUniform() const
return true if the morse array is unifom
Definition: CORE_MorseArray.h:518
tUInteger mPacksNumber
Definition: CORE_MorseArray.h:59
void clear()
clear the morse array : desallocate the data.
Definition: CORE_MorseArray.h:318
const tUIndex & getIndex(const tUIndex &i) const
get the pointer to the index of the first value for element i for reading
Definition: CORE_MorseArray.h:505
this class describes an array
Definition: CORE_Array.h:19
This class describes a more array iterator.
Definition: CORE_MorseArrayConstIterator.h:17
void getSharedPointer(boost::shared_ptr< const CORE_MorseArray< T > > &p) const
return the shared pointer corresponding to the class whith casting
Definition: CORE_MorseArray.h:112
virtual tString toString() const
return the string reprensetaion of the morse array
Definition: CORE_MorseArray.hpp:5
virtual void fitToSize()
fit the array alocation exactly to size fit the allocation of the array to its size ...
Definition: CORE_Array.hpp:128
CORE_MorseArray< long double > CORE_LDoubleMorseArray
Definition: CORE_MorseArray.h:631
const tUIndex & getSize() const
get the number of elements of the array
Definition: CORE_MorseArray.h:404
tUIndex getSize(const tUIndex &i) const
get the number of values for element i
Definition: CORE_MorseArray.h:410
void getSharedPointer(SP::CORE_Object &p)
get the shared pointer of this class into p
Definition: CORE_Object.h:97
virtual tULLInt getMemorySize() const
return the memory size in byte
Definition: CORE_Array.h:545
SP::CORE_UIndexArray getIndicesByReference() const
get the indices of the morse array for reading/writing
Definition: CORE_MorseArray.h:443
virtual tULLInt getMemorySize() const
return the memory size in byte
Definition: CORE_MorseArray.h:396
CORE_MorseArray< double > CORE_DoubleMorseArray
Definition: CORE_MorseArray.h:630
CORE_MorseArray< T > & operator*=(const Q &f)
This*=f.
Definition: CORE_MorseArray.h:195
#define tUIndex
Definition: types.h:126
CORE_MorseArray< tBoolean > CORE_BooleanMorseArray
Definition: CORE_MorseArray.h:640
CORE_Array< T > & getValues()
get the values of the morse array
Definition: CORE_MorseArray.h:489
CORE_MorseArray< tFlag > CORE_FlagMorseArray
Definition: CORE_MorseArray.h:638
void begin(CORE_MorseArrayIterator< T > &iter)
create an iterator to index 0 of pack 0 for writing
Definition: CORE_MorseArray.h:272
void setSize(const tUIndex &n, const tUIndex &m)
set the size of the morse array
Definition: CORE_MorseArray.h:360
void init(const T *values, const tUIndex *index, const tBoolean &inc)
init an iterator to pointers
Definition: CORE_MorseArrayConstIterator.h:79
abstract base class for most classes.
Definition: CORE_Object.h:53
boost::shared_ptr< const CORE_MorseArray< T > > getThis() const
return the shared pointer this for reading
Definition: CORE_MorseArray.h:129
#define tString
Definition: types.h:135
CORE_MorseArray< T > & operator+=(const Q &f)
This+=f.
Definition: CORE_MorseArray.h:175
CORE_MorseArray< tChar > CORE_CharMorseArray
Definition: CORE_MorseArray.h:635
tUIndex mLD
Definition: CORE_MorseArray.h:53
const tBoolean & isConstant() const
return true if the morse array is constant
Definition: CORE_MorseArray.h:523
tBoolean mIncI
Definition: CORE_MorseArray.h:56
CORE_MorseArray< T > & operator=(const CORE_MorseArray< Q > &f)
copy the array
Definition: CORE_MorseArray.h:216
void begin(const tUIndex &start, const tUInteger &iPack, CORE_MorseArrayIterator< T > &iter)
create an iterator to index start for the pack at iPack for creating the morse array ...
Definition: CORE_MorseArray.h:232
void getSharedPointer(boost::shared_ptr< CORE_MorseArray< T > > &p)
return the shared pointer corresponding to the class with casting d*
Definition: CORE_MorseArray.h:104
#define tULLInt
Definition: types.h:45
TYPEDEF_SVPTR(CORE_DoubleMorseArray)
tUIndex & getIndex(const tUIndex &i)
get the index of the first value for element i for writting
Definition: CORE_MorseArray.h:512
CORE_MorseArray< float > CORE_FloatMorseArray
Definition: CORE_MorseArray.h:632
This class describes a more array iterator.
Definition: CORE_MorseArrayIterator.h:15
TYPEDEF_SPTR(CORE_DoubleMorseArray)
tBoolean mIsIndicesReferenced
Definition: CORE_MorseArray.h:50
void begin(const tUIndex &start, CORE_MorseArrayIterator< T > &iter)
create an iterator to index start for the pack at iPack for writing the morse array only in values ...
Definition: CORE_MorseArray.h:253
static void MergeMorseArray(const tUInteger &P, CORE_UIndexArray &indices, const tUIndex &ld, CORE_Array< T > &array)
merge morse arrays
Definition: CORE_MorseArray.hpp:358
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
void setSize(const tUIndex &n, const tUIndex &m, const tUInteger &p)
set the size of the morse array
Definition: CORE_MorseArray.h:342
CORE_Array< T > mValues
Definition: CORE_MorseArray.h:46
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:141