iterate_binary_log.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4  * Copyright 2019-2023 CNRS-UM LIRMM, CNRS-AIST JRL
5  */
6 
8 #include <mc_rtc/log/FlatLog.h>
9 
10 namespace mc_rtc::log
11 {
12 
13 using copy_callback = std::function<void(mc_rtc::MessagePackBuilder &, const std::vector<std::string> &)>;
14 
17 {
19  const std::vector<std::string> & keys;
21  std::vector<FlatLog::record> & records;
23  std::vector<Logger::GUIEvent> & gui_events;
25  std::optional<double> time;
29  const char * raw_data;
31  size_t raw_data_size;
33  const std::optional<Logger::Meta> & meta;
34 };
35 
37 
38 using binary_log_callback =
39  std::function<bool(const std::vector<std::string> &, std::vector<FlatLog::record> &, double)>;
40 
41 using binary_log_copy_callback = std::function<bool(const std::vector<std::string> &,
42  std::vector<FlatLog::record> &,
43  double,
44  const copy_callback &,
45  const char *,
46  uint64_t)>;
47 
57 bool MC_RTC_UTILS_DLLAPI iterate_binary_log(const std::string & fpath,
58  const iterate_binary_log_callback & callback,
59  bool extract,
60  const std::string & time = "t");
61 
63 inline bool iterate_binary_log(const std::string & fpath,
64  const binary_log_copy_callback & callback,
65  bool extract,
66  const std::string & time = "t")
67 {
68  return iterate_binary_log(
69  fpath,
70  [&callback](IterateBinaryLogData data) {
71  return callback(data.keys, data.records, data.time.value_or(-1), data.copy_cb, data.raw_data,
72  data.raw_data_size);
73  },
74  extract, time);
75 }
76 
78 inline bool iterate_binary_log(const std::string & fpath,
79  const binary_log_callback & callback,
80  bool extract,
81  const std::string & time = "t")
82 {
83  return iterate_binary_log(
84  fpath, [&callback](IterateBinaryLogData data)
85  { return callback(data.keys, data.records, data.time.value_or(-1)); }, extract, time);
86 }
87 
88 } // namespace mc_rtc::log
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
mc_rtc::log::IterateBinaryLogData
Definition: iterate_binary_log.h:16
mc_rtc::log::IterateBinaryLogData::raw_data_size
size_t raw_data_size
Definition: iterate_binary_log.h:31
mc_rtc::log::iterate_binary_log_callback
std::function< bool(IterateBinaryLogData)> iterate_binary_log_callback
Definition: iterate_binary_log.h:36
mc_rtc::log::IterateBinaryLogData::time
std::optional< double > time
Definition: iterate_binary_log.h:25
mc_rtc::log::copy_callback
std::function< void(mc_rtc::MessagePackBuilder &, const std::vector< std::string > &)> copy_callback
Definition: iterate_binary_log.h:13
FlatLog.h
MessagePackBuilder.h
mc_rtc::log::IterateBinaryLogData::raw_data
const char * raw_data
Definition: iterate_binary_log.h:29
mc_rtc::log::IterateBinaryLogData::keys
const std::vector< std::string > & keys
Definition: iterate_binary_log.h:19
MC_RTC_UTILS_DLLAPI
#define MC_RTC_UTILS_DLLAPI
Definition: utils_api.h:50
mc_rtc::log::IterateBinaryLogData::records
std::vector< FlatLog::record > & records
Definition: iterate_binary_log.h:21
mc_rtc::log::IterateBinaryLogData::copy_cb
const copy_callback & copy_cb
Definition: iterate_binary_log.h:27
mc_rtc::log
Definition: deprecated.h:15
mc_rtc::log::binary_log_callback
std::function< bool(const std::vector< std::string > &, std::vector< FlatLog::record > &, double)> binary_log_callback
Definition: iterate_binary_log.h:39
mc_rtc::log::IterateBinaryLogData::meta
const std::optional< Logger::Meta > & meta
Definition: iterate_binary_log.h:33
mc_rtc::log::IterateBinaryLogData::gui_events
std::vector< Logger::GUIEvent > & gui_events
Definition: iterate_binary_log.h:23
mc_rtc::log::binary_log_copy_callback
std::function< bool(const std::vector< std::string > &, std::vector< FlatLog::record > &, double, const copy_callback &, const char *, uint64_t)> binary_log_copy_callback
Definition: iterate_binary_log.h:46
mc_rtc::log::iterate_binary_log
bool MC_RTC_UTILS_DLLAPI iterate_binary_log(const std::string &fpath, const iterate_binary_log_callback &callback, bool extract, const std::string &time="t")