FlatLog.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <mc_rtc/log/Logger.h>
8 #include <mc_rtc/log/utils.h>
9 #include <mc_rtc/utils_api.h>
10 
11 #include <SpaceVecAlg/SpaceVecAlg>
12 
13 #include <stdexcept>
14 #include <string>
15 #include <unordered_map>
16 
17 namespace mc_rtc::log
18 {
19 
20 namespace details
21 {
22 
23 template<typename T>
25 {
26  using type = T;
27 };
28 
29 template<int N, int _Options, int _MaxRows, int _MaxCols>
30 struct GetRawReturnType<Eigen::Matrix<double, N, 1, _Options, _MaxRows, _MaxCols>>
31 {
32  using type = std::conditional_t<N == 2 || N == 3 || N == 6,
33  Eigen::Matrix<double, N, 1, _Options, _MaxRows, _MaxCols>,
34  Eigen::VectorXd>;
35 };
36 
37 } // namespace details
38 
41 {
42  template<typename T>
44 
46  FlatLog() = default;
47 
49  FlatLog(const std::string & fpath);
50 
51  FlatLog(const FlatLog &) = delete;
52  FlatLog & operator=(const FlatLog &) = delete;
53 
54  FlatLog(FlatLog &&) = default;
55  FlatLog & operator=(FlatLog &&) = default;
56 
58  void load(const std::string & fpath);
59 
61  void append(const std::string & fpath);
62 
64  size_t size() const;
65 
67  std::set<std::string> entries() const;
68 
70  bool has(const std::string & entry) const;
71 
73  std::set<LogType> types(const std::string & entry) const;
74 
76  LogType type(const std::string & entry) const;
77 
79  LogType type(const std::string & entry, size_t i) const;
80 
89  template<typename T>
90  std::vector<const get_raw_return_t<T> *> getRaw(const std::string & entry) const;
91 
103  template<typename T>
104  std::vector<get_raw_return_t<T>> get(const std::string & entry, const T & def) const;
105 
115  template<typename T>
116  std::vector<get_raw_return_t<T>> get(const std::string & entry) const;
117 
130  template<typename T>
131  get_raw_return_t<T> get(const std::string & entry, size_t i, const T & def) const;
132 
142  template<typename T>
143  const get_raw_return_t<T> * getRaw(const std::string & entry, size_t i) const;
144 
146  inline const std::vector<std::vector<Logger::GUIEvent>> & guiEvents() const noexcept { return gui_events_; }
147 
152  inline const std::optional<Logger::Meta> & meta() const noexcept { return meta_; }
153 
154  struct record
155  {
156  using unique_void_ptr = std::unique_ptr<void, void (*)(void const *)>;
158  record(LogType t, unique_void_ptr && d) : type(t), data(std::move(d)) {}
159  record(const record &) = delete;
160  record & operator=(const record &) = delete;
161  record(record &&) = default;
162  record & operator=(record &&) = default;
165  };
166  struct entry
167  {
168  std::string name;
169  std::vector<record> records;
170  };
171 
172 private:
173  std::vector<entry> data_;
174  std::vector<std::vector<Logger::GUIEvent>> gui_events_;
175  std::optional<Logger::Meta> meta_;
176 
178  const std::vector<record> & at(const std::string & entry) const;
179 
181  size_t index(const std::string & entry, size_t size);
182 
184  void appendFlat(const std::string & fpath);
185 
187  void appendBin(const std::string & fpath);
188 };
189 
190 } // namespace mc_rtc::log
191 
192 #include "FlatLog.hpp"
Definition: deprecated.h:16
LogType
Definition: utils.h:13
Definition: Contact.h:67
Definition: FlatLog.h:167
std::string name
Definition: FlatLog.h:168
std::vector< record > records
Definition: FlatLog.h:169
Definition: FlatLog.h:155
record & operator=(const record &)=delete
std::unique_ptr< void, void(*)(void const *)> unique_void_ptr
Definition: FlatLog.h:156
record(LogType t, unique_void_ptr &&d)
Definition: FlatLog.h:158
unique_void_ptr data
Definition: FlatLog.h:164
record(const record &)=delete
record & operator=(record &&)=default
record(record &&)=default
Definition: FlatLog.h:41
FlatLog(const std::string &fpath)
get_raw_return_t< T > get(const std::string &entry, size_t i, const T &def) const
FlatLog(FlatLog &&)=default
std::vector< get_raw_return_t< T > > get(const std::string &entry, const T &def) const
const get_raw_return_t< T > * getRaw(const std::string &entry, size_t i) const
FlatLog & operator=(const FlatLog &)=delete
void append(const std::string &fpath)
const std::optional< Logger::Meta > & meta() const noexcept
Definition: FlatLog.h:152
std::vector< const get_raw_return_t< T > * > getRaw(const std::string &entry) const
std::set< LogType > types(const std::string &entry) const
bool has(const std::string &entry) const
std::set< std::string > entries() const
LogType type(const std::string &entry, size_t i) const
FlatLog & operator=(FlatLog &&)=default
void load(const std::string &fpath)
std::vector< get_raw_return_t< T > > get(const std::string &entry) const
typename details::GetRawReturnType< T >::type get_raw_return_t
Definition: FlatLog.h:43
FlatLog(const FlatLog &)=delete
const std::vector< std::vector< Logger::GUIEvent > > & guiEvents() const noexcept
Definition: FlatLog.h:146
LogType type(const std::string &entry) const
size_t size() const
std::conditional_t< N==2||N==3||N==6, Eigen::Matrix< double, N, 1, _Options, _MaxRows, _MaxCols >, Eigen::VectorXd > type
Definition: FlatLog.h:34
T type
Definition: FlatLog.h:26
#define MC_RTC_UTILS_DLLAPI
Definition: utils_api.h:50