1 #ifndef __XBOT_MATLOGGER2_H__ 2 #define __XBOT_MATLOGGER2_H__ 6 #include <unordered_map> 8 #include <eigen3/Eigen/Dense> 72 typedef std::weak_ptr<MatLogger2>
WeakPtr;
73 typedef std::shared_ptr<MatLogger2>
Ptr;
91 template <
typename... Args>
92 static Ptr MakeLogger(Args... args);
97 const std::string& get_filename()
const;
132 bool create(
const std::string& var_name,
133 int rows,
int cols = 1,
134 int buffer_size = -1);
142 template <
typename Derived>
143 bool add(
const std::string& var_name,
const Eigen::MatrixBase<Derived>& data);
145 template <
typename Scalar>
146 bool add(
const std::string& var_name,
const std::vector<Scalar>& data);
148 template <
typename Iterator>
150 bool add(
const std::string& var_name, Iterator begin, Iterator end);
152 bool add(
const std::string& var_name,
double data);
159 int flush_available_data();
184 bool flush_to_queue_all();
203 std::unique_ptr<MutexImpl> _vars_mutex;
206 std::unordered_map<std::string, VariableBuffer> _vars;
215 std::string _file_name;
218 std::unique_ptr<matlogger2::Backend> _backend;
227 template <
typename... Args>
233 template <
typename Derived>
236 VariableBuffer * vbuf = find_or_create(var_name, data.rows(), data.cols());
238 return vbuf && vbuf->
add_elem(data);
242 template<
typename Iterator>
245 static std::vector<double> tmp;
247 tmp.assign(begin, end);
249 return add(var_name, tmp);
254 template <
typename Scalar>
257 Eigen::Map<
const Eigen::Matrix<Scalar,-1,1>> map(data.data(), data.size());
258 return add(var_name, map);
Mode
Enum for specifying the type of buffer.
bool add_elem(const Eigen::MatrixBase< Derived > &data)
Add an element to the buffer.
std::weak_ptr< MatLogger2 > WeakPtr
static Ptr MakeLogger(Args...args)
Factory method that must be used to construct a MatLogger2 instance.
The MatLogger2 class allows the user to save numeric variables (scalars, vectors, matrices) to HDF5 M...
std::shared_ptr< MatLogger2 > Ptr
The VariableBuffer class implements a memory buffer for a single logged variable. ...
bool add(const std::string &var_name, const Eigen::MatrixBase< Derived > &data)
Add an element to an existing variable.
std::function< void(BufferInfo)> CallbackType