First drop the game's core mechanic that compiles.

This commit is contained in:
Zed A. Shaw 2024-07-30 06:01:39 -04:00
commit 5f87d9846c
11 changed files with 607 additions and 0 deletions

49
dbc.h Normal file
View file

@ -0,0 +1,49 @@
#include <string>
#include <fmt/core.h>
using namespace std;
namespace dbc {
class Error {
public:
const string message;
Error(string m) : message{m} {}
Error(const char *m) : message{m} {}
};
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);
throw CheckError{err};
}
}
}