14 #include <type_traits>
18 namespace checkpoints {
20 template<
typename... Args>
21 using Tuple = std::tuple<std::decay_t<Args>...>;
22 using Checkpoint = std::tuple<std::string,bool,std::any>;
36 return std::get<0>(
cur());
39 return std::get<1>(
cur());
43 return std::any_cast<T>(std::get<2>(
cur()));
47 return std::any_cast<T>(&std::get<2>(
cur()));
56 template<
typename... Args>
70 template<
typename... Args>
72 using Channels = std::map<std::string, CheckpointVector>;
80 template<
typename... Args>
81 void push(
const std::string& channel,
const std::string& description,
bool forced, Args&&... args) {
82 mChannels[channel].add(description, forced, std::forward<Args>(args)...);
83 CARL_LOG_DEBUG(
"carl.checkpoint",
"Added " << (forced ?
"forced " :
"") << description <<
": " <<
Tuple<Args...>(args...) <<
" in " << channel);
86 template<
typename... Args>
87 bool check(
const std::string& channel,
const std::string& description, Args&&... args) {
93 if (
mChannels[channel].description() != description) {
94 CARL_LOG_ERROR(
"carl.checkpoint",
"Expected " <<
mChannels[channel].description() <<
" but got " << description <<
" in " << channel);
98 if (checkpoint ==
nullptr) {
103 bool res = *checkpoint ==
Tuple<Args...>(args...);
105 CARL_LOG_ERROR(
"carl.checkpoint",
"Expected " << *checkpoint <<
" -> " << std::boolalpha << res);
108 CARL_LOG_ERROR(
"carl.checkpoint",
"Expected " << *checkpoint <<
" -> " << std::boolalpha << res);
110 res = !
mChannels[channel].forced() || res;
114 template<
typename... Args>
115 void expect(
const std::string& channel,
const std::string& description, Args&&... args) {
118 CARL_LOG_ERROR(
"carl.checkpoint",
"***** Checkpoint for " << channel);
122 auto res =
check(channel, description, args...);
130 void clear(
const std::string& channel) {
A small wrapper that configures logging for carl.
#define CARL_LOG_WARN(channel, msg)
#define CARL_LOG_ERROR(channel, msg)
#define CARL_LOG_DEBUG(channel, msg)
carl is the main namespace for the library.
std::string demangle(const char *name)
const T * try_data() const
std::tuple< std::decay_t< Args >... > Tuple
const std::string & description() const
std::tuple< std::string, bool, std::any > Checkpoint
const Checkpoint & cur() const
void add(const std::string &description, bool forced, Args &&... args)
std::vector< Checkpoint > mData
bool & mayExceed(const std::string &channel)
CheckpointVector::Tuple< Args... > Tuple
void push(const std::string &channel, const std::string &description, bool forced, Args &&... args)
bool & printDebug(const std::string &channel)
std::map< std::string, CheckpointVector > Channels
bool check(const std::string &channel, const std::string &description, Args &&... args)
void clear(const std::string &channel)
void expect(const std::string &channel, const std::string &description, Args &&... args)
Base class that implements a singleton.
static VariablePool & getInstance()
Returns the single instance of this class by reference.