GUECS: Minimal components from zedcaster that will let me make a GUI for a game.

This commit is contained in:
Zed A. Shaw 2025-04-21 23:45:04 -04:00
parent 10ecf50bc0
commit 1be770d62d
28 changed files with 2528 additions and 30 deletions

35
dbc.cpp
View file

@ -1,40 +1,47 @@
#include "dbc.hpp"
#include <iostream>
void dbc::log(const string &message) {
fmt::print("{}\n", message);
void dbc::log(const string &message, const std::source_location location) {
std::cout << '[' << location.file_name() << ':'
<< location.line() << "|"
<< location.function_name() << "] "
<< message << std::endl;
}
void dbc::sentinel(const string &message) {
string err = fmt::format("[SENTINEL!] {}\n", message);
void dbc::sentinel(const string &message, const std::source_location location) {
string err = fmt::format("[SENTINEL!] {}", message);
dbc::log(err, location);
throw dbc::SentinelError{err};
}
void dbc::pre(const string &message, bool test) {
void dbc::pre(const string &message, bool test, const std::source_location location) {
if(!test) {
string err = fmt::format("[PRE!] {}\n", message);
string err = fmt::format("[PRE!] {}", message);
dbc::log(err, location);
throw dbc::PreCondError{err};
}
}
void dbc::pre(const string &message, std::function<bool()> tester) {
dbc::pre(message, tester());
void dbc::pre(const string &message, std::function<bool()> tester, const std::source_location location) {
dbc::pre(message, tester(), location);
}
void dbc::post(const string &message, bool test) {
void dbc::post(const string &message, bool test, const std::source_location location) {
if(!test) {
string err = fmt::format("[POST!] {}\n", message);
string err = fmt::format("[POST!] {}", message);
dbc::log(err, location);
throw dbc::PostCondError{err};
}
}
void dbc::post(const string &message, std::function<bool()> tester) {
dbc::post(message, tester());
void dbc::post(const string &message, std::function<bool()> tester, const std::source_location location) {
dbc::post(message, tester(), location);
}
void dbc::check(bool test, const string &message) {
void dbc::check(bool test, const string &message, const std::source_location location) {
if(!test) {
string err = fmt::format("[CHECK!] {}\n", message);
fmt::println("{}", err);
dbc::log(err, location);
throw dbc::CheckError{err};
}
}