fifo.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef ECL_CONTAINERS_FIFO_HPP_
16 #define ECL_CONTAINERS_FIFO_HPP_
17 
18 /*****************************************************************************
19 ** Includes
20 *****************************************************************************/
21 
22 #include <algorithm> // std::copy
23 #include <ecl/config/macros.hpp>
24 #include <ecl/errors/compile_time_assert.hpp>
25 #include <ecl/exceptions/standard_exception.hpp>
26 #include "array.hpp"
27 
28 /*****************************************************************************
29 ** Namespaces
30 *****************************************************************************/
31 
32 namespace ecl {
33 
34 /*****************************************************************************
35 ** Interface
36 *****************************************************************************/
81 template<typename T>
82 class ECL_PUBLIC FiFo
83 {
84 public:
89  FiFo( const unsigned int length = 0 ) :
90  size_fifo(length),
91  running_index(0)
92  {
93  if ( size_fifo > 0 ) {
94  data.resize( size_fifo );
95  }
96  }
97 
103  FiFo( const unsigned int length, const T &value ) :
104  size_fifo(length),
105  running_index(0)
106  {
107  if ( size_fifo > 0 ) {
108  data = Array<T>::Constant(size_fifo,value);
109  }
110  }
111  virtual ~FiFo() {}
122  T & operator[] (int idx) {
123  return data[ ((running_index+idx)%size_fifo) ];
124  }
125 
132  const T & operator[] (int idx) const {
133  return data[ ((running_index+idx)%size_fifo) ];
134  }
135 
143  void push_back( const T & datum ) {
144  data[ running_index++ ] = datum;
145  running_index %= size_fifo;
146  }
147 
152  void fill( const T & value ) {
153  for( unsigned int i=0; i<size_fifo; i++ ) data[i] = value;
154  }
155 
160  unsigned int get_idx() { return running_index;}
161 
167  void resize( unsigned int length ) ecl_assert_throw_decl(StandardException) {
168  size_fifo = length;
169  ecl_assert_throw( (size_fifo>0), StandardException(LOC, OutOfRangeError, "SimpleFIFO start with zero size buffer"));
170  data.resize( size_fifo );
171  }
172 
173 private:
175  unsigned int size_fifo;
176  unsigned int running_index;
177 };
178 
179 } // namespace ecl
180 
181 #endif /* ECL_CONTAINERS_FIFO_HPP_ */
ecl_geometry_PUBLIC void resize(Trajectory2D &trajectory, const int &size)
#define LOC
Stringify the line of code you are at.
data
#define ecl_assert_throw(expression, exception)
Debug mode throw with a logical condition check.
OutOfRangeError
#define ECL_PUBLIC
#define ecl_assert_throw_decl(exception)
Assure throw exception declaration.
static ConstantArray< Type, Size > Constant(const Type &value)
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13