Brought line numbers back for the dbc.cpp logging stuff. May not work in clang because of the bug they have (had?).
parent
0efb17371b
commit
5ed8196c80
@ -1,44 +1,47 @@ |
|||||||
#include "dbc.hpp" |
#include "dbc.hpp" |
||||||
#include <iostream> |
#include <iostream> |
||||||
|
|
||||||
void dbc::log(const string &message) { |
void dbc::log(const string &message, const std::source_location location) { |
||||||
std::cerr << "!!!!!!!!!!" << message << std::endl; |
std::clog << '[' << location.file_name() << ':' |
||||||
|
<< location.line() << "|" |
||||||
|
<< location.function_name() << "] " |
||||||
|
<< message << std::endl; |
||||||
} |
} |
||||||
|
|
||||||
void dbc::sentinel(const string &message) { |
void dbc::sentinel(const string &message, const std::source_location location) { |
||||||
string err = fmt::format("[SENTINEL!] {}", message); |
string err = fmt::format("[SENTINEL!] {}", message); |
||||||
dbc::log(err); |
dbc::log(err, location); |
||||||
throw dbc::SentinelError{err}; |
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) { |
if(!test) { |
||||||
string err = fmt::format("[PRE!] {}", message); |
string err = fmt::format("[PRE!] {}", message); |
||||||
dbc::log(err); |
dbc::log(err, location); |
||||||
throw dbc::PreCondError{err}; |
throw dbc::PreCondError{err}; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
void dbc::pre(const string &message, std::function<bool()> tester) { |
void dbc::pre(const string &message, std::function<bool()> tester, const std::source_location location) { |
||||||
dbc::pre(message, tester()); |
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) { |
if(!test) { |
||||||
string err = fmt::format("[POST!] {}", message); |
string err = fmt::format("[POST!] {}", message); |
||||||
dbc::log(err); |
dbc::log(err, location); |
||||||
throw dbc::PostCondError{err}; |
throw dbc::PostCondError{err}; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
void dbc::post(const string &message, std::function<bool()> tester) { |
void dbc::post(const string &message, std::function<bool()> tester, const std::source_location location) { |
||||||
dbc::post(message, tester()); |
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) { |
if(!test) { |
||||||
string err = fmt::format("[CHECK!] {}\n", message); |
string err = fmt::format("[CHECK!] {}\n", message); |
||||||
dbc::log(err); |
dbc::log(err, location); |
||||||
throw dbc::CheckError{err}; |
throw dbc::CheckError{err}; |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue