19#include <shared_mutex>
27 class thread_safe_container;
46 std::vector<std::shared_ptr<value>>
values;
87 std::shared_ptr<thread_safe_container>,
98 template<
typename T,
typename Variant>
100 return std::variant<T, Variant>::index();
104 static_assert(std::variant_size_v<ValueVariant> == 16,
105 "ValueVariant must have exactly 16 types");
106 static_assert(std::is_same_v<std::variant_alternative_t<0, ValueVariant>, std::monostate>,
107 "Index 0 must be std::monostate");
108 static_assert(std::is_same_v<std::variant_alternative_t<1, ValueVariant>,
bool>,
109 "Index 1 must be bool");
110 static_assert(std::is_same_v<std::variant_alternative_t<12, ValueVariant>, std::string>,
111 "Index 12 must be string");
112 static_assert(std::is_same_v<std::variant_alternative_t<13, ValueVariant>, std::vector<uint8_t>>,
113 "Index 13 must be bytes (vector<uint8_t>)");
114 static_assert(std::is_same_v<std::variant_alternative_t<15, ValueVariant>,
array_variant>,
115 "Index 15 must be array_variant");
152 value(std::string_view
name, value_types
type,
const std::vector<uint8_t>& raw_data);
177 std::string_view
name() const noexcept {
return name_; }
189 value_types
type()
const;
195 std::shared_lock lock(
mutex_);
196 return data_.index();
203 std::shared_lock lock(
mutex_);
204 return data_.index() == 0;
212 template<concepts::ValueVariantType T>
213 std::optional<T>
get()
const {
214 std::shared_lock lock(
mutex_);
215 if (
auto* ptr = std::get_if<T>(&
data_)) {
225 template<concepts::ValueVariantType T>
227 std::unique_lock lock(
mutex_);
236 template<concepts::ValueVisitor Visitor>
238 std::shared_lock lock(
mutex_);
239 read_count_.fetch_add(1, std::memory_order_relaxed);
240 return std::visit(std::forward<Visitor>(vis),
data_);
247 template<concepts::ValueVisitor Visitor>
249 std::unique_lock lock(
mutex_);
251 return std::visit(std::forward<Visitor>(vis),
data_);
283 static std::optional<value>
deserialize(
const std::vector<uint8_t>& data);
309 const std::vector<uint8_t>& data,
Enhanced type-safe value with perfect legacy compatibility.
static bool deserialize_data(value &result, value_types type, const std::vector< uint8_t > &data, size_t &offset)
Deserialize data portion based on type.
std::string to_json() const
Convert to JSON representation.
value_types type() const
Get the value_types enum (NOT variant::index()!)
bool operator==(const value &other) const
Comparison operators (thread-safe)
value & operator=(const value &other)
Copy assignment (thread-safe)
std::string to_string() const
Convert to string representation.
std::optional< T > get() const
Type-safe getter with optional return.
value(std::string_view name, T &&value)
Construct with name and typed value.
size_t write_count() const
void set(T &&value)
Type-safe setter.
std::string_view name() const noexcept
Get the name of this value (lock-free, immutable)
value()
Default constructor - creates null value.
auto visit_mut(Visitor &&vis)
Apply visitor to contained value (mutable)
void serialize_data(std::vector< uint8_t > &result) const
Serialize data portion based on type.
bool operator<(const value &other) const
bool is_null() const
Check if null value.
value(std::string_view name)
Construct with name (null value)
size_t read_count() const
Get read/write statistics.
static std::optional< value > deserialize(const std::vector< uint8_t > &data)
Deserialize from binary format (legacy compatible)
std::atomic< size_t > write_count_
auto visit(Visitor &&vis) const
Apply visitor to contained value (const)
std::atomic< size_t > read_count_
std::vector< uint8_t > serialize() const
Serialize to binary format (legacy compatible)
size_t variant_index() const
Get variant index (for internal use only)
bool operator!=(const value &other) const
constexpr size_t variant_index_of()
constexpr bool is_variant_type_v2_v
std::variant< std::monostate, bool, int16_t, uint16_t, int32_t, uint32_t, long, unsigned long, long long, unsigned long long, float, double, std::string, std::vector< uint8_t >, std::shared_ptr< thread_safe_container >, array_variant > ValueVariant
Type-aligned variant matching value_types enum EXACTLY.
Recursive array type for variant.
bool operator==(const array_variant &other) const
std::vector< std::shared_ptr< value > > values
bool operator!=(const array_variant &other) const
array_variant & operator=(const array_variant &other)
array_variant & operator=(array_variant &&other) noexcept=default
array_variant(array_variant &&other) noexcept=default
bool operator<(const array_variant &other) const
Type traits for variant types.