The next little game in the series where I make a fancy rogue game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
roguish/dbc.cpp

45 lines
1013 B

#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};
}
}