USML
seq_vector.h
1 
5 #ifndef USML_TYPES_SEQ_VECTOR_H
6 #define USML_TYPES_SEQ_VECTOR_H
7 
8 #include <boost/numeric/ublas/vector.hpp>
9 #include <boost/numeric/ublas/io.hpp>
10 
11 namespace usml {
12 namespace types {
13 
14 using boost::numeric::ublas::vector;
15 
18 
36 class USML_DECLSPEC seq_vector: public vector_container<seq_vector>
37 {
38  //**************************************************
39  // type definisions
40 
42 public:
43  typedef double value_type;
44  typedef vector<value_type>::size_type size_type;
45  typedef vector<value_type>::difference_type difference_type;
46  typedef vector<value_type>::const_reference const_reference;
47  typedef vector<value_type>::const_reference reference;
48  typedef vector<value_type>::array_type array_type;
49 
50  typedef const vector_reference<const self_type> const_closure_type;
51  typedef vector_reference<self_type> closure_type;
52  typedef vector<value_type>::storage_category storage_category;
53 
54  typedef vector<value_type>::const_iterator const_iterator;
55  typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
56 
57  //**************************************************
58  // data property
59 
60 protected:
64  vector<value_type> _data;
65 
66 public:
75  inline value_type operator[](size_type index) const {
76  return _data[index];
77  }
78 
87  virtual value_type operator()(size_type index) const {
88  index = max( (size_type) 0, min(_max_index,index) );
89  return _data[index] ;
90  }
91 
95  const array_type &data () const {
96  return _data.data() ;
97  }
98 
99  //**************************************************
100  // increment property
101 
102 protected:
106  vector<value_type> _increment;
107 
108 public:
109 
119  inline value_type increment(size_type index) const {
120  index = max( (size_type) 0, min(_max_index,index) );
121  return _increment[index] ;
122  }
123 
124  //**************************************************
125  // size property
126 
127 protected:
130 
133 
134 public:
138  inline size_type size() const {
139  return _size ;
140  }
141 
142  //**************************************************
143  // iterators
144 
149  inline const_iterator begin() const {
150  return _data.begin() ;
151  }
152 
157  inline const_iterator end() const {
158  return _data.end() ;
159  }
160 
166  return _data.rbegin() ;
167  }
168 
173  inline const_reverse_iterator rend() const {
174  return _data.rend() ;
175  }
176 
181  inline const_iterator find(size_type index) const {
182  return _data.find(index) ;
183  }
184 
185  //**************************************************
186  // virtual functions
187 
199  virtual size_type find_index(value_type value) = 0;
200 
201  //**************************************************
202  // constructors and destructors
203 
204 protected:
209  _data(size), _increment(size), _size(size), _max_index(size-1)
210  {
211  }
212 
218  seq_vector( const seq_vector & copy ) :
219  _data(copy._data), _increment(copy._increment),
220  _size(copy._size), _max_index(copy._max_index)
221  {
222  }
223 
224 public:
226  virtual ~seq_vector()
227  {
228  }
229 
231  virtual seq_vector* clone() const = 0;
232 
233 }; // end of class
234 
236 } // end of namespace types
237 } // end of namespace usml
238 
239 #endif
BOOST_UBLAS_INLINE boost::enable_if< boost::is_convertible< T2, typename E1::value_type >, typename matrix_binary_scalar2_traits< E1, const T2, scalar_max< typename E1::value_type, T2 > >::result_type >::type max(const matrix_expression< E1 > &e1, const T2 &e2)
Maximum between a matrix and a scalar.
Definition: matrix_math.h:143
value_type increment(size_type index) const
Retrieves the increment between two elements in this sequence.
Definition: seq_vector.h:119
seq_vector(const seq_vector &copy)
Copies data from another seq_vector object.
Definition: seq_vector.h:218
vector_reference< self_type > closure_type
Definition: seq_vector.h:51
vector< value_type >::const_reference reference
Definition: seq_vector.h:47
vector< value_type > _increment
Cache of increment values.
Definition: seq_vector.h:106
const_iterator find(size_type index) const
Create iterator for a random position in the sequence.
Definition: seq_vector.h:181
BOOST_UBLAS_INLINE boost::enable_if< boost::is_convertible< T2, typename E1::value_type >, typename matrix_binary_scalar2_traits< E1, const T2, scalar_min< typename E1::value_type, T2 > >::result_type >::type min(const matrix_expression< E1 > &e1, const T2 &e2)
Minimum between a matrix and a scalar.
Definition: matrix_math.h:158
seq_vector self_type
Definition: seq_vector.h:41
const_iterator end() const
Create iterator for the end of sequence.
Definition: seq_vector.h:157
vector< value_type >::storage_category storage_category
Definition: seq_vector.h:52
vector< value_type >::const_reference const_reference
Definition: seq_vector.h:46
const_reverse_iterator rend() const
Create iterator for the end of reverse sequence.
Definition: seq_vector.h:173
const size_type _size
Number of elements in the sequence.
Definition: seq_vector.h:129
vector< value_type >::const_iterator const_iterator
Definition: seq_vector.h:54
const_reverse_iterator rbegin() const
Create iterator for the beginning of reverse sequence.
Definition: seq_vector.h:165
size_type size() const
Returns the number of elements in this sequence.
Definition: seq_vector.h:138
reverse_iterator_base< const_iterator > const_reverse_iterator
Definition: seq_vector.h:55
virtual value_type operator()(size_type index) const
Retrieves the value at a specified index in the sequence in the safest way possible.
Definition: seq_vector.h:87
vector< value_type >::size_type size_type
Definition: seq_vector.h:44
value_type operator[](size_type index) const
Retrieves the value at a specified index in the sequence in the fastest way possible.
Definition: seq_vector.h:75
seq_vector(size_type size)
Initialize data caches.
Definition: seq_vector.h:208
const size_type _max_index
Largest valid index number (one less than _size).
Definition: seq_vector.h:132
const vector_reference< const self_type > const_closure_type
Definition: seq_vector.h:50
vector< value_type > _data
Cache of sequence values.
Definition: seq_vector.h:64
vector< value_type >::difference_type difference_type
Definition: seq_vector.h:45
const array_type & data() const
Convert seqence into a normal C++ array,.
Definition: seq_vector.h:95
A read-only, monotonic sequence of values.
Definition: seq_vector.h:36
vector< value_type >::array_type array_type
Definition: seq_vector.h:48
virtual ~seq_vector()
Virtual destructor.
Definition: seq_vector.h:226
double value_type
Definition: seq_vector.h:43
const_iterator begin() const
Create iterator for the beginning of sequence.
Definition: seq_vector.h:149