History< Writer, Loggers > Class Template Reference

CPP API: mio::History< Writer, Loggers > Class Template Reference
mio::History< Writer, Loggers > Class Template Reference

History class that handles writers and loggers. More...

#include <history.h>

Public Types

using WriteWrapper = Writer< Loggers... >
 

Public Member Functions

const WriteWrapper::Data & get_log () const
 Get the data object. More...
 
 History ()=default
 
 History (typename Loggers::Type... args)
 
 History (typename WriteWrapper::Data data)
 
template<class T >
void log (const T &t)
 Logs new records according to the Writer and Loggers. More...
 

Private Member Functions

template<class T , class Logger >
void log_impl (const T &t, Logger &logger)
 Checks if the given logger should log. More...
 

Private Attributes

WriteWrapper::Data m_data
 
std::tuple< Loggers... > m_loggers
 

Detailed Description

template<template< class... > class Writer, class... Loggers>
class mio::History< Writer, Loggers >

History class that handles writers and loggers.

History provides a function "log" to add a new record and a function "get_log" to access all records.

The History class uses Loggers to retrieve data from a given input, and a Writer to record this data. A Logger is a struct with a type Type and functions Type log(const T&) and bool should_log(const T&). All Loggers must be unique types and default construcible/destructible. Their member "should_log" indicates whether to log, while "Type" and "log" determine what is logged. The input for "should_log" and "log" is the same input of type T that is given to "History::log". (Note: T does not have to be a template for a Logger implementation.) The Writer defines the type Data to store all records (i.e. the return values of Logger::log), and the function template <class Logger> static void add_record(const Logger::Type&, Data&) to add a new record. "add_record" is used whenever "History::log" was called and "Logger::should_log" is true.

Template Parameters
WriterThe writer that is used to handle the data, e.g. store it into an array.
LoggersThe loggers that are used to log data.

Member Typedef Documentation

◆ WriteWrapper

template<template< class... > class Writer, class... Loggers>
using mio::History< Writer, Loggers >::WriteWrapper = Writer<Loggers...>

Constructor & Destructor Documentation

◆ History() [1/3]

template<template< class... > class Writer, class... Loggers>
mio::History< Writer, Loggers >::History ( )
default

◆ History() [2/3]

template<template< class... > class Writer, class... Loggers>
mio::History< Writer, Loggers >::History ( typename WriteWrapper::Data  data)
inline

◆ History() [3/3]

template<template< class... > class Writer, class... Loggers>
mio::History< Writer, Loggers >::History ( typename Loggers::Type...  args)
inline

Member Function Documentation

◆ get_log()

template<template< class... > class Writer, class... Loggers>
const WriteWrapper::Data& mio::History< Writer, Loggers >::get_log ( ) const
inline

Get the data object.

Returns
const WriteWrapper::Data&

◆ log()

template<template< class... > class Writer, class... Loggers>
template<class T >
void mio::History< Writer, Loggers >::log ( const T &  t)
inline

Logs new records according to the Writer and Loggers.

Calls the log_impl function for every Logger for Input t to record data.

Template Parameters
TThe type of the record.
Parameters
[in]tThe input to record.

◆ log_impl()

template<template< class... > class Writer, class... Loggers>
template<class T , class Logger >
void mio::History< Writer, Loggers >::log_impl ( const T &  t,
Logger &  logger 
)
inlineprivate

Checks if the given logger should log.

If so, adds a record of the log to m_data.

Parameters
[in]tThe argument given to History::log. Passed to Logger::should_log and Logger::log.
[in]loggerA Logger instance.
Template Parameters
LoggerA logger from the list Loggers.

Member Data Documentation

◆ m_data

template<template< class... > class Writer, class... Loggers>
WriteWrapper::Data mio::History< Writer, Loggers >::m_data
private

◆ m_loggers

template<template< class... > class Writer, class... Loggers>
std::tuple<Loggers...> mio::History< Writer, Loggers >::m_loggers
private