DBC now works and has a test.

This commit is contained in:
Zed A. Shaw 2024-09-16 09:20:35 -04:00
parent f632f2d5af
commit 2035a6dd00
8 changed files with 100 additions and 34 deletions

38
dbc.hpp
View file

@ -15,39 +15,15 @@ namespace dbc {
};
class CheckError : public Error {};
class SentinelError : public Error {};
class PreCondError : public Error {};
class PostCondError : public Error {};
void log(const string &message) {
fmt::print("{}\n", message);
}
void sentinel(const string &message) {
string err = fmt::format("[SENTINEL!] {}\n", message);
throw SentinelError{err};
}
void pre(const string &message, std::function<bool()> tester) {
if(!tester()) {
string err = fmt::format("[PRE!] {}\n", message);
throw PreCondError{err};
}
}
void post(const string &message, std::function<bool()> tester) {
if(!tester()) {
string err = fmt::format("[POST!] {}\n", message);
throw PostCondError{err};
}
}
void check(bool test, const string &message) {
if(!test) {
string err = fmt::format("[CHECK!] {}\n", message);
fmt::println("{}", err);
throw CheckError{err};
}
}
void log(const string &message);
void sentinel(const string &message);
void pre(const string &message, bool test);
void pre(const string &message, std::function<bool()> tester);
void post(const string &message, bool test);
void post(const string &message, std::function<bool()> tester);
void check(bool test, const string &message);
}