1 #ifndef __XBOT_MATLOGGER2_BUFFER_BLOCK__ 2 #define __XBOT_MATLOGGER2_BUFFER_BLOCK__ 7 #include <eigen3/Eigen/Dense> 74 int dim_rows,
int dim_cols,
107 template <
typename Derived>
108 bool add_elem(
const Eigen::MatrixBase<Derived>& data);
123 int& valid_elements);
149 typedef std::shared_ptr<BufferBlock> Ptr;
157 BufferBlock(
int dim,
int block_size);
167 template <
typename Derived>
168 bool add(
const Eigen::MatrixBase<Derived>& data);
181 const Eigen::MatrixXd& get_data()
const;
188 int get_valid_elements()
const;
190 int get_size()
const;
191 int get_size_bytes()
const;
200 Eigen::MatrixXd _buf;
215 BufferBlock::Ptr _current_block;
219 std::unique_ptr<QueueImpl> _queue;
222 CallbackType _on_block_available;
232 template <
typename Derived>
233 inline bool XBot::VariableBuffer::BufferBlock::add(
const Eigen::MatrixBase<Derived>& data)
236 if(_write_idx == get_size())
242 double * col_ptr = _buf.data() + _write_idx*_buf.rows();
245 Eigen::Map<Eigen::MatrixXd> elem_map(col_ptr,
246 data.rows(), data.cols());
249 elem_map.noalias() = data.template cast<double>();
259 template <
typename Derived>
263 if( data.size() != _rows*_cols )
265 fprintf(stderr,
"Unable to add element to variable '%s': \ 266 size does not match (%d vs %d)\n",
267 _name.c_str(), (int)data.size(), _rows*_cols);
273 if(!_current_block->add(data))
280 _current_block->reset();
std::pair< int, int > get_dimension() const
bool flush_to_queue()
Writes current block to the queue.
void set_buffer_mode(VariableBuffer::Mode mode)
Set whether this buffer should be treated as a (possibly dual threaded) producer-consumer queue...
Mode
Enum for specifying the type of buffer.
bool add_elem(const Eigen::MatrixBase< Derived > &data)
Add an element to the buffer.
bool read_block(Eigen::MatrixXd &data, int &valid_elements)
Reads a whole block from the queue, if one is available.
VariableBuffer(std::string name, int dim_rows, int dim_cols, int block_size)
Constructor.
The VariableBuffer class implements a memory buffer for a single logged variable. ...
double variable_free_space
const char * variable_name
std::function< void(BufferInfo)> CallbackType
void set_on_block_available(CallbackType callback)
Sets a callback that is used to notify that a new block has been pushed into the queue.
const std::string & get_name() const
The QueueImpl class implements the buffering strategy for a single logged variable.