dinkyecs_sandbox/dbc.cpp

55 lines
1.1 KiB
C++
Raw Normal View History

2025-02-13 18:59:40 +03:00
#include "dbc.hpp"
#include <iostream>
2025-02-13 19:47:52 +03:00
void dbc::log(const string &message)
{
std::cerr << "!!!!!!!!!!" << message << std::endl;
2025-02-13 18:59:40 +03:00
}
2025-02-13 19:47:52 +03:00
void dbc::sentinel(const string &message)
{
string err = fmt::format("[SENTINEL!] {}", message);
dbc::log(err);
throw dbc::SentinelError{err};
2025-02-13 18:59:40 +03:00
}
2025-02-13 19:47:52 +03:00
void dbc::pre(const string &message, bool test)
{
if (!test)
{
string err = fmt::format("[PRE!] {}", message);
dbc::log(err);
throw dbc::PreCondError{err};
}
2025-02-13 18:59:40 +03:00
}
2025-02-13 19:47:52 +03:00
void dbc::pre(const string &message, std::function<bool()> tester)
{
dbc::pre(message, tester());
2025-02-13 18:59:40 +03:00
}
2025-02-13 19:47:52 +03:00
void dbc::post(const string &message, bool test)
{
if (!test)
{
string err = fmt::format("[POST!] {}", message);
dbc::log(err);
throw dbc::PostCondError{err};
}
2025-02-13 18:59:40 +03:00
}
2025-02-13 19:47:52 +03:00
void dbc::post(const string &message, std::function<bool()> tester)
{
dbc::post(message, tester());
2025-02-13 18:59:40 +03:00
}
2025-02-13 19:47:52 +03:00
void dbc::check(bool test, const string &message)
{
if (!test)
{
string err = fmt::format("[CHECK!] {}\n", message);
dbc::log(err);
throw dbc::CheckError{err};
}
}