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

JSON array wrapper for Document. More...

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

Classes

class  Iterator
 Forward iterator for Array elements. More...

Public Member Functions

 Array ()
 Default constructor - creates empty array.
 Array (const Document::Array &other)
 Copy constructor.
 Array (Document::Array &&other) noexcept
 Move constructor.
 ~Array ()=default
 Destructor.
Document::Arrayoperator= (const Document::Array &other)
 Copy assignment operator.
Document::Arrayoperator= (Document::Array &&other) noexcept
 Move assignment operator.
bool operator== (const Document::Array &other) const
 Equality comparison.
bool operator!= (const Document::Array &other) const
 Inequality comparison.
std::string toString (int indent=0) const
 Convert array to JSON string.
std::vector< uint8_t > toBytes () const
 Convert array to JSON bytes.
size_t size () const
 Get number of elements in array.
void clear ()
 Clear all elements from array.
bool remove (size_t index)
 Remove element at index.
bool contains (std::string_view indexStr) const
 Check if an element exists at the specified index.
template<JsonValue T>
std::optional< T > get (size_t index) const
 Get element at index.
template<JsonValue T>
bool get (size_t index, T &value) const
 Get element at index into output parameter.
template<JsonValue T>
std::optional< T > get (std::string_view path) const
 Get nested element at path.
template<JsonValue T>
bool get (std::string_view path, T &value) const
 Get nested element at path into output parameter.
template<JsonValue T>
void set (size_t index, const T &value)
 Set element at index (copy version).
template<JsonValue T>
void set (size_t index, T &&value)
 Set element at index (move version).
template<JsonValue T>
void set (std::string_view path, const T &value)
 Set nested element at path (copy version).
template<JsonValue T>
void set (std::string_view path, T &&value)
 Set nested element at path (move version).
template<JsonValue T>
void append (const T &value)
 Append element to end of array (copy version).
template<JsonValue T>
void append (T &&value)
 Append element to end of array (move version).
void append (Document &value)
 Append Document to end of array (reference version).
void append (Document::Array &value)
 Append Array to end of array (reference version).
void append (Document::Object &value)
 Append Object to end of array (reference version).
template<JsonValue T>
void insert (size_t index, const T &value)
 Insert element at index (copy version).
template<JsonValue T>
void insert (size_t index, T &&value)
 Insert element at index (move version).
void insert (size_t index, Document &value)
 Insert Document at index (reference version).
void insert (size_t index, Document::Array &value)
 Insert Array at index (reference version).
void insert (size_t index, Document::Object &value)
 Insert Object at index (reference version).
bool isValid () const
 Check if array is valid.
std::string lastError () const
 Get last error message.
Iterator begin () const
 Get iterator to first element.
Iterator end () const
 Get iterator past last element.

Friends

class Document
class Document_impl

Detailed Description

JSON array wrapper for Document.

Provides type-safe access to JSON array elements with support for indexed access, element addition/insertion/removal, and nested operations.

Definition at line 663 of file Document.h.

Constructor & Destructor Documentation

◆ Array() [1/2]

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

Copy constructor.

Parameters
otherArray to copy from

◆ Array() [2/2]

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

Move constructor.

Parameters
otherArray to move from

Member Function Documentation

◆ append() [1/5]

template<JsonValue T>
void nfx::serialization::json::Document::Array::append ( const T & value)

Append element to end of array (copy version).

Template Parameters
TType to append
Parameters
valueValue to copy and append

◆ append() [2/5]

void nfx::serialization::json::Document::Array::append ( Document & value)

Append Document to end of array (reference version).

Parameters
valueDocument reference to append

◆ append() [3/5]

void nfx::serialization::json::Document::Array::append ( Document::Array & value)

Append Array to end of array (reference version).

Parameters
valueArray reference to append

◆ append() [4/5]

void nfx::serialization::json::Document::Array::append ( Document::Object & value)

Append Object to end of array (reference version).

Parameters
valueObject reference to append

◆ append() [5/5]

template<JsonValue T>
void nfx::serialization::json::Document::Array::append ( T && value)

Append element to end of array (move version).

Template Parameters
TType to append
Parameters
valueValue to move and append

◆ begin()

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

Get iterator to first element.

Returns
Iterator pointing to first element

◆ contains()

bool nfx::serialization::json::Document::Array::contains ( std::string_view indexStr) const

Check if an element exists at the specified index.

Parameters
indexStrIndex as string (e.g., "0", "1") or JSON Pointer (e.g., "/0", "/1")
Returns
true if the element exists, false otherwise

◆ end()

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

Get iterator past last element.

Returns
Iterator representing end position

◆ get() [1/4]

template<JsonValue T>
std::optional< T > nfx::serialization::json::Document::Array::get ( size_t index) const

Get element at index.

Template Parameters
TType to retrieve
Parameters
indexArray index
Returns
Optional containing element if exists and correct type

◆ get() [2/4]

template<JsonValue T>
bool nfx::serialization::json::Document::Array::get ( size_t index,
T & value ) const

Get element at index into output parameter.

Template Parameters
TType to retrieve
Parameters
indexArray index
[out]valueOutput parameter to store the result
Returns
true if element exists and was successfully retrieved, false otherwise

◆ get() [3/4]

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

Get nested element at path.

Template Parameters
TType to retrieve
Parameters
pathJSON pointer path
Returns
Optional containing element if exists and correct type

◆ get() [4/4]

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

Get nested element at path into output parameter.

Template Parameters
TType to retrieve
Parameters
pathJSON pointer path
[out]valueOutput parameter to store the result
Returns
true if element exists and was successfully retrieved, false otherwise

◆ insert() [1/5]

template<JsonValue T>
void nfx::serialization::json::Document::Array::insert ( size_t index,
const T & value )

Insert element at index (copy version).

Template Parameters
TType to insert
Parameters
indexPosition to insert at
valueValue to copy and insert

◆ insert() [2/5]

void nfx::serialization::json::Document::Array::insert ( size_t index,
Document & value )

Insert Document at index (reference version).

Parameters
indexPosition to insert at
valueDocument reference to insert

◆ insert() [3/5]

void nfx::serialization::json::Document::Array::insert ( size_t index,
Document::Array & value )

Insert Array at index (reference version).

Parameters
indexPosition to insert at
valueArray reference to insert

◆ insert() [4/5]

void nfx::serialization::json::Document::Array::insert ( size_t index,
Document::Object & value )

Insert Object at index (reference version).

Parameters
indexPosition to insert at
valueObject reference to insert

◆ insert() [5/5]

template<JsonValue T>
void nfx::serialization::json::Document::Array::insert ( size_t index,
T && value )

Insert element at index (move version).

Template Parameters
TType to insert
Parameters
indexPosition to insert at
valueValue to move and insert

◆ isValid()

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

Check if array is valid.

Returns
true if array is valid and accessible

◆ lastError()

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

Get last error message.

Returns
String describing the last error

◆ operator!=()

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

Inequality comparison.

Parameters
otherArray to compare with
Returns
true if arrays are not equal

◆ operator=() [1/2]

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

Copy assignment operator.

Parameters
otherArray to copy from
Returns
Reference to this array

◆ operator=() [2/2]

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

Move assignment operator.

Parameters
otherArray to move from
Returns
Reference to this array

◆ operator==()

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

Equality comparison.

Parameters
otherArray to compare with
Returns
true if arrays are equal

◆ remove()

bool nfx::serialization::json::Document::Array::remove ( size_t index)

Remove element at index.

Parameters
indexArray index
Returns
true if element was removed

◆ set() [1/4]

template<JsonValue T>
void nfx::serialization::json::Document::Array::set ( size_t index,
const T & value )

Set element at index (copy version).

Template Parameters
TType to set
Parameters
indexArray index
valueValue to copy

◆ set() [2/4]

template<JsonValue T>
void nfx::serialization::json::Document::Array::set ( size_t index,
T && value )

Set element at index (move version).

Template Parameters
TType to set
Parameters
indexArray index
valueValue to move

◆ set() [3/4]

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

Set nested element at path (copy version).

Template Parameters
TType to set
Parameters
pathJSON pointer path
valueValue to copy

◆ set() [4/4]

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

Set nested element at path (move version).

Template Parameters
TType to set
Parameters
pathJSON pointer path
valueValue to move

◆ size()

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

Get number of elements in array.

Returns
Size of array

◆ toBytes()

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

Convert array to JSON bytes.

Returns
JSON byte representation

◆ toString()

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

Convert array 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 669 of file Document.h.

◆ Document_impl

friend class Document_impl
friend

Definition at line 670 of file Document.h.


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