cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
cppfig::Value Class Reference

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.
 

Detailed Description

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.

Member Typedef Documentation

◆ ArrayType

using cppfig::Value::ArrayType = std::vector<Value>

Ordered sequence of Value elements.

◆ ObjectType

using cppfig::Value::ObjectType = std::map<std::string, Value, std::less<> >

Ordered map of string keys to Value children.

Constructor & Destructor Documentation

◆ Value() [1/12]

cppfig::Value::Value ( )
inline

Constructs a null value.

◆ Value() [2/12]

cppfig::Value::Value ( std::nullptr_t  )
inline

Constructs a null value.

◆ Value() [3/12]

cppfig::Value::Value ( bool  b)
inline

Constructs a boolean value.

◆ Value() [4/12]

cppfig::Value::Value ( int  i)
inline

Constructs an integer value from int.

◆ Value() [5/12]

cppfig::Value::Value ( std::int64_t  i)
inline

Constructs an integer value.

◆ Value() [6/12]

cppfig::Value::Value ( double  d)
inline

Constructs a double value.

◆ Value() [7/12]

cppfig::Value::Value ( float  f)
inline

Constructs a double value from float.

◆ Value() [8/12]

cppfig::Value::Value ( const char *  s)
inline

Constructs a string value from a C string.

◆ Value() [9/12]

cppfig::Value::Value ( std::string  s)
inline

Constructs a string value.

◆ Value() [10/12]

cppfig::Value::Value ( std::string_view  s)
inline

Constructs a string value from string_view.

◆ Value() [11/12]

cppfig::Value::Value ( const Value other)
inline

Deep-copies the value (recursive for objects / arrays).

◆ Value() [12/12]

cppfig::Value::Value ( Value &&  )
defaultnoexcept

Move constructor (default, transfers ownership).

◆ ~Value()

cppfig::Value::~Value ( )
default

Destructor (default, shared_ptr handles cleanup).

Member Function Documentation

◆ Array()

static auto cppfig::Value::Array ( ) -> Value
inlinestatic

Creates an empty array value.

◆ Contains()

auto cppfig::Value::Contains ( std::string_view  key) const -> bool
inline

Checks whether the given key exists in an object value.

◆ Dump()

auto cppfig::Value::Dump ( int  indent = 0) const -> std::string
inline

Produces a JSON-like string representation.

Parameters
indentNumber of spaces per indentation level (0 = compact).

◆ Get()

template<typename T >
auto cppfig::Value::Get ( ) const -> T
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.

◆ GetAtPath()

auto cppfig::Value::GetAtPath ( std::string_view  path) const -> StatusOr<Value>
inline

Gets a value at a dot-separated path.

◆ HasPath()

auto cppfig::Value::HasPath ( std::string_view  path) const -> bool
inline

Checks if a path exists in the data.

◆ IsArray()

auto cppfig::Value::IsArray ( ) const -> bool
inline

Returns true if this value is an array.

◆ IsBoolean()

auto cppfig::Value::IsBoolean ( ) const -> bool
inline

Returns true if this value is a boolean.

◆ IsDouble()

auto cppfig::Value::IsDouble ( ) const -> bool
inline

Returns true if this value is a double.

◆ IsInteger()

auto cppfig::Value::IsInteger ( ) const -> bool
inline

Returns true if this value is an integer.

◆ IsNull()

auto cppfig::Value::IsNull ( ) const -> bool
inline

Returns true if this value is null.

◆ IsNumber()

auto cppfig::Value::IsNumber ( ) const -> bool
inline

Returns true if this value is any numeric type (integer or double).

◆ IsObject()

auto cppfig::Value::IsObject ( ) const -> bool
inline

Returns true if this value is an object (key-value map).

◆ IsString()

auto cppfig::Value::IsString ( ) const -> bool
inline

Returns true if this value is a string.

◆ Items() [1/2]

auto cppfig::Value::Items ( ) -> ObjectType&
inline

Returns mutable reference to the object entries, promoting null → object.

◆ Items() [2/2]

auto cppfig::Value::Items ( ) const -> const ObjectType&
inline

Returns const reference to the object entries.

◆ Merge()

static auto cppfig::Value::Merge ( const Value base,
const Value overlay 
) -> Value
inlinestatic

Deep-merges two object values; overlay takes precedence.

  • Objects are merged recursively.
  • Arrays and primitives from overlay replace base entirely.

◆ Object()

static auto cppfig::Value::Object ( ) -> Value
inlinestatic

Creates an empty object value.

◆ operator!=()

auto cppfig::Value::operator!= ( const Value other) const -> bool
inline

Value inequality.

◆ operator=() [1/2]

auto cppfig::Value::operator= ( const Value other) -> Value&
inline

Deep-copy assignment.

◆ operator=() [2/2]

auto cppfig::Value::operator= ( Value &&  ) -> Value &=default
defaultnoexcept

Move assignment (default).

◆ operator==()

auto cppfig::Value::operator== ( const Value other) const -> bool
inline

Value equality (deep comparison for objects/arrays).

◆ operator[]() [1/2]

auto cppfig::Value::operator[] ( const std::string &  key) -> Value&
inline

Accesses or creates a child by key, promoting null → object.

◆ operator[]() [2/2]

auto cppfig::Value::operator[] ( const std::string &  key) const -> const Value&
inline

Read-only access to a child by key (returns static null for missing keys).

◆ SetAtPath()

void cppfig::Value::SetAtPath ( std::string_view  path,
const Value value 
)
inline

Sets a value at a dot-separated path, creating intermediate objects.


The documentation for this class was generated from the following file: