14 #include <unordered_map>
33 static const uint8_t magic[4];
99 using LogEvent = std::variant<KeyAddedEvent, KeyRemovedEvent, GUIEvent, StartEvent>;
111 std::map<std::string, sva::PTransformd>
init;
113 std::map<std::string, std::vector<std::vector<double>>>
init_q;
115 std::map<std::string, std::map<std::string, mc_rtc::Configuration>>
calibs;
127 Logger(
const Policy & policy,
const std::string & directory,
const std::string & tmpl);
140 void setup(
const Policy & policy,
const std::string & directory,
const std::string & tmpl);
146 inline const Meta &
meta() const noexcept {
return meta_; }
162 void start(
const std::string & ctl_name,
double timestep,
bool resume =
false,
double start_t = 0.0);
175 void open(
const std::string & file,
double timestep,
double start_t = 0.0);
205 template<
typename CallbackT,
206 typename SourceT = void,
207 typename std::enable_if<mc_rtc::log::callback_is_serializable<CallbackT>::value,
int>::type = 0>
208 void addLogEntry(
const std::string & name,
const SourceT * source, CallbackT && get_fn,
bool overwrite =
false)
210 using ret_t = decltype(get_fn());
211 using base_t =
typename std::decay<ret_t>::type;
212 auto it = find_entry(name);
213 if(it != log_entries_.end())
217 log::error(
"Already logging an entry named {}", name);
220 else { log_entries_.erase(it); }
243 template<
typename MemberPtrT,
246 typename std::enable_if<mc_rtc::log::is_serializable_member<MemberPtrT>::value,
int>::type = 0>
247 void addLogEntry(
const std::string & name,
const SourceT * source,
bool overwrite =
false)
249 using MemberT = decltype(source->*member);
250 addLogEntry(name, source, [source]() ->
const MemberT & {
return source->*member; }, overwrite);
268 template<
typename MethodPtrT,
271 typename std::enable_if<mc_rtc::log::is_serializable_getter<MethodPtrT>::value,
int>::type = 0>
272 void addLogEntry(
const std::string & name,
const SourceT * source,
bool overwrite =
false)
274 using MethodRetT = decltype((source->*method)());
275 addLogEntry(name, source, [source]() -> MethodRetT {
return (source->*method)(); }, overwrite);
293 template<typename T, typename std::enable_if<mc_rtc::log::callback_is_serializable<T>::value,
int>::type = 0>
294 void addLogEntry(
const std::string & name, T && get_fn,
bool overwrite =
false)
296 addLogEntry(name,
static_cast<const void *
>(
nullptr), std::forward<T>(get_fn), overwrite);
311 template<
typename SourceT,
typename CallbackT,
typename... Args>
312 void addLogEntries(
const SourceT * source,
const std::string & name, CallbackT && get_fn, Args &&... args)
314 addLogEntry(name, source, get_fn);
315 addLogEntries(source, std::forward<Args>(args)...);
331 void removeLogEntry(
const std::string & name);
340 void removeLogEntries(
const void * source);
349 const std::string & path()
const;
355 inline size_t size()
const {
return log_entries_.size(); }
363 void clear(
bool record =
true);
379 std::shared_ptr<LoggerImpl> impl_ =
nullptr;
383 std::vector<LogEvent> log_events_;
385 std::vector<LogEntry> log_entries_;
387 std::vector<LogEntry>::iterator find_entry(
const std::string & name);
390 template<
typename SourceT>
391 void addLogEntries(
const SourceT *)
397 #define MC_RTC_LOG_HELPER(NAME, MEMBER) \
399 using ThisT = typename std::remove_pointer<decltype(this)>::type; \
400 logger.addLogEntry<decltype(&ThisT::MEMBER), &ThisT::MEMBER>(NAME, this); \
404 #define MC_RTC_LOG_GETTER(NAME, METHOD) \
406 using MethodRetT = decltype(this->METHOD()); \
407 logger.addLogEntry(NAME, this, [this]() -> MethodRetT { return METHOD(); }); \