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:
faumarayandClaude Opus 4.8 committed 2026-06-22 15:45:16 +03:00
1 parent 43b5a81504
commit 80293ee56f
93 files changed
+8500 -3312

No files matched your search

+121 -124
View File
@@ -1,138 +1,135 @@
#include <Void/Core/Bits.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <Void/Testing/Suite.hpp>
#include <cstdint>
// ── popcount ──────────────────────────────────────────────────────────────────
Void::Testing::Test popcount_zero()
namespace
{
Void::Testing::expect_eq(Void::Bits::popcount(0u), 0);
}
using Void::Testing::Test;
Void::Testing::Test popcount_all_ones_u8()
{
Void::Testing::expect_eq(Void::Bits::popcount(std::uint8_t{0xFF}), 8);
}
struct Bits : Void::Testing::Suite<Bits> {
// ── popcount ──────────────────────────────────────────────
Test popcount_zero()
{
Void::Testing::expect_eq(Void::Bits::popcount(0u), 0);
}
Test popcount_all_ones_u8()
{
Void::Testing::expect_eq(
Void::Bits::popcount(std::uint8_t{0xFF}), 8);
}
Test popcount_u32()
{
Void::Testing::expect_eq(
Void::Bits::popcount(std::uint32_t{0x0F0F0F0F}), 16);
}
Void::Testing::Test popcount_u32()
{
Void::Testing::expect_eq(Void::Bits::popcount(std::uint32_t{0x0F0F0F0F}), 16);
}
// ── test/set/clear/toggle ─────────────────────────────────
Test test_bit_set()
{
Void::Testing::expect(
Void::Bits::test_bit(std::uint8_t{0b00000100u}, 2));
}
Test test_bit_clear()
{
Void::Testing::expect(
!Void::Bits::test_bit(std::uint8_t{0b00000100u}, 0));
}
Test set_bit_works()
{
Void::Testing::expect_eq(
Void::Bits::set_bit(std::uint8_t{0u}, 3),
std::uint8_t{0b00001000u});
}
Test clear_bit_works()
{
Void::Testing::expect_eq(
Void::Bits::clear_bit(std::uint8_t{0xFF}, 3),
std::uint8_t{0b11110111u});
}
Test toggle_bit_works()
{
Void::Testing::expect_eq(
Void::Bits::toggle_bit(std::uint8_t{0u}, 5),
std::uint8_t{0b00100000u});
}
// ── test/set/clear/toggle ────────────────────────────────────────────────────
// ── extract / deposit ─────────────────────────────────────
Test extract_bits_works()
{
Void::Testing::expect_eq(
Void::Bits::extract_bits(std::uint8_t{0b10110100u}, 4, 4),
std::uint8_t{0b1011u});
}
Test deposit_bits_works()
{
Void::Testing::expect_eq(
Void::Bits::deposit_bits(std::uint8_t{0u},
std::uint8_t{0b1010u}, 4, 4),
std::uint8_t{0b10100000u});
}
Void::Testing::Test test_bit_set()
{
Void::Testing::expect(Void::Bits::test_bit(std::uint8_t{0b00000100u}, 2));
}
// ── rotation ──────────────────────────────────────────────
Test rotl_8()
{
Void::Testing::expect_eq(
Void::Bits::rotl(std::uint8_t{0b10000001u}, 1),
std::uint8_t{0b00000011u});
}
Test rotr_8()
{
Void::Testing::expect_eq(
Void::Bits::rotr(std::uint8_t{0b10000001u}, 1),
std::uint8_t{0b11000000u});
}
Void::Testing::Test test_bit_clear()
{
Void::Testing::expect(!Void::Bits::test_bit(std::uint8_t{0b00000100u}, 0));
}
// ── pow2 helpers ──────────────────────────────────────────
Test has_single_bit()
{
Void::Testing::expect(Void::Bits::has_single_bit(64u));
Void::Testing::expect(!Void::Bits::has_single_bit(63u));
}
Test ceil_pow2_works()
{
Void::Testing::expect_eq(Void::Bits::ceil_pow2(5u), 8u);
Void::Testing::expect_eq(Void::Bits::ceil_pow2(8u), 8u);
}
Test floor_pow2_works()
{
Void::Testing::expect_eq(Void::Bits::floor_pow2(5u), 4u);
}
Void::Testing::Test set_bit_works()
{
Void::Testing::expect_eq(Void::Bits::set_bit(std::uint8_t{0u}, 3),
std::uint8_t{0b00001000u});
}
// ── align ─────────────────────────────────────────────────
Test align_up_works()
{
Void::Testing::expect_eq(Void::Bits::align_up(13u, 8u), 16u);
Void::Testing::expect_eq(Void::Bits::align_up(8u, 8u), 8u);
}
Test align_down_works()
{
Void::Testing::expect_eq(Void::Bits::align_down(13u, 8u), 8u);
}
Void::Testing::Test clear_bit_works()
{
Void::Testing::expect_eq(Void::Bits::clear_bit(std::uint8_t{0xFF}, 3),
std::uint8_t{0b11110111u});
}
// ── masks ─────────────────────────────────────────────────
Test low_mask_works()
{
Void::Testing::expect_eq(Void::Bits::low_mask<std::uint8_t>(4),
std::uint8_t{0x0F});
}
Test range_mask_works()
{
Void::Testing::expect_eq(
Void::Bits::range_mask<std::uint8_t>(2, 5),
std::uint8_t{0b00111100u});
}
Void::Testing::Test toggle_bit_works()
{
Void::Testing::expect_eq(Void::Bits::toggle_bit(std::uint8_t{0u}, 5),
std::uint8_t{0b00100000u});
}
// ── extract / deposit ─────────────────────────────────────────────────────────
Void::Testing::Test extract_bits_works()
{
// bits 4-7 of 0b10110100 = 0b1011
Void::Testing::expect_eq(
Void::Bits::extract_bits(std::uint8_t{0b10110100u}, 4, 4),
std::uint8_t{0b1011u});
}
Void::Testing::Test deposit_bits_works()
{
// deposit 0b1010 into bits 4-7 of 0x00
Void::Testing::expect_eq(
Void::Bits::deposit_bits(std::uint8_t{0u}, std::uint8_t{0b1010u}, 4, 4),
std::uint8_t{0b10100000u});
}
// ── rotation ─────────────────────────────────────────────────────────────────
Void::Testing::Test rotl_8()
{
Void::Testing::expect_eq(Void::Bits::rotl(std::uint8_t{0b10000001u}, 1),
std::uint8_t{0b00000011u});
}
Void::Testing::Test rotr_8()
{
Void::Testing::expect_eq(Void::Bits::rotr(std::uint8_t{0b10000001u}, 1),
std::uint8_t{0b11000000u});
}
// ── pow2 helpers ──────────────────────────────────────────────────────────────
Void::Testing::Test has_single_bit()
{
Void::Testing::expect(Void::Bits::has_single_bit(64u));
Void::Testing::expect(!Void::Bits::has_single_bit(63u));
}
Void::Testing::Test ceil_pow2_works()
{
Void::Testing::expect_eq(Void::Bits::ceil_pow2(5u), 8u);
Void::Testing::expect_eq(Void::Bits::ceil_pow2(8u), 8u);
}
Void::Testing::Test floor_pow2_works()
{
Void::Testing::expect_eq(Void::Bits::floor_pow2(5u), 4u);
}
// ── align ────────────────────────────────────────────────────────────────────
Void::Testing::Test align_up_works()
{
Void::Testing::expect_eq(Void::Bits::align_up(13u, 8u), 16u);
Void::Testing::expect_eq(Void::Bits::align_up(8u, 8u), 8u);
}
Void::Testing::Test align_down_works()
{
Void::Testing::expect_eq(Void::Bits::align_down(13u, 8u), 8u);
}
// ── masks ────────────────────────────────────────────────────────────────────
Void::Testing::Test low_mask_works()
{
Void::Testing::expect_eq(Void::Bits::low_mask<std::uint8_t>(4),
std::uint8_t{0x0F});
}
Void::Testing::Test range_mask_works()
{
Void::Testing::expect_eq(Void::Bits::range_mask<std::uint8_t>(2, 5),
std::uint8_t{0b00111100u});
}
// ── byteswap / endian ────────────────────────────────────────────────────────
Void::Testing::Test byteswap_u32()
{
Void::Testing::expect_eq(Void::Bits::byteswap(std::uint32_t{0x12345678u}),
std::uint32_t{0x78563412u});
}
// ── byteswap / endian ─────────────────────────────────────
Test byteswap_u32()
{
Void::Testing::expect_eq(
Void::Bits::byteswap(std::uint32_t{0x12345678u}),
std::uint32_t{0x78563412u});
}
};
} // namespace
+32
View File
@@ -0,0 +1,32 @@
#include <Void/Core/Flags.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
namespace
{
enum class Perm : unsigned { Read = 1, Write = 2, Exec = 4 };
} // namespace
// @tag reflection
Void::Testing::Test flags_to_string_lists_set_names()
{
const auto f = Void::Flags::Flags<Perm>{Perm::Read} | Perm::Exec;
Void::Testing::expect_eq(Void::Flags::to_string(f),
std::string{"Read|Exec"});
Void::Testing::expect_eq(Void::Flags::to_string(Void::Flags::Flags<Perm>{}),
std::string{});
}
// @tag reflection
Void::Testing::Test flags_parse_names()
{
const auto f = Void::Flags::parse<Perm>("Read|Write");
Void::Testing::expect(f.test(Perm::Read));
Void::Testing::expect(f.test(Perm::Write));
Void::Testing::expect(!f.test(Perm::Exec));
// unknown names ignored
const auto g = Void::Flags::parse<Perm>("Exec|Nope");
Void::Testing::expect(g.test(Perm::Exec) && !g.test(Perm::Read));
}
+98
View File
@@ -0,0 +1,98 @@
#include <Void/Core/Meta.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <string>
namespace M = Void::Meta;
namespace
{
struct Point {
int x = 1;
int y = 2;
};
struct Nest {
Point p;
std::string tag = "z";
};
enum class Color { Red, Green, Blue };
} // namespace
Void::Testing::Test meta_field_walk()
{
Void::Testing::expect_eq(M::field_count<Point>(), std::size_t{2});
const auto names = M::field_names<Point>();
Void::Testing::expect_eq(names.size(), std::size_t{2});
Void::Testing::expect(names[0] == "x" && names[1] == "y");
Point p{3, 4};
int sum = 0;
M::for_each_field(p, [&](std::string_view, auto& f) { sum += f; });
Void::Testing::expect_eq(sum, 7);
// mutate through for_each_field
M::for_each_field(p, [](std::string_view, auto& f) { f += 1; });
Void::Testing::expect(p.x == 4 && p.y == 5);
}
Void::Testing::Test meta_equal_compare_hash()
{
Point a{3, 4};
Point b{3, 4};
Point c{3, 5};
Void::Testing::expect(M::equal(a, b));
Void::Testing::expect(!M::equal(a, c));
Void::Testing::expect(M::compare(a, c) == std::strong_ordering::less);
Void::Testing::expect(M::compare(a, b) == std::strong_ordering::equal);
Void::Testing::expect_eq(M::hash(a), M::hash(b));
Void::Testing::expect(M::hash(a) != M::hash(c));
}
Void::Testing::Test meta_repr_nested()
{
Point p{5, 6};
Void::Testing::expect_eq(M::repr(p), std::string{"Point{x: 5, y: 6}"});
Nest n{Point{1, 2}, "hi"};
Void::Testing::expect_eq(
M::repr(n), std::string{"Nest{p: Point{x: 1, y: 2}, tag: hi}"});
}
Void::Testing::Test meta_enum_utilities()
{
Void::Testing::expect_eq(M::enum_count<Color>, std::size_t{3});
constexpr auto vals = M::enum_values<Color>();
Void::Testing::expect(vals[0] == Color::Red && vals[2] == Color::Blue);
const auto entries = M::enum_entries<Color>();
Void::Testing::expect(entries[1].first == Color::Green &&
entries[1].second == "Green");
Void::Testing::expect(M::enum_name(Color::Blue) == "Blue");
Void::Testing::expect(M::enum_parse<Color>("Green").value() ==
Color::Green);
Void::Testing::expect(!M::enum_parse<Color>("Nope").has_value());
}
namespace
{
struct Marker {
};
struct Annotated {
[[= Marker{}]] int tagged = 0;
int plain = 0;
};
} // namespace
Void::Testing::Test meta_member_annotations()
{
static constexpr auto members = M::members_v<Annotated>;
static_assert(M::has_annotation<Marker>(members[0]));
static_assert(!M::has_annotation<Marker>(members[1]));
Void::Testing::expect(M::has_annotation<Marker>(members[0]));
Void::Testing::expect(!M::has_annotation<Marker>(members[1]));
}
Void::Testing::Test meta_type_name()
{
Void::Testing::expect_eq(M::type_name<Point>(), std::string{"Point"});
Void::Testing::expect_eq(M::type_name<Nest>(), std::string{"Nest"});
}