std::string_view rather than std::string reads a bit better for this use.

This commit is contained in:
Adrian Conlon 2022-01-21 22:49:22 +00:00
parent 8e0092ec9d
commit 1796d62517
2 changed files with 9 additions and 9 deletions

View File

@ -48,7 +48,7 @@ void checker_t::dumpCycle(const cycle_t cycle) {
dumpCycle(cycle.address(), cycle.value(), cycle.action());
}
void checker_t::raise(const std::string what, const uint16_t expected, const uint16_t actual) {
void checker_t::raise(std::string_view what, const uint16_t expected, const uint16_t actual) {
os()
<< std::setw(2) << std::setfill(' ')
<< what
@ -58,7 +58,7 @@ void checker_t::raise(const std::string what, const uint16_t expected, const uin
pushCurrentMessage();
}
void checker_t::raise(const std::string what, const uint8_t expected, const uint8_t actual) {
void checker_t::raise(std::string_view what, const uint8_t expected, const uint8_t actual) {
os()
<< std::setw(2) << std::setfill(' ')
<< what
@ -70,7 +70,7 @@ void checker_t::raise(const std::string what, const uint8_t expected, const uint
pushCurrentMessage();
}
void checker_t::raise(const std::string what, const std::string_view expected, const std::string_view actual) {
void checker_t::raise(std::string_view what, const std::string_view expected, const std::string_view actual) {
os()
<< std::setw(0) << std::setfill(' ')
<< what
@ -79,7 +79,7 @@ void checker_t::raise(const std::string what, const std::string_view expected, c
pushCurrentMessage();
}
bool checker_t::check(const std::string what, const uint16_t address, const uint8_t expected, const uint8_t actual) {
bool checker_t::check(std::string_view what, const uint16_t address, const uint8_t expected, const uint8_t actual) {
const auto success = actual == expected;
if (!success) {
os() << what << ": " << std::setw(4) << std::setfill('0') << (int)address;

View File

@ -42,19 +42,19 @@ private:
void pushCurrentMessage();
void raise(std::string what, uint16_t expected, uint16_t actual);
void raise(std::string what, uint8_t expected, uint8_t actual);
void raise(std::string what, std::string_view expected, std::string_view actual);
void raise(std::string_view what, uint16_t expected, uint16_t actual);
void raise(std::string_view what, uint8_t expected, uint8_t actual);
void raise(std::string_view what, std::string_view expected, std::string_view actual);
template<class T>
bool check(std::string what, T expected, T actual) {
bool check(std::string_view what, T expected, T actual) {
const auto success = actual == expected;
if (!success)
raise(what, expected, actual);
return success;
}
bool check(std::string what, uint16_t address, uint8_t expected, uint8_t actual);
bool check(std::string_view what, uint16_t address, uint8_t expected, uint8_t actual);
void addActualCycle(uint16_t address, uint8_t value, std::string action);
void addActualCycle(EightBit::register16_t address, uint8_t value, std::string action);