nfx-serialization 0.3.0
Cross-platform C++ JSON serialization library with extensible trait capabilities
Loading...
Searching...
No Matches
nfx::serialization::json::Document::Object Class Referencefinal

JSON object wrapper for Document. More...

#include <nfx/serialization/json/Document.h>

Classes

class  Iterator
 Forward iterator for Object fields. More...

Public Member Functions

 Object ()
 Default constructor - creates invalid object.
 Object (const Document::Object &other)
 Copy constructor.
 Object (Document::Object &&other) noexcept
 Move constructor.
 ~Object ()=default
 Destructor.
Document::Objectoperator= (const Document::Object &other)
 Copy assignment operator.
Document::Objectoperator= (Document::Object &&other) noexcept
 Move assignment operator.
bool operator== (const Document::Object &other) const
 Equality comparison operator.
bool operator!= (const Document::Object &other) const
 Inequality comparison operator.
std::string toString (int indent=0) const
 Convert object to JSON string.
std::vector< uint8_t > toBytes () const
 Convert object to JSON bytes.
size_t size () const
 Get number of fields in object.
void clear ()
 Clear all fields from object.
bool removeField (std::string_view key)
 Remove field from object.
bool contains (std::string_view fieldName) const
 Check if a field exists in this object.
template<JsonValue T>
std::optional< T > get (std::string_view path) const
 Get field value by key.
template<JsonValue T>
bool get (std::string_view path, T &value) const
 Get field value into output parameter.
template<JsonValue T>
void set (std::string_view path, const T &value)
 Set field value (copy version).
template<JsonValue T>
void set (std::string_view path, T &&value)
 Set field value (move version).
bool isValid () const
 Check if object is valid.
std::string lastError () const
 Get last error message.
Iterator begin () const
 Get iterator to first field.
Iterator end () const
 Get iterator past last field.

Friends

class Document
class Document_impl

Detailed Description

JSON object wrapper for Document.

Provides type-safe access to JSON object fields with support for field access, modification, removal, and nested operations using JSON Pointer paths.

Definition at line 335 of file Document.h.

Constructor & Destructor Documentation

◆ Object() [1/2]

nfx::serialization::json::Document::Object::Object ( const Document::Object & other)

Copy constructor.

Parameters
otherObject to copy from

◆ Object() [2/2]

nfx::serialization::json::Document::Object::Object ( Document::Object && other)
noexcept

Move constructor.

Parameters
otherObject to move from

Member Function Documentation

◆ begin()

Iterator nfx::serialization::json::Document::Object::begin ( ) const

Get iterator to first field.

Returns
Iterator pointing to first key-value pair

◆ contains()

bool nfx::serialization::json::Document::Object::contains ( std::string_view fieldName) const

Check if a field exists in this object.

Parameters
fieldNameName of the field to check (simple name, not a path)
Returns
true if the field exists, false otherwise

◆ end()

Iterator nfx::serialization::json::Document::Object::end ( ) const

Get iterator past last field.

Returns
Iterator representing end position

◆ get() [1/2]

template<JsonValue T>
std::optional< T > nfx::serialization::json::Document::Object::get ( std::string_view path) const

Get field value by key.

Template Parameters
TType to retrieve
Parameters
pathField key or nested path
Returns
Optional containing field value if exists and correct type

◆ get() [2/2]

template<JsonValue T>
bool nfx::serialization::json::Document::Object::get ( std::string_view path,
T & value ) const

Get field value into output parameter.

Template Parameters
TType to retrieve
Parameters
pathField key or nested path
[out]valueOutput parameter to store the result
Returns
true if field exists and was successfully retrieved, false otherwise

◆ isValid()

bool nfx::serialization::json::Document::Object::isValid ( ) const

Check if object is valid.

Returns
true if object is valid and accessible

◆ lastError()

std::string nfx::serialization::json::Document::Object::lastError ( ) const

Get last error message.

Returns
String describing the last error

◆ operator!=()

bool nfx::serialization::json::Document::Object::operator!= ( const Document::Object & other) const

Inequality comparison operator.

Parameters
otherObject to compare with
Returns
true if objects are not equal

◆ operator=() [1/2]

Document::Object & nfx::serialization::json::Document::Object::operator= ( const Document::Object & other)

Copy assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

◆ operator=() [2/2]

Document::Object & nfx::serialization::json::Document::Object::operator= ( Document::Object && other)
noexcept

Move assignment operator.

Parameters
otherObject to move from
Returns
Reference to this object

◆ operator==()

bool nfx::serialization::json::Document::Object::operator== ( const Document::Object & other) const

Equality comparison operator.

Parameters
otherObject to compare with
Returns
true if objects are equal

◆ removeField()

bool nfx::serialization::json::Document::Object::removeField ( std::string_view key)

Remove field from object.

Parameters
keyField name to remove
Returns
true if field was removed

◆ set() [1/2]

template<JsonValue T>
void nfx::serialization::json::Document::Object::set ( std::string_view path,
const T & value )

Set field value (copy version).

Template Parameters
TType to set
Parameters
pathField key or nested path
valueValue to copy and set

◆ set() [2/2]

template<JsonValue T>
void nfx::serialization::json::Document::Object::set ( std::string_view path,
T && value )

Set field value (move version).

Template Parameters
TType to set
Parameters
pathField key or nested path
valueValue to move and set

◆ size()

size_t nfx::serialization::json::Document::Object::size ( ) const

Get number of fields in object.

Returns
Number of key-value pairs

◆ toBytes()

std::vector< uint8_t > nfx::serialization::json::Document::Object::toBytes ( ) const

Convert object to JSON bytes.

Returns
JSON byte representation

◆ toString()

std::string nfx::serialization::json::Document::Object::toString ( int indent = 0) const

Convert object to JSON string.

Parameters
indentIndentation level for pretty printing
  • 0: compact output (no whitespace)
  • >0: pretty-print with specified spaces per level
Returns
JSON string representation

◆ Document

friend class Document
friend

Definition at line 341 of file Document.h.

◆ Document_impl

friend class Document_impl
friend

Definition at line 342 of file Document.h.


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