brainrat-private  5.0.5
array.h
Go to the documentation of this file.
1 /* Copyright (C) 2000-2013 CEA
2  *
3  * This software and supporting documentation were developed by
4  * bioPICSEL
5  * CEA/DSV/I²BM/MIRCen/LMN, Batiment 61,
6  * 18, route du Panorama
7  * 92265 Fontenay-aux-Roses
8  * France
9  */
10 
11 #ifndef BIOPROCESSING_OBJECT_ARRAY_H
12 #define BIOPROCESSING_OBJECT_ARRAY_H
13 
14 #include <string>
15 #include <vector>
16 #include <cartobase/object/object.h>
17 
18 namespace carto
19 {
20 
21  template <typename T>
22  class Array: public virtual Interface,
23  public DynArrayInterface,
24  public std::vector<T>
25  {
26  private :
27  typedef typename std::vector<T>::const_iterator ArrayIterator;
28 
29  public :
30  Array() : std::vector<T>() {}
31 
32  virtual ~Array() {
33 // std::cout << "In array destructor" << std::endl << std::flush;
34 // typename std::vector<T>::const_iterator it, et = std::vector<T>::end();
35 // for(it = std::vector<T>::begin(); it < et; it++)
36 // {
37 // //cout << "*it : " << *it << endl << flush;
38 // std::cout << "it : " << typeid(*it).name() << std::endl << std::flush;
39 // }
40  }
41 
42  class interfaced_iterator;
43 
44  inline interfaced_iterator getIterator() const
45  {
46  return interfaced_iterator( std::vector<T>::begin(), std::vector<T>::end() );
47  }
48 
50  virtual Object objectIterator() const
51  {
52  return Object::value( getIterator() );
53  }
54 
55  virtual size_t size() const { return std::vector<T>::size(); }
56 
57  virtual Object getArrayItem( int index ) const { return Object::value(std::vector<T>::at( index )); }
58  virtual void setArrayItem( int index, Object o ) { std::vector<T>::at( index ) = o->GenericObject::value<T>(); }
59 
62  virtual void reserveArray( size_t s ) { std::vector<T>::reserve(s); }
66  virtual void resizeArray( size_t s ) { std::vector<T>::resize(s); }
69  virtual void removeArrayItem( int i ) { std::vector<T>::erase( std::vector<T>::begin() + i ); }
72  virtual void insertArrayItem( int i, Object o ) { std::vector<T>::insert( std::vector<T>::begin() + i, o->GenericObject::value<T>() ); }
73 
74  class interfaced_iterator : public IteratorInterface
75  {
76 
77  public:
79  {
80  }
81 
82 
83  //-----------------------------------------------------------------------------
84  inline interfaced_iterator( const ArrayIterator &begin,
85  const ArrayIterator &end ) :
86  _iterator( begin ), _end( end )
87  {
88  }
89 
92  virtual bool isValid() const
93  {
94  return _iterator != _end;
95  }
96 
98  virtual Object currentValue() const
99  {
100  return Object::value(*_iterator);
101  }
102 
103 
105  virtual void next()
106  {
107  ++_iterator;
108  }
109 
110 
111  private:
112 
114 
115  ArrayIterator _iterator;
116  ArrayIterator _end;
117  };
118 
119  };
120 
121 }
122 
123 #endif
virtual size_t size() const
Definition: array.h:55
STL namespace.
virtual Object currentValue() const
Access the value of the element pointed to by the iterator.
Definition: array.h:98
virtual void next()
Point to the next element of the iterable container.
Definition: array.h:105
virtual void resizeArray(size_t s)
resize the array.
Definition: array.h:66
virtual void reserveArray(size_t s)
like the STL std::vector::reserve(), memory is reserved but no element is stored
Definition: array.h:62
virtual bool isValid() const
true if the iterator points to a valid value, false when the end of the iterable container has been r...
Definition: array.h:92
virtual Object objectIterator() const
returns an object implementing the IteratorIntrerface
Definition: array.h:50
virtual void insertArrayItem(int i, Object o)
inserts an element into the array.
Definition: array.h:72
interfaced_iterator(const ArrayIterator &begin, const ArrayIterator &end)
Definition: array.h:84
virtual void removeArrayItem(int i)
removes an element from the array.
Definition: array.h:69
virtual Object getArrayItem(int index) const
Definition: array.h:57
virtual ~Array()
Definition: array.h:32
virtual void setArrayItem(int index, Object o)
Definition: array.h:58
interfaced_iterator getIterator() const
Definition: array.h:44