From 4ab0837c4d5ad07949388ed55b58e3a367c571e7 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 8 Jan 2026 18:42:51 -0500 Subject: [PATCH] xo-arena: reorg: move verify_policy to dedicated file --- include/xo/arena/DArenaHashMap.hpp | 38 +------------- include/xo/arena/hashmap/verify_policy.hpp | 59 ++++++++++++++++++++++ 2 files changed, 60 insertions(+), 37 deletions(-) create mode 100644 include/xo/arena/hashmap/verify_policy.hpp diff --git a/include/xo/arena/DArenaHashMap.hpp b/include/xo/arena/DArenaHashMap.hpp index c20695e..77689f2 100644 --- a/include/xo/arena/DArenaHashMap.hpp +++ b/include/xo/arena/DArenaHashMap.hpp @@ -6,6 +6,7 @@ #pragma once #include "DArenaVector.hpp" +#include "hashmap/verify_policy.hpp" #include "hashmap/DArenaHashMapUtil.hpp" #include "hashmap/ControlGroup.hpp" #include @@ -15,43 +16,6 @@ #include 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 - bool report_error(scope & log, Tn&&... args) - { - if (!this->is_silent()) { - // TODO: consider global arena here for string - std::string msg = tostr(std::forward(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 { diff --git a/include/xo/arena/hashmap/verify_policy.hpp b/include/xo/arena/hashmap/verify_policy.hpp new file mode 100644 index 0000000..4d0d32a --- /dev/null +++ b/include/xo/arena/hashmap/verify_policy.hpp @@ -0,0 +1,59 @@ +/** @file verify_policy.hpp +* + * @author Roland Conybeare, Jan 2026 + **/ + +#pragma once + +#include +#include + +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 + bool report_error(scope & log, Tn&&... args) + { + if (!this->is_silent()) { + // TODO: consider global arena here for string + std::string msg = tostr(std::forward(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 */