|
cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
|
A self-contained, recursive value type for configuration data. More...
#include <value.h>
Public Types | |
| using | ObjectType = std::map< std::string, Value, std::less<> > |
| Ordered map of string keys to Value children. | |
| using | ArrayType = std::vector< Value > |
| Ordered sequence of Value elements. | |
Public Member Functions | |
| Value () | |
| Constructs a null value. | |
| Value (std::nullptr_t) | |
| Constructs a null value. | |
| Value (bool b) | |
| Constructs a boolean value. | |
| Value (int i) | |
| Constructs an integer value from int. | |
| Value (std::int64_t i) | |
| Constructs an integer value. | |
| Value (double d) | |
| Constructs a double value. | |
| Value (float f) | |
| Constructs a double value from float. | |
| Value (const char *s) | |
| Constructs a string value from a C string. | |
| Value (std::string s) | |
| Constructs a string value. | |
| Value (std::string_view s) | |
| Constructs a string value from string_view. | |
| Value (const Value &other) | |
| Deep-copies the value (recursive for objects / arrays). | |
| auto | operator= (const Value &other) -> Value & |
| Deep-copy assignment. | |
| Value (Value &&) noexcept=default | |
| Move constructor (default, transfers ownership). | |
| auto | operator= (Value &&) noexcept -> Value &=default |
| Move assignment (default). | |
| ~Value ()=default | |
| Destructor (default, shared_ptr handles cleanup). | |
| auto | IsNull () const -> bool |
| Returns true if this value is null. | |
| auto | IsBoolean () const -> bool |
| Returns true if this value is a boolean. | |
| auto | IsInteger () const -> bool |
| Returns true if this value is an integer. | |
| auto | IsDouble () const -> bool |
| Returns true if this value is a double. | |
| auto | IsNumber () const -> bool |
| Returns true if this value is any numeric type (integer or double). | |
| auto | IsString () const -> bool |
| Returns true if this value is a string. | |
| auto | IsObject () const -> bool |
| Returns true if this value is an object (key-value map). | |
| auto | IsArray () const -> bool |
| Returns true if this value is an array. | |
| template<typename T > | |
| auto | Get () const -> T |
| Extracts the stored value as the requested type. | |
| auto | Contains (std::string_view key) const -> bool |
| Checks whether the given key exists in an object value. | |
| auto | operator[] (const std::string &key) -> Value & |
| Accesses or creates a child by key, promoting null → object. | |
| auto | operator[] (const std::string &key) const -> const Value & |
| Read-only access to a child by key (returns static null for missing keys). | |
| auto | Items () const -> const ObjectType & |
| Returns const reference to the object entries. | |
| auto | Items () -> ObjectType & |
| Returns mutable reference to the object entries, promoting null → object. | |
| auto | GetAtPath (std::string_view path) const -> StatusOr< Value > |
| Gets a value at a dot-separated path. | |
| void | SetAtPath (std::string_view path, const Value &value) |
| Sets a value at a dot-separated path, creating intermediate objects. | |
| auto | HasPath (std::string_view path) const -> bool |
| Checks if a path exists in the data. | |
| auto | Dump (int indent=0) const -> std::string |
| Produces a JSON-like string representation. | |
| auto | operator== (const Value &other) const -> bool |
| Value equality (deep comparison for objects/arrays). | |
| auto | operator!= (const Value &other) const -> bool |
| Value inequality. | |
Static Public Member Functions | |
| static auto | Object () -> Value |
| Creates an empty object value. | |
| static auto | Array () -> Value |
| Creates an empty array value. | |
| static auto | Merge (const Value &base, const Value &overlay) -> Value |
| Deep-merges two object values; overlay takes precedence. | |
A self-contained, recursive value type for configuration data.
This type replaces external JSON dependencies in the core library. It supports: null, bool, int64, double, string, object (map), and array.
Objects use std::map with transparent comparison for efficient std::string_view lookups. Recursive containers are heap-allocated via std::shared_ptr to keep the variant's inline size small; a custom copy constructor ensures full deep-copy (value) semantics.
| using cppfig::Value::ArrayType = std::vector<Value> |
Ordered sequence of Value elements.
| using cppfig::Value::ObjectType = std::map<std::string, Value, std::less<> > |
Ordered map of string keys to Value children.
|
inline |
Constructs a null value.
|
inline |
Constructs a null value.
|
inline |
Constructs a boolean value.
|
inline |
Constructs an integer value from int.
|
inline |
Constructs an integer value.
|
inline |
Constructs a double value.
|
inline |
Constructs a double value from float.
|
inline |
Constructs a string value from a C string.
|
inline |
Constructs a string value.
|
inline |
Constructs a string value from string_view.
|
inline |
Deep-copies the value (recursive for objects / arrays).
|
defaultnoexcept |
Move constructor (default, transfers ownership).
|
default |
Destructor (default, shared_ptr handles cleanup).
|
inlinestatic |
Creates an empty array value.
|
inline |
Checks whether the given key exists in an object value.
|
inline |
Produces a JSON-like string representation.
| indent | Number of spaces per indentation level (0 = compact). |
|
inline |
Extracts the stored value as the requested type.
Supported types: bool, int, std::int64_t, double, float, std::string. Integer↔double conversions are performed with static_cast when the underlying storage differs from the requested type.
Gets a value at a dot-separated path.
|
inline |
Checks if a path exists in the data.
|
inline |
Returns true if this value is an array.
|
inline |
Returns true if this value is a boolean.
|
inline |
Returns true if this value is a double.
|
inline |
Returns true if this value is an integer.
|
inline |
Returns true if this value is null.
|
inline |
Returns true if this value is any numeric type (integer or double).
|
inline |
Returns true if this value is an object (key-value map).
|
inline |
Returns true if this value is a string.
|
inline |
Returns mutable reference to the object entries, promoting null → object.
|
inline |
Returns const reference to the object entries.
|
inlinestatic |
Deep-merges two object values; overlay takes precedence.
|
inlinestatic |
Creates an empty object value.
Move assignment (default).
|
inline |
Value equality (deep comparison for objects/arrays).
|
inline |
Accesses or creates a child by key, promoting null → object.
|
inline |
Read-only access to a child by key (returns static null for missing keys).
|
inline |
Sets a value at a dot-separated path, creating intermediate objects.