Add dbc.cpp
This commit is contained in:
parent
d91f403d99
commit
acd5fd453f
1 changed files with 44 additions and 0 deletions
44
dbc.cpp
Normal file
44
dbc.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "dbc.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void dbc::log(const string &message) {
|
||||
std::cerr << "!!!!!!!!!!" << message << std::endl;
|
||||
}
|
||||
|
||||
void dbc::sentinel(const string &message) {
|
||||
string err = fmt::format("[SENTINEL!] {}", message);
|
||||
dbc::log(err);
|
||||
throw dbc::SentinelError{err};
|
||||
}
|
||||
|
||||
void dbc::pre(const string &message, bool test) {
|
||||
if(!test) {
|
||||
string err = fmt::format("[PRE!] {}", message);
|
||||
dbc::log(err);
|
||||
throw dbc::PreCondError{err};
|
||||
}
|
||||
}
|
||||
|
||||
void dbc::pre(const string &message, std::function<bool()> tester) {
|
||||
dbc::pre(message, tester());
|
||||
}
|
||||
|
||||
void dbc::post(const string &message, bool test) {
|
||||
if(!test) {
|
||||
string err = fmt::format("[POST!] {}", message);
|
||||
dbc::log(err);
|
||||
throw dbc::PostCondError{err};
|
||||
}
|
||||
}
|
||||
|
||||
void dbc::post(const string &message, std::function<bool()> tester) {
|
||||
dbc::post(message, tester());
|
||||
}
|
||||
|
||||
void dbc::check(bool test, const string &message) {
|
||||
if(!test) {
|
||||
string err = fmt::format("[CHECK!] {}\n", message);
|
||||
dbc::log(err);
|
||||
throw dbc::CheckError{err};
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue