Add async/resilience/reflection primitives + FSM v2 rewrite
A round of new universal capabilities (all generic — templated/reflection based, no app coupling), verified by the test suite (1103 passing): Data reflection: - Reflect.hpp now (de)serializes chrono::duration, chrono::time_point, std::variant (tagged), std::array, and non-string-keyed std::map; Meta.hpp gains is_time_point_v et al. Async: - EventBus gains Mode::Async (worker-thread dispatch + flush()). - ThreadPool gains a bounded queue, try_submit(), and rejection stats. New modules / containers: - Resilience: TokenBucket, KeyedRateLimiter<Key>, CircuitBreaker, ResourceMonitor. - Containers: BufferPool<T> (size-class buffer reuse) and Cache<K,V> (per-entry TTL, LRU/LFU/FIFO eviction, hit/miss stats). - System: process/CPU/memory metrics (Metrics.hpp) and a streaming Process API. Plus FSM v2 (typed Success/Failure, sub-machines, parallel regions, history states, deferred events), Configuration/Logging reflection helpers, and the accompanying test suites. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
43b5a81504
commit
80293ee56f
93 files changed
+8500
-3312
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Configuration/Config.hpp>
|
||||
#include <Void/Core/Meta.hpp>
|
||||
#include <Void/Functional/Error.hpp>
|
||||
#include <Void/Functional/Result.hpp>
|
||||
|
||||
@@ -39,31 +40,28 @@
|
||||
namespace Void::Configuration
|
||||
{
|
||||
|
||||
// ── field annotations ─────────────────────────────────────────────────
|
||||
// Annotate aggregate members to control binding:
|
||||
// struct Settings {
|
||||
// [[= Configuration::Key{"log_level"}]] std::string level = "info";
|
||||
// [[= Configuration::Required{}]] std::string host;
|
||||
// };
|
||||
struct Key {
|
||||
Void::Meta::Str name;
|
||||
};
|
||||
struct Required {
|
||||
};
|
||||
|
||||
#ifdef VOID_HAS_CONFIG_REFLECTION
|
||||
|
||||
namespace BindDetail
|
||||
{
|
||||
template <typename T> struct IsOptional : std::false_type {
|
||||
};
|
||||
template <typename U>
|
||||
struct IsOptional<std::optional<U>> : std::true_type {
|
||||
};
|
||||
|
||||
template <typename T> struct IsVector : std::false_type {
|
||||
};
|
||||
template <typename U> struct IsVector<std::vector<U>> : std::true_type {
|
||||
};
|
||||
|
||||
template <typename T> struct IsDuration : std::false_type {
|
||||
};
|
||||
template <typename Rep, typename Period>
|
||||
struct IsDuration<std::chrono::duration<Rep, Period>> : std::true_type {
|
||||
};
|
||||
|
||||
// Leaf / container shape detection comes from Void::Meta (single
|
||||
// source); Config additionally treats chrono durations as leaves.
|
||||
template <typename T>
|
||||
concept Leaf = std::is_same_v<T, std::string> ||
|
||||
std::is_same_v<T, bool> || std::is_arithmetic_v<T> ||
|
||||
std::is_enum_v<T> || IsDuration<T>::value;
|
||||
std::is_enum_v<T> || Void::Meta::is_duration_v<T>;
|
||||
|
||||
template <typename T>
|
||||
concept BindableAggregate =
|
||||
@@ -86,16 +84,20 @@ namespace Void::Configuration
|
||||
T out{};
|
||||
std::optional<Void::Result::Error> failure;
|
||||
|
||||
static constexpr auto members =
|
||||
std::define_static_array(std::meta::nonstatic_data_members_of(
|
||||
^^T, std::meta::access_context::current()));
|
||||
|
||||
template for (constexpr auto m : members)
|
||||
template for (constexpr auto m : Void::Meta::members_v<T>)
|
||||
{
|
||||
if (!failure) {
|
||||
constexpr auto name = std::meta::identifier_of(m);
|
||||
using MT = [:std::meta::type_of(m):];
|
||||
const auto key = join(prefix, name);
|
||||
// Key segment: a [[= Configuration::Key("…")]] override,
|
||||
// else the field identifier.
|
||||
constexpr auto ko = Void::Meta::annotation_of<Key>(m);
|
||||
const std::string seg =
|
||||
ko.has_value()
|
||||
? std::string{ko->name.view()}
|
||||
: std::string{std::meta::identifier_of(m)};
|
||||
const auto key = join(prefix, seg);
|
||||
[[maybe_unused]] constexpr bool required =
|
||||
Void::Meta::has_annotation<Required>(m);
|
||||
|
||||
if constexpr (BindableAggregate<MT> && !Leaf<MT>) {
|
||||
auto nested = bind_into<MT>(cfg, key);
|
||||
@@ -104,7 +106,7 @@ namespace Void::Configuration
|
||||
} else {
|
||||
out.[:m:] = std::move(*nested);
|
||||
}
|
||||
} else if constexpr (IsOptional<MT>::value) {
|
||||
} else if constexpr (Void::Meta::is_optional_v<MT>) {
|
||||
using U = typename MT::value_type;
|
||||
if (cfg.contains(key)) {
|
||||
auto v = cfg.get_as<U>(key);
|
||||
@@ -114,7 +116,7 @@ namespace Void::Configuration
|
||||
out.[:m:] = std::move(*v);
|
||||
}
|
||||
}
|
||||
} else if constexpr (IsVector<MT>::value) {
|
||||
} else if constexpr (Void::Meta::is_vector_v<MT>) {
|
||||
using U = typename MT::value_type;
|
||||
MT items;
|
||||
for (std::size_t i = 0;; ++i) {
|
||||
@@ -142,8 +144,11 @@ namespace Void::Configuration
|
||||
} else {
|
||||
out.[:m:] = std::move(*v);
|
||||
}
|
||||
} else if constexpr (required) {
|
||||
failure = Void::Result::Error{
|
||||
"missing required config key '" + key + "'"};
|
||||
}
|
||||
// absent key: keep the default member value
|
||||
// absent + not required: keep the default member value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user