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 *)>;
157  record();
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"
mc_rtc::log::details::GetRawReturnType
Definition: FlatLog.h:24
mc_rtc::log::LogType::None
@ None
mc_rtc::log::FlatLog
Definition: FlatLog.h:40
mc_rtc::log::FlatLog::get_raw_return_t
typename details::GetRawReturnType< T >::type get_raw_return_t
Definition: FlatLog.h:43
mc_rtc::log::LogType
LogType
Definition: utils.h:12
mc_rtc::log::FlatLog::record::record
record(LogType t, unique_void_ptr &&d)
Definition: FlatLog.h:158
mc_rtc::log::details::GetRawReturnType::type
T type
Definition: FlatLog.h:26
mc_rtc::log::FlatLog::record::unique_void_ptr
std::unique_ptr< void, void(*)(void const *)> unique_void_ptr
Definition: FlatLog.h:156
mc_rtc::log::FlatLog::meta
const std::optional< Logger::Meta > & meta() const noexcept
Definition: FlatLog.h:152
Logger.h
mc_rtc::log::FlatLog::record
Definition: FlatLog.h:154
mc_rtc::log::FlatLog::guiEvents
const std::vector< std::vector< Logger::GUIEvent > > & guiEvents() const noexcept
Definition: FlatLog.h:146
mc_rtc::log::FlatLog::entry::name
std::string name
Definition: FlatLog.h:168
mc_rtc::log::FlatLog::entry
Definition: FlatLog.h:166
mc_rtc::log::details::GetRawReturnType< Eigen::Matrix< double, N, 1, _Options, _MaxRows, _MaxCols > >::type
std::conditional_t< N==2||N==3||N==6, Eigen::Matrix< double, N, 1, _Options, _MaxRows, _MaxCols >, Eigen::VectorXd > type
Definition: FlatLog.h:34
utils.h
mc_rtc::log::FlatLog::entry::records
std::vector< record > records
Definition: FlatLog.h:169
MC_RTC_UTILS_DLLAPI
#define MC_RTC_UTILS_DLLAPI
Definition: utils_api.h:50
utils_api.h
mc_rtc::log
Definition: deprecated.h:15
mc_rtc::log::FlatLog::record::data
unique_void_ptr data
Definition: FlatLog.h:164
std
Definition: Contact.h:66