Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
Thoth::NJson::JsonObject Struct Reference

#include <JsonObject.hpp>

Public Types

using JsonValRef = Json &
 
using JsonPair = std::pair< JsonObjKey, Json >
 
using JsonPairRef = std::pair< JsonObjKeyRef, JsonValRef >
 
using MapType = Dsa::LinearMap< JsonObjKey, Json >
 
using IterType = decltype(MapType{}.begin())
 
using CIterType = decltype(MapType{}.cbegin())
 

Public Member Functions

 ~JsonObject ()
 
 JsonObject ()=default
 
 JsonObject (JsonObject &&other) noexcept
 
 JsonObject (const JsonObject &other)
 
 JsonObject (MapType &&initAs)
 Create with an existing map.
 
 JsonObject (std::initializer_list< JsonPair > init)
 
JsonObjectoperator= (JsonObject &&other) noexcept
 
JsonObjectoperator= (const JsonObject &other)
 
JsonObjectoperator= (std::initializer_list< JsonPair > list)
 
bool Exists (JsonObjKeyRef key) const
 check if a key exists.
 
bool Exists (JsonPairRef p) const
 check if a key exists.
 
bool Exists (JsonObjKeyRef key, JsonValRef val) const
 check if a key=val exists.
 
void Set (JsonPairRef p)
 Add a value with the specified key. Replace if already exists.
 
void Set (JsonObjKeyRef key, JsonValRef val)
 same as Add(JsonPairRef p).
 
bool Remove (JsonObjKeyRef key)
 Removes a key.
 
bool SetIfNull (JsonPairRef p)
 If key not exists, set it to value.
 
bool SetIfNull (JsonObjKeyRef key, JsonValRef val)
 same as SetIfNull(JsonPairRef p).
 
OptRefValWrapper Get (JsonObjKeyRef key)
 Get the reference of a key but don't create if it not exists.
 
OptCRefValWrapper Get (JsonObjKeyRef key) const
 Get the reference of a key but don't create if it not exists.
 
OptValWrapper GetCopy (JsonObjKeyRef key) const
 Copy of a value if it exists.
 
OptValWrapper GetAndMove (JsonObjKeyRef key) &&
 Copy of a value if it exists.
 
ValWrapper GetCopyOrNull (JsonObjKeyRef key) const
 Copy of a value or return null if it not exists.
 
ValWrapper GetOrNullAndMove (JsonObjKeyRef key) &&
 Copy of a value or return null if it not exists.
 
IterType begin ()
 
IterType end ()
 
CIterType begin () const
 
CIterType end () const
 
void Clear ()
 Clear all keys.
 
size_t Size () const
 
bool Empty () const
 
Jsonoperator[] (JsonObjKeyRef key)
 
const Jsonoperator[] (JsonObjKeyRef key) const
 
bool operator== (const JsonObject &other) const
 

Public Attributes

friend Json
 

Friends

struct std::formatter< JsonObject >
 
bool Details::ReadObject (std::string_view &input, auto &val, const Details::BufferInfo &info)
 

Member Typedef Documentation

◆ CIterType

using Thoth::NJson::JsonObject::CIterType = decltype(MapType{}.cbegin())

◆ IterType

◆ JsonPair

◆ JsonPairRef

◆ JsonValRef

◆ MapType

Constructor & Destructor Documentation

◆ ~JsonObject()

Thoth::NJson::JsonObject::~JsonObject ( )

◆ JsonObject() [1/5]

Thoth::NJson::JsonObject::JsonObject ( )
default

◆ JsonObject() [2/5]

Thoth::NJson::JsonObject::JsonObject ( JsonObject &&  other)
noexcept

◆ JsonObject() [3/5]

Thoth::NJson::JsonObject::JsonObject ( const JsonObject other)

◆ JsonObject() [4/5]

Thoth::NJson::JsonObject::JsonObject ( MapType &&  initAs)
explicit

Create with an existing map.

◆ JsonObject() [5/5]

Thoth::NJson::JsonObject::JsonObject ( std::initializer_list< JsonPair init)

Member Function Documentation

◆ begin() [1/2]

IterType Thoth::NJson::JsonObject::begin ( )
inline

◆ begin() [2/2]

CIterType Thoth::NJson::JsonObject::begin ( ) const
inline

◆ Clear()

void Thoth::NJson::JsonObject::Clear ( )

Clear all keys.

◆ Empty()

bool Thoth::NJson::JsonObject::Empty ( ) const
Returns
True if Size() is 0.

◆ end() [1/2]

IterType Thoth::NJson::JsonObject::end ( )
inline

◆ end() [2/2]

CIterType Thoth::NJson::JsonObject::end ( ) const
inline

◆ Exists() [1/3]

bool Thoth::NJson::JsonObject::Exists ( JsonObjKeyRef  key) const

check if a key exists.

Parameters
keyThe key to be checked.
Returns
True if the key exists, false otherwise.

◆ Exists() [2/3]

bool Thoth::NJson::JsonObject::Exists ( JsonObjKeyRef  key,
JsonValRef  val 
) const

check if a key=val exists.

Parameters
keyThe key to be checked.
valThe value to be checked.
Returns
True if the key-value pair exists, false otherwise.

◆ Exists() [3/3]

bool Thoth::NJson::JsonObject::Exists ( JsonPairRef  p) const

check if a key exists.

Parameters
pA pair with the key and value to be checked.
Returns
True if the key exists, false otherwise.

◆ Get() [1/2]

OptRefValWrapper Thoth::NJson::JsonObject::Get ( JsonObjKeyRef  key)

Get the reference of a key but don't create if it not exists.

Parameters
keyThe key.
Returns
JsonVal* if the key exists, std::nullopt otherwise.

◆ Get() [2/2]

OptCRefValWrapper Thoth::NJson::JsonObject::Get ( JsonObjKeyRef  key) const

Get the reference of a key but don't create if it not exists.

Parameters
keyThe key.
Returns
const JsonVal* if the key exists, std::nullopt otherwise.

◆ GetAndMove()

OptValWrapper Thoth::NJson::JsonObject::GetAndMove ( JsonObjKeyRef  key) &&

Copy of a value if it exists.

Parameters
keyThe key.
Returns
const JsonVal* if the key exists, std::nullopt otherwise.

◆ GetCopy()

OptValWrapper Thoth::NJson::JsonObject::GetCopy ( JsonObjKeyRef  key) const

Copy of a value if it exists.

Parameters
keyThe key.
Returns
const JsonVal* if the key exists, std::nullopt otherwise.

◆ GetCopyOrNull()

ValWrapper Thoth::NJson::JsonObject::GetCopyOrNull ( JsonObjKeyRef  key) const

Copy of a value or return null if it not exists.

Parameters
keyThe key.
Returns
const JsonVal* if the key exists, NullV otherwise.

◆ GetOrNullAndMove()

ValWrapper Thoth::NJson::JsonObject::GetOrNullAndMove ( JsonObjKeyRef  key) &&

Copy of a value or return null if it not exists.

Parameters
keyThe key.
Returns
const JsonVal* if the key exists, NullV otherwise.

◆ operator=() [1/3]

JsonObject & Thoth::NJson::JsonObject::operator= ( const JsonObject other)

◆ operator=() [2/3]

JsonObject & Thoth::NJson::JsonObject::operator= ( JsonObject &&  other)
noexcept

◆ operator=() [3/3]

JsonObject & Thoth::NJson::JsonObject::operator= ( std::initializer_list< JsonPair list)

◆ operator==()

bool Thoth::NJson::JsonObject::operator== ( const JsonObject other) const
Returns
True if both jsons match.

◆ operator[]() [1/2]

Json & Thoth::NJson::JsonObject::operator[] ( JsonObjKeyRef  key)
Returns
The JsonVal& associated with a key. Create if it not exists. STL containers has many problems so it must be JsonKey.

◆ operator[]() [2/2]

const Json & Thoth::NJson::JsonObject::operator[] ( JsonObjKeyRef  key) const
Returns
The const JsonVal& associated with a key or returns a null reference if it not exists. STL containers has many problems so it must be JsonKey.

◆ Remove()

bool Thoth::NJson::JsonObject::Remove ( JsonObjKeyRef  key)

Removes a key.

◆ Set() [1/2]

void Thoth::NJson::JsonObject::Set ( JsonObjKeyRef  key,
JsonValRef  val 
)

same as Add(JsonPairRef p).

◆ Set() [2/2]

void Thoth::NJson::JsonObject::Set ( JsonPairRef  p)

Add a value with the specified key. Replace if already exists.

Parameters
pA pair with the key and the value to be added.

◆ SetIfNull() [1/2]

bool Thoth::NJson::JsonObject::SetIfNull ( JsonObjKeyRef  key,
JsonValRef  val 
)

◆ SetIfNull() [2/2]

bool Thoth::NJson::JsonObject::SetIfNull ( JsonPairRef  p)

If key not exists, set it to value.

Parameters
pA pair with the key and the value to be added.
Returns
True if the key not exists, false otherwise.

◆ Size()

size_t Thoth::NJson::JsonObject::Size ( ) const
Returns
The count of keys.

Friends And Related Symbol Documentation

◆ Details::ReadObject

bool Details::ReadObject ( std::string_view &  input,
auto &  val,
const Details::BufferInfo info 
)
friend

◆ std::formatter< JsonObject >

friend struct std::formatter< JsonObject >
friend

Member Data Documentation

◆ Json

friend Thoth::NJson::JsonObject::Json

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