USML
seq_linear.h
1 
5 #ifndef USML_TYPES_SEQ_LINEAR_H
6 #define USML_TYPES_SEQ_LINEAR_H
7 
8 #include <usml/types/seq_vector.h>
9 
10 namespace usml {
11 namespace types {
14 
19 class USML_DECLSPEC seq_linear : public seq_vector {
20 
22 public:
23  typedef const vector_reference<const self_type> const_closure_type;
24  typedef vector_reference<self_type> closure_type;
25 
26  //***************************************************************
27  // vritual functions
28 
29 public:
30 
40  virtual size_type find_index( value_type value ) {
41  return (size_type) max(
42  (difference_type) 0, min( (difference_type) _size-2,
43  (difference_type) floor( (value - _data(0)) / _increment(0) )));
44  }
45 
46  //***************************************************************
47  // constructors and destructors
48 
49 private:
57  void initialize( value_type first, value_type increment, size_type size ) {
58  value_type v = first ;
59  for (size_type n = 0; n < size; ++n) {
60  _data[n] = v ;
61  _increment[n] = increment ;
62  v += increment ;
63  }
64  }
65 public:
66 
68  virtual ~seq_linear() {}
69 
77  seq_linear( value_type first, value_type increment, size_type size ) :
78  seq_vector( size )
79  {
80  initialize( first, increment, size ) ;
81  }
82 
90  seq_linear( value_type first, value_type increment, int size ) :
91  seq_vector( (size_type) size )
92  {
93  initialize( first, increment, (size_type) size ) ;
94  }
95 
106  seq_linear( value_type first, value_type increment, value_type last ) :
107  seq_vector( (increment == 0.0) ? 1 : max(
108  (difference_type) 1,
109  (difference_type) floor(1.0+(last-first)/increment)))
110  {
111  initialize( first, increment, _size ) ;
112  }
113 
119  seq_linear( const seq_linear & copy ) : seq_vector( copy ) {
120  }
121 
123  virtual seq_vector* clone() const {
124  return new seq_linear( *this ) ;
125  }
126 
127 }; // end of class
128 
130 } // end of namespace types
131 } // end of namespace usml
132 
133 #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
seq_linear(value_type first, value_type increment, size_type size)
Construct sequence using first value, increment, and size.
Definition: seq_linear.h:77
virtual size_type find_index(value_type value)
Search for a value in this sequence.
Definition: seq_linear.h:40
void initialize(value_type first, value_type increment, size_type size)
Construct sequence using first value, increment, and size.
Definition: seq_linear.h:57
BOOST_UBLAS_INLINE matrix_unary1_traits< E, scalar_floor< typename E::value_type > >::result_type floor(const matrix_expression< E > &e)
Rounding elements of a matrix down to the nearest integer.
Definition: matrix_math.h:170
const vector_reference< const self_type > const_closure_type
Definition: seq_linear.h:23
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_linear(value_type first, value_type increment, value_type last)
Construct sequence using first value, increment value, and last value.
Definition: seq_linear.h:106
virtual seq_vector * clone() const
Create a copy using a reference to the base class.
Definition: seq_linear.h:123
Sequence defined by an evenly spaced grid of points.
Definition: seq_linear.h:19
vector_reference< self_type > closure_type
Definition: seq_linear.h:24
seq_linear(const seq_linear &copy)
Copies data from another sequence object.
Definition: seq_linear.h:119
vector< value_type >::size_type size_type
Definition: seq_vector.h:44
seq_linear self_type
Definition: seq_linear.h:21
virtual ~seq_linear()
Virtual destructor.
Definition: seq_linear.h:68
seq_linear(value_type first, value_type increment, int size)
Construct sequence using first value, increment, and size.
Definition: seq_linear.h:90
vector< value_type >::difference_type difference_type
Definition: seq_vector.h:45
A read-only, monotonic sequence of values.
Definition: seq_vector.h:36
double value_type
Definition: seq_vector.h:43