Initial commit that has most of what I need.

This commit is contained in:
Zed A. Shaw 2024-09-24 18:28:01 -04:00
parent 933f47a440
commit ad143dca05
11 changed files with 317 additions and 0 deletions

40
dbc.cpp Normal file
View file

@ -0,0 +1,40 @@
#include "dbc.hpp"
void dbc::log(const string &message) {
fmt::print("{}\n", message);
}
void dbc::sentinel(const string &message) {
string err = fmt::format("[SENTINEL!] {}\n", message);
throw dbc::SentinelError{err};
}
void dbc::pre(const string &message, bool test) {
if(!test) {
string err = fmt::format("[PRE!] {}\n", message);
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!] {}\n", message);
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);
fmt::println("{}", err);
throw dbc::CheckError{err};
}
}