Container System 0.1.0
High-performance C++20 type-safe container framework with SIMD-accelerated serialization
Loading...
Searching...
No Matches
kcenon::container::factory Namespace Reference

Modern factory namespace for creating value instances. More...

Functions

template<typename T >
value make (std::string_view name, T &&val)
 Generic factory template for creating typed values.
 
value make_null (std::string_view name="")
 Create a null value.
 
value make_array (std::string_view name, std::vector< std::shared_ptr< value > > values)
 Create an array value from vector of shared_ptr<value>
 
value make_array (std::string_view name, std::initializer_list< value > values)
 Create an array value from initializer list.
 
value make_empty_array (std::string_view name)
 Create an empty array value.
 
value make_container (std::string_view name, std::shared_ptr< thread_safe_container > container)
 Create a container value.
 
value make_bytes (std::string_view name, const uint8_t *data, size_t size)
 Create a bytes value from raw data pointer.
 
value make_bytes_from_string (std::string_view name, std::string_view data)
 Create a bytes value from string (copy bytes) Note: This treats the string as binary data.
 

Detailed Description

Modern factory namespace for creating value instances.

Provides a unified, minimal API for value creation:

Usage examples:

auto v1 = factory::make("enabled", true); // bool
auto v2 = factory::make("count", 42); // int
auto v3 = factory::make("name", std::string("John")); // string
auto v4 = factory::make_null("empty"); // null
// Or use constructors directly (preferred):
auto v5 = value("flag", true);
auto v6 = value("num", 42);
Enhanced type-safe value with perfect legacy compatibility.
Definition value.h:129
value make(std::string_view name, T &&val)
Generic factory template for creating typed values.
value make_null(std::string_view name="")
Create a null value.

Function Documentation

◆ make()

template<typename T >
value kcenon::container::factory::make ( std::string_view name,
T && val )
inline

Generic factory template for creating typed values.

Forwards arguments to the value constructor with perfect forwarding. This is a thin wrapper that provides a consistent factory interface.

Template Parameters
TThe value type (automatically deduced)
Parameters
nameValue name
valThe value to store
Returns
value containing the specified data

Definition at line 59 of file variant_value_factory.h.

59 {
60 return value(name, std::forward<T>(val));
61 }

◆ make_array() [1/2]

value kcenon::container::factory::make_array ( std::string_view name,
std::initializer_list< value > values )
inline

Create an array value from initializer list.

Definition at line 88 of file variant_value_factory.h.

91 {
92 array_variant arr;
93 arr.values.reserve(values.size());
94 for (const auto& v : values) {
95 arr.values.push_back(std::make_shared<value>(v));
96 }
97 return value(name, std::move(arr));
98 }
Recursive array type for variant.
Definition value.h:45
std::vector< std::shared_ptr< value > > values
Definition value.h:46

References kcenon::container::array_variant::values.

◆ make_array() [2/2]

value kcenon::container::factory::make_array ( std::string_view name,
std::vector< std::shared_ptr< value > > values )
inline

Create an array value from vector of shared_ptr<value>

Definition at line 78 of file variant_value_factory.h.

79 {
80 array_variant arr;
81 arr.values = std::move(values);
82 return value(name, std::move(arr));
83 }

References kcenon::container::array_variant::values.

◆ make_bytes()

value kcenon::container::factory::make_bytes ( std::string_view name,
const uint8_t * data,
size_t size )
inline

Create a bytes value from raw data pointer.

Definition at line 118 of file variant_value_factory.h.

120 {
121 return value(name, std::vector<uint8_t>(data, data + size));
122 }

◆ make_bytes_from_string()

value kcenon::container::factory::make_bytes_from_string ( std::string_view name,
std::string_view data )
inline

Create a bytes value from string (copy bytes) Note: This treats the string as binary data.

Definition at line 128 of file variant_value_factory.h.

128 {
129 return value(name, std::vector<uint8_t>(
130 reinterpret_cast<const uint8_t*>(data.data()),
131 reinterpret_cast<const uint8_t*>(data.data() + data.size())
132 ));
133 }

◆ make_container()

value kcenon::container::factory::make_container ( std::string_view name,
std::shared_ptr< thread_safe_container > container )
inline

Create a container value.

Definition at line 110 of file variant_value_factory.h.

111 {
112 return value(name, std::move(container));
113 }

◆ make_empty_array()

value kcenon::container::factory::make_empty_array ( std::string_view name)
inline

Create an empty array value.

Definition at line 103 of file variant_value_factory.h.

103 {
104 return value(name, array_variant{});
105 }

◆ make_null()

value kcenon::container::factory::make_null ( std::string_view name = "")
inline

Create a null value.

Explicit factory for null value creation when a named null is needed.

Parameters
nameValue name (default: empty string)
Returns
value containing null (std::monostate)

Definition at line 71 of file variant_value_factory.h.

71 {
72 return value(name);
73 }