xo-arena: reorg: move verify_policy to dedicated file
This commit is contained in:
parent
fd74dbf5dd
commit
cf5a8e9614
2 changed files with 60 additions and 37 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "DArenaVector.hpp"
|
||||
#include "hashmap/verify_policy.hpp"
|
||||
#include "hashmap/DArenaHashMapUtil.hpp"
|
||||
#include "hashmap/ControlGroup.hpp"
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
|
@ -15,43 +16,6 @@
|
|||
#include <cstring>
|
||||
|
||||
namespace xo {
|
||||
struct verify_policy {
|
||||
static verify_policy log_only() {
|
||||
return verify_policy{.flags_ = 0x01};
|
||||
}
|
||||
static verify_policy throw_only() {
|
||||
return verify_policy{.flags_ = 0x02};
|
||||
}
|
||||
static verify_policy chatty() {
|
||||
return verify_policy{.flags_ = 0x03};
|
||||
}
|
||||
|
||||
bool is_silent() const noexcept { return flags_ == 0; }
|
||||
bool log_flag() const noexcept { return flags_ & 0x01; }
|
||||
bool throw_flag() const noexcept { return flags_ & 0x02; }
|
||||
|
||||
template<typename... Tn>
|
||||
bool report_error(scope & log, Tn&&... args)
|
||||
{
|
||||
if (!this->is_silent()) {
|
||||
// TODO: consider global arena here for string
|
||||
std::string msg = tostr(std::forward<Tn>(args)...);
|
||||
|
||||
if (this->log_flag()) {
|
||||
log.retroactively_enable();
|
||||
log(msg);
|
||||
}
|
||||
if (this->throw_flag()) {
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * c_self_ = "anonymous";
|
||||
uint8_t flags_;
|
||||
};
|
||||
|
||||
namespace mm {
|
||||
#ifdef NOT_YET
|
||||
enum class insert_error : int32_t {
|
||||
|
|
|
|||
59
xo-arena/include/xo/arena/hashmap/verify_policy.hpp
Normal file
59
xo-arena/include/xo/arena/hashmap/verify_policy.hpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/** @file verify_policy.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace xo {
|
||||
// TODO: move xo/indentlog
|
||||
|
||||
/** @brief policy for verify_ok behavior.
|
||||
*
|
||||
* Remarke: wrote this for DArenaHashMap,
|
||||
* want to incorporate into other subsystems
|
||||
* that provide a verify_ok() method.
|
||||
* e.g. RedBlackTree
|
||||
**/
|
||||
struct verify_policy {
|
||||
static verify_policy log_only() {
|
||||
return verify_policy{.flags_ = 0x01};
|
||||
}
|
||||
static verify_policy throw_only() {
|
||||
return verify_policy{.flags_ = 0x02};
|
||||
}
|
||||
static verify_policy chatty() {
|
||||
return verify_policy{.flags_ = 0x03};
|
||||
}
|
||||
|
||||
bool is_silent() const noexcept { return flags_ == 0; }
|
||||
bool log_flag() const noexcept { return flags_ & 0x01; }
|
||||
bool throw_flag() const noexcept { return flags_ & 0x02; }
|
||||
|
||||
template<typename... Tn>
|
||||
bool report_error(scope & log, Tn&&... args)
|
||||
{
|
||||
if (!this->is_silent()) {
|
||||
// TODO: consider global arena here for string
|
||||
std::string msg = tostr(std::forward<Tn>(args)...);
|
||||
|
||||
if (this->log_flag()) {
|
||||
log.retroactively_enable();
|
||||
log(msg);
|
||||
}
|
||||
if (this->throw_flag()) {
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * c_self_ = "anonymous";
|
||||
uint8_t flags_;
|
||||
};
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end verify_policy.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue