AFLOW
 
Loading...
Searching...
No Matches
aurostd::JSON::object Struct Reference

storge container for a JSON object More...

#include <aurostd_xparser_json.h>

Public Member Functions

JSON::objectoperator[] (size_t index) const
 direct index access to JSON::object_types::LIST objects
 
JSON::objectoperator[] (const std::string &key) const
 direct key access to JSON::object_types::DICTIONARY objects
 
JSON::objectoperator[] (const char *key) const
 direct key access to JSON::object_types::DICTIONARY objects
 
JSON::objectoperator= (const char *content)
 assignment operator for char
 
JSON::objectoperator= (const std::string &content)
 assignment operator for string
 
JSON::objectoperator= (bool content)
 assignment operator for bool
 
JSON::objectoperator= (std::nullptr_t content)
 assignment operator for nullptr
 
JSON::objectoperator= (const List &content)
 assignment operator for JSON::List
 
JSON::objectoperator= (const Dictionary &content)
 assignment operator for JSON::Dictionary
 
template<class utype, enable_arithmetic< utype > = true>
JSON::objectoperator= (utype content)
 
template<class utype>
JSON::objectoperator= (const xcomplex< utype > &content)
 
template<class utype>
JSON::objectoperator= (const std::vector< utype > &content)
 
template<class utype>
JSON::objectoperator= (const std::deque< utype > &content)
 
template<class utype>
JSON::objectoperator= (const std::map< std::string, utype > &content)
 
template<class utype>
JSON::objectoperator= (const xvector< utype > &content)
 
template<class utype>
JSON::objectoperator= (const xmatrix< utype > &content)
 
template<class utype>
JSON::objectoperator= (const JsonSerializable< utype > &content)
 
template<class T, enable_list_like< T > = true>
JSON::objectoperator= (const T &content)
 
template<class T, enable_dict_like< T > = true>
JSON::objectoperator= (const T &content)
 
 object ()=default
 
 object (const char *content)
 converting constructor: set the content of this JSON::object based on a char
 
 object (const std::string &content)
 converting constructor: set the content of this JSON::object based on a string
 
 object (bool content)
 converting constructor: set the content of this JSON::object based on a bool
 
 object (std::nullptr_t content)
 converting constructor: set the content of this JSON::object to null
 
 object (object_types create_type)
 create an empty JSON::object of a given JSON::object_types
 
 object (const List &content)
 
 object (const Dictionary &content)
 
template<typename utype, enable_arithmetic< utype > = true>
 object (utype content)
 
template<typename utype>
 object (const xcomplex< utype > &content)
 
template<typename utype>
 object (const std::vector< utype > &content)
 
template<typename utype>
 object (const std::deque< utype > &content)
 
template<typename utype>
 object (const std::map< std::string, utype > &content)
 
template<typename utype>
 object (const xvector< utype > &content)
 
template<typename utype>
 object (const xmatrix< utype > &content)
 
template<typename T>
 object (const JsonSerializable< T > &content)
 
template<typename T, enable_list_like< T > = true>
 object (const T &content)
 
template<typename T, enable_dict_like< T > = true>
 object (const T &content)
 
 operator bool () const
 conversion function for bool
 
 operator std::string () const
 conversion function for string
 
 operator double () const
 conversion function for double
 
 operator long double () const
 conversion function for float
 
 operator float () const
 conversion function for float
 
 operator long long () const
 conversion function for long long
 
 operator long () const
 conversion function for long
 
 operator int () const
 conversion function for int
 
 operator char () const
 conversion function for char
 
 operator unsigned long long () const
 conversion function for unsigned long long
 
 operator unsigned long () const
 conversion function for unsigned long
 
 operator unsigned int () const
 conversion function for int
 
 operator List () const
 
 operator Dictionary () const
 
template<class utype>
 operator xcomplex< utype > () const
 
template<class utype>
 operator std::vector< utype > () const
 
template<class utype>
 operator std::deque< utype > () const
 
template<class utype>
 operator std::set< utype > () const
 
template<class utype>
 operator std::map< std::string, utype > () const
 
template<class utype>
 operator aurostd::xvector< utype > () const
 
template<class utype>
 operator aurostd::xmatrix< utype > () const
 
template<class T, enable_list_like< T > = true>
 operator T () const
 
template<class T, enable_dict_like< T > = true>
 operator T () const
 
template<class T, enable_serializable< T > = true>
 operator T () const
 
void push_back (const JSON::object &content) const
 allow to append to JSON::object_type::LIST
 
void join (const JSON::object &content) const
 allow to merge two dictionaries or lists
 
size_t size () const
 gives the size of JSON::object_tpe::LIST, JSON::object_tpe::DICTIONARY or JSON::object_tpe::STRING
 
bool empty () const
 checks if JSON::object_tpe::LIST, JSON::object_tpe::DICTIONARY or JSON::object_tpe::STRING is empty
 
size_t count (const std::string &) const
 count the occurrence of key string in a JSON::object_type::DICTIONARY
 
std::map< std::string, JSON::object >::iterator find (const std::string &key) const
 returns an iterator to the result of find in JSON::object_type::DICTIONARY
 
template<class utype>
std::list< utype >::iterator find_list (const utype &key) const
 
std::map< std::string, JSON::object >::iterator end () const
 returns an iterator to the end() of a JSON::object_type::DICTIONARY
 
std::map< std::string, JSON::object >::iterator begin () const
 returns an iterator to the begin() of a JSON::object_type::DICTIONARY
 
std::vector< std::string > keys () const
 returns a vector of all keys in a JSON::object_type::DICTIONARY
 
void fromString (const std::string &content)
 change this JSON::object to a JSON::object_types::STRING
 
void fromList (const List &content)
 change this JSON::object to a JSON::object_types::LIST
 
void fromDictionary (const Dictionary &content)
 change this JSON::object to a JSON::object_types::DICTIONARY
 
template<class utype>
void fromNumber (utype content)
 
template<class utype>
void fromComplex (const xcomplex< utype > &content)
 
template<class utype>
void fromVector (const std::vector< utype > &content)
 
template<class utype>
void fromDeque (const std::deque< utype > &content)
 
template<class utype>
void fromMap (const std::map< std::string, utype > &content)
 
template<class utype>
void fromXvector (const xvector< utype > &content)
 
template<class utype>
void fromXmatrix (const xmatrix< utype > &content)
 
template<class T, enable_list_like< T > = true>
void fromListLike (const T &content)
 
template<class T, enable_dict_like< T > = true>
void fromDictLike (const T &content)
 
template<class T, enable_list_like< T > = true>
T toListLike () const
 
template<class T, enable_dict_like< T > = true>
T toDictLike () const
 
std::string toString (bool json_format=true, bool escape_unicode=true) const
 converts a JSON::object into a string
 
void saveFile (const std::string &file_path, compression_type ct=compression_type::None, bool escape_unicode=true) const
 save JSON::object to file
 

Public Attributes

object_types type = object_types::NONE
 
std::shared_ptr< void > obj = nullptr
 

Detailed Description

storge container for a JSON object

Authors
20220924 | Hagen Eckert - created struct
See also
"JSON definition"
"Parsing JSON is a Minefield"

Definition at line 51 of file aurostd_xparser_json.h.

Constructor & Destructor Documentation

◆ object() [1/18]

aurostd::JSON::object::object ( )
default

◆ object() [2/18]

aurostd::JSON::object::object ( const char * content)

converting constructor: set the content of this JSON::object based on a char

Definition at line 208 of file aurostd_xparser_json.cpp.

◆ object() [3/18]

aurostd::JSON::object::object ( const std::string & content)

converting constructor: set the content of this JSON::object based on a string

Definition at line 213 of file aurostd_xparser_json.cpp.

◆ object() [4/18]

aurostd::JSON::object::object ( bool content)

converting constructor: set the content of this JSON::object based on a bool

Definition at line 218 of file aurostd_xparser_json.cpp.

◆ object() [5/18]

aurostd::JSON::object::object ( std::nullptr_t content)

converting constructor: set the content of this JSON::object to null

Note
pass in a nullptr

Definition at line 228 of file aurostd_xparser_json.cpp.

◆ object() [6/18]

aurostd::JSON::object::object ( object_types create_type)

create an empty JSON::object of a given JSON::object_types

Authors
20221031 | Hagen Eckert - created

Definition at line 236 of file aurostd_xparser_json.cpp.

◆ object() [7/18]

aurostd::JSON::object::object ( const List & content)

◆ object() [8/18]

aurostd::JSON::object::object ( const Dictionary & content)

◆ object() [9/18]

template<typename utype, enable_arithmetic< utype > = true>
aurostd::JSON::object::object ( utype content)

◆ object() [10/18]

template<typename utype>
aurostd::JSON::object::object ( const xcomplex< utype > & content)

◆ object() [11/18]

template<typename utype>
aurostd::JSON::object::object ( const std::vector< utype > & content)

◆ object() [12/18]

template<typename utype>
aurostd::JSON::object::object ( const std::deque< utype > & content)

◆ object() [13/18]

template<typename utype>
aurostd::JSON::object::object ( const std::map< std::string, utype > & content)

◆ object() [14/18]

template<typename utype>
aurostd::JSON::object::object ( const xvector< utype > & content)

◆ object() [15/18]

template<typename utype>
aurostd::JSON::object::object ( const xmatrix< utype > & content)

◆ object() [16/18]

template<typename T>
aurostd::JSON::object::object ( const JsonSerializable< T > & content)
inline

Definition at line 92 of file aurostd_xparser_json.h.

◆ object() [17/18]

template<typename T, enable_list_like< T > = true>
aurostd::JSON::object::object ( const T & content)

◆ object() [18/18]

template<typename T, enable_dict_like< T > = true>
aurostd::JSON::object::object ( const T & content)

Member Function Documentation

◆ operator[]() [1/3]

JSON::object & aurostd::JSON::object::operator[] ( size_t index) const

direct index access to JSON::object_types::LIST objects

Parameters
indexlist index
Returns
JSON::object stored at index
Note
throws an error if used on something other than JSON::object_types::LIST
the returned JSON::object can be directly be saved into an appropriate variable like string content = json_obj[3];
Authors
20220924 | Hagen Eckert - created

Definition at line 56 of file aurostd_xparser_json.cpp.

◆ operator[]() [2/3]

JSON::object & aurostd::JSON::object::operator[] ( const std::string & key) const

direct key access to JSON::object_types::DICTIONARY objects

Parameters
keydictionary key
Returns
JSON::object stored at key
Note
throws an error if used on something other than JSON::object_types::DICTIONARY
the returned JSON::object can be directly be saved into an appropriate variable like ‘string content = json_obj['my_key’];`
Authors
20220924 | Hagen Eckert - created

Definition at line 74 of file aurostd_xparser_json.cpp.

◆ operator[]() [3/3]

JSON::object & aurostd::JSON::object::operator[] ( const char * key) const

direct key access to JSON::object_types::DICTIONARY objects

Definition at line 91 of file aurostd_xparser_json.cpp.

◆ operator=() [1/16]

JSON::object & aurostd::JSON::object::operator= ( const char * content)

assignment operator for char

Definition at line 281 of file aurostd_xparser_json.cpp.

◆ operator=() [2/16]

JSON::object & aurostd::JSON::object::operator= ( const std::string & content)

assignment operator for string

Definition at line 287 of file aurostd_xparser_json.cpp.

◆ operator=() [3/16]

JSON::object & aurostd::JSON::object::operator= ( bool content)

assignment operator for bool

Definition at line 293 of file aurostd_xparser_json.cpp.

◆ operator=() [4/16]

JSON::object & aurostd::JSON::object::operator= ( std::nullptr_t content)

assignment operator for nullptr

Definition at line 303 of file aurostd_xparser_json.cpp.

◆ operator=() [5/16]

JSON::object & aurostd::JSON::object::operator= ( const List & content)

assignment operator for JSON::List

Definition at line 310 of file aurostd_xparser_json.cpp.

◆ operator=() [6/16]

JSON::object & aurostd::JSON::object::operator= ( const Dictionary & content)

assignment operator for JSON::Dictionary

Definition at line 316 of file aurostd_xparser_json.cpp.

◆ operator=() [7/16]

template<class utype, enable_arithmetic< utype > = true>
JSON::object & aurostd::JSON::object::operator= ( utype content)

◆ operator=() [8/16]

template<class utype>
JSON::object & aurostd::JSON::object::operator= ( const xcomplex< utype > & content)

◆ operator=() [9/16]

template<class utype>
JSON::object & aurostd::JSON::object::operator= ( const std::vector< utype > & content)

◆ operator=() [10/16]

template<class utype>
JSON::object & aurostd::JSON::object::operator= ( const std::deque< utype > & content)

◆ operator=() [11/16]

template<class utype>
JSON::object & aurostd::JSON::object::operator= ( const std::map< std::string, utype > & content)

◆ operator=() [12/16]

template<class utype>
JSON::object & aurostd::JSON::object::operator= ( const xvector< utype > & content)

◆ operator=() [13/16]

template<class utype>
JSON::object & aurostd::JSON::object::operator= ( const xmatrix< utype > & content)

◆ operator=() [14/16]

template<class utype>
JSON::object & aurostd::JSON::object::operator= ( const JsonSerializable< utype > & content)

◆ operator=() [15/16]

template<class T, enable_list_like< T > = true>
JSON::object & aurostd::JSON::object::operator= ( const T & content)

◆ operator=() [16/16]

template<class T, enable_dict_like< T > = true>
JSON::object & aurostd::JSON::object::operator= ( const T & content)

◆ operator bool()

aurostd::JSON::object::operator bool ( ) const
explicit

conversion function for bool

Note
for LIST, DICTIONARY and STRING tests emptiness
for NULL returns always false

Definition at line 324 of file aurostd_xparser_json.cpp.

◆ operator std::string()

aurostd::JSON::object::operator std::string ( ) const
explicit

conversion function for string

Definition at line 474 of file aurostd_xparser_json.cpp.

◆ operator double()

aurostd::JSON::object::operator double ( ) const
explicit

conversion function for double

Definition at line 384 of file aurostd_xparser_json.cpp.

◆ operator long double()

aurostd::JSON::object::operator long double ( ) const
explicit

conversion function for float

Definition at line 404 of file aurostd_xparser_json.cpp.

◆ operator float()

aurostd::JSON::object::operator float ( ) const
explicit

conversion function for float

Definition at line 409 of file aurostd_xparser_json.cpp.

◆ operator long long()

aurostd::JSON::object::operator long long ( ) const
explicit

conversion function for long long

Definition at line 414 of file aurostd_xparser_json.cpp.

◆ operator long()

aurostd::JSON::object::operator long ( ) const
explicit

conversion function for long

Definition at line 459 of file aurostd_xparser_json.cpp.

◆ operator int()

aurostd::JSON::object::operator int ( ) const
explicit

conversion function for int

Definition at line 464 of file aurostd_xparser_json.cpp.

◆ operator char()

aurostd::JSON::object::operator char ( ) const
explicit

conversion function for char

Definition at line 469 of file aurostd_xparser_json.cpp.

◆ operator unsigned long long()

aurostd::JSON::object::operator unsigned long long ( ) const
explicit

conversion function for unsigned long long

Definition at line 439 of file aurostd_xparser_json.cpp.

◆ operator unsigned long()

aurostd::JSON::object::operator unsigned long ( ) const
explicit

conversion function for unsigned long

Definition at line 449 of file aurostd_xparser_json.cpp.

◆ operator unsigned int()

aurostd::JSON::object::operator unsigned int ( ) const
explicit

conversion function for int

Definition at line 454 of file aurostd_xparser_json.cpp.

◆ operator List()

aurostd::JSON::object::operator List ( ) const

◆ operator Dictionary()

aurostd::JSON::object::operator Dictionary ( ) const

◆ operator xcomplex< utype >()

template<class utype>
aurostd::JSON::object::operator xcomplex< utype > ( ) const

◆ operator std::vector< utype >()

template<class utype>
aurostd::JSON::object::operator std::vector< utype > ( ) const

◆ operator std::deque< utype >()

template<class utype>
aurostd::JSON::object::operator std::deque< utype > ( ) const

◆ operator std::set< utype >()

template<class utype>
aurostd::JSON::object::operator std::set< utype > ( ) const

◆ operator std::map< std::string, utype >()

template<class utype>
aurostd::JSON::object::operator std::map< std::string, utype > ( ) const

◆ operator aurostd::xvector< utype >()

template<class utype>
aurostd::JSON::object::operator aurostd::xvector< utype > ( ) const

◆ operator aurostd::xmatrix< utype >()

template<class utype>
aurostd::JSON::object::operator aurostd::xmatrix< utype > ( ) const

◆ operator T() [1/3]

template<class T, enable_list_like< T > = true>
aurostd::JSON::object::operator T ( ) const
explicit

◆ operator T() [2/3]

template<class T, enable_dict_like< T > = true>
aurostd::JSON::object::operator T ( ) const
explicit

◆ operator T() [3/3]

template<class T, enable_serializable< T > = true>
aurostd::JSON::object::operator T ( ) const
explicit

◆ push_back()

void aurostd::JSON::object::push_back ( const JSON::object & content) const

allow to append to JSON::object_type::LIST

Definition at line 497 of file aurostd_xparser_json.cpp.

◆ join()

void aurostd::JSON::object::join ( const JSON::object & content) const

allow to merge two dictionaries or lists

Note
keys already stored in the dictionary will be updated

Definition at line 508 of file aurostd_xparser_json.cpp.

◆ size()

size_t aurostd::JSON::object::size ( ) const
nodiscard

gives the size of JSON::object_tpe::LIST, JSON::object_tpe::DICTIONARY or JSON::object_tpe::STRING

Definition at line 527 of file aurostd_xparser_json.cpp.

◆ empty()

bool aurostd::JSON::object::empty ( ) const
nodiscard

checks if JSON::object_tpe::LIST, JSON::object_tpe::DICTIONARY or JSON::object_tpe::STRING is empty

Definition at line 548 of file aurostd_xparser_json.cpp.

◆ count()

size_t aurostd::JSON::object::count ( const std::string & key) const
nodiscard

count the occurrence of key string in a JSON::object_type::DICTIONARY

Definition at line 556 of file aurostd_xparser_json.cpp.

◆ find()

std::map< std::string, JSON::object >::iterator aurostd::JSON::object::find ( const std::string & key) const
nodiscard

returns an iterator to the result of find in JSON::object_type::DICTIONARY

Definition at line 595 of file aurostd_xparser_json.cpp.

◆ find_list()

template<class utype>
std::list< utype >::iterator aurostd::JSON::object::find_list ( const utype & key) const

◆ end()

std::map< std::string, JSON::object >::iterator aurostd::JSON::object::end ( ) const
nodiscard

returns an iterator to the end() of a JSON::object_type::DICTIONARY

Definition at line 569 of file aurostd_xparser_json.cpp.

◆ begin()

std::map< std::string, JSON::object >::iterator aurostd::JSON::object::begin ( ) const
nodiscard

returns an iterator to the begin() of a JSON::object_type::DICTIONARY

Definition at line 582 of file aurostd_xparser_json.cpp.

◆ keys()

std::vector< std::string > aurostd::JSON::object::keys ( ) const
nodiscard

returns a vector of all keys in a JSON::object_type::DICTIONARY

Definition at line 608 of file aurostd_xparser_json.cpp.

◆ fromString()

void aurostd::JSON::object::fromString ( const std::string & content)

change this JSON::object to a JSON::object_types::STRING

Authors
20220926 | Hagen Eckert - created

Definition at line 180 of file aurostd_xparser_json.cpp.

◆ fromList()

void aurostd::JSON::object::fromList ( const List & content)

change this JSON::object to a JSON::object_types::LIST

Authors
20241218 | Scott Thiel - created

Definition at line 190 of file aurostd_xparser_json.cpp.

◆ fromDictionary()

void aurostd::JSON::object::fromDictionary ( const Dictionary & content)

change this JSON::object to a JSON::object_types::DICTIONARY

Authors
20241218 | Scott Thiel - created

Definition at line 200 of file aurostd_xparser_json.cpp.

◆ fromNumber()

template<class utype>
void aurostd::JSON::object::fromNumber ( utype content)

◆ fromComplex()

template<class utype>
void aurostd::JSON::object::fromComplex ( const xcomplex< utype > & content)

◆ fromVector()

template<class utype>
void aurostd::JSON::object::fromVector ( const std::vector< utype > & content)

◆ fromDeque()

template<class utype>
void aurostd::JSON::object::fromDeque ( const std::deque< utype > & content)

◆ fromMap()

template<class utype>
void aurostd::JSON::object::fromMap ( const std::map< std::string, utype > & content)

◆ fromXvector()

template<class utype>
void aurostd::JSON::object::fromXvector ( const xvector< utype > & content)

◆ fromXmatrix()

template<class utype>
void aurostd::JSON::object::fromXmatrix ( const xmatrix< utype > & content)

◆ fromListLike()

template<class T, enable_list_like< T > = true>
void aurostd::JSON::object::fromListLike ( const T & content)

◆ fromDictLike()

template<class T, enable_dict_like< T > = true>
void aurostd::JSON::object::fromDictLike ( const T & content)

◆ toListLike()

template<class T, enable_list_like< T > = true>
T aurostd::JSON::object::toListLike ( ) const

◆ toDictLike()

template<class T, enable_dict_like< T > = true>
T aurostd::JSON::object::toDictLike ( ) const

◆ toString()

std::string aurostd::JSON::object::toString ( bool json_format = true,
bool escape_unicode = true ) const
nodiscard

converts a JSON::object into a string

Parameters
json_formatif true add encapsulate strings in " (default: true)
escape_unicodeif true escape unicode in strings - αβγ becomes \u03b1\u03b2\u03b3 (default: true)
Returns
JSON formatted string
Authors
20220924 | Hagen Eckert - created

Definition at line 107 of file aurostd_xparser_json.cpp.

◆ saveFile()

void aurostd::JSON::object::saveFile ( const std::string & file_path,
compression_type ct = compression_type::None,
bool escape_unicode = true ) const

save JSON::object to file

Parameters
file_pathpath to save to
escape_unicodeif true escape unicode in strings - αβγ becomes \u03b1\u03b2\u03b3 (default: true)
ctcompression type
Authors
20221110 | Hagen Eckert - created

Definition at line 173 of file aurostd_xparser_json.cpp.

Member Data Documentation

◆ type

object_types aurostd::JSON::object::type = object_types::NONE

Definition at line 52 of file aurostd_xparser_json.h.

◆ obj

std::shared_ptr<void> aurostd::JSON::object::obj = nullptr

Definition at line 53 of file aurostd_xparser_json.h.


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