Entity Generator 4.2.0
Composable, deterministic entity generation for C++23
Loading...
Searching...
No Matches
dasmig::json_value Class Reference

A component value as JSON: null, a boolean, an integer, a number, a (UTF-8) string, an array or an object. More...

#include <entitygen.hpp>

Public Types

using array = std::vector< json_value >
 A JSON array.
 
using object = std::vector< std::pair< std::string, json_value > >
 A JSON object, members in order.
 

Public Member Functions

 json_value ()=default
 null.
 
 json_value (std::nullptr_t)
 null. // NOLINT(google-explicit-constructor)
 
 json_value (std::string s)
 A string (UTF-8). // NOLINT(google-explicit-constructor)
 
 json_value (const char *s)
 A string (UTF-8). // NOLINT(google-explicit-constructor)
 
 json_value (array a)
 An array. // NOLINT(google-explicit-constructor)
 
 json_value (object o)
 An object. // NOLINT(google-explicit-constructor)
 
template<std::same_as< bool > B>
 json_value (B b)
 A boolean. Only bool itself: a pointer (such as a wide literal L"...") would otherwise convert and write true.
 
template<std::integral I>
requires (!std::same_as<I, bool>)
 json_value (I n)
 An integer.
 
template<std::floating_point F>
 json_value (F d)
 A number; a non-finite one is null.
 
const array * get_array () const
 The array held, or null when this is not an array.
 
const object * get_object () const
 The object held, or null when this is not an object.
 
object * get_object ()
 The object held, or null when this is not an object.
 
void write (core::json_writer &w) const
 Write this value.
 

Detailed Description

A component value as JSON: null, a boolean, an integer, a number, a (UTF-8) string, an array or an object.

Objects keep their members in the order given. Integers convert implicitly to an integer value, floating-point numbers to a number (non-finite ones are written as null).

See also
component::to_json()

Definition at line 52 of file entitygen.hpp.

Member Typedef Documentation

◆ array

using dasmig::json_value::array = std::vector<json_value>

A JSON array.

Definition at line 55 of file entitygen.hpp.

◆ object

using dasmig::json_value::object = std::vector<std::pair<std::string, json_value> >

A JSON object, members in order.

Definition at line 56 of file entitygen.hpp.

Constructor & Destructor Documentation

◆ json_value() [1/8]

dasmig::json_value::json_value ( std::nullptr_t  )
inline

null. // NOLINT(google-explicit-constructor)

Definition at line 59 of file entitygen.hpp.

◆ json_value() [2/8]

dasmig::json_value::json_value ( std::string  s)
inline

A string (UTF-8). // NOLINT(google-explicit-constructor)

Definition at line 60 of file entitygen.hpp.

◆ json_value() [3/8]

dasmig::json_value::json_value ( const char *  s)
inline

A string (UTF-8). // NOLINT(google-explicit-constructor)

Definition at line 61 of file entitygen.hpp.

◆ json_value() [4/8]

dasmig::json_value::json_value ( array  a)
inline

An array. // NOLINT(google-explicit-constructor)

Definition at line 62 of file entitygen.hpp.

◆ json_value() [5/8]

dasmig::json_value::json_value ( object  o)
inline

An object. // NOLINT(google-explicit-constructor)

Definition at line 63 of file entitygen.hpp.

◆ json_value() [6/8]

template<std::same_as< bool > B>
dasmig::json_value::json_value ( B  b)
inline

A boolean. Only bool itself: a pointer (such as a wide literal L"...") would otherwise convert and write true.

Definition at line 68 of file entitygen.hpp.

◆ json_value() [7/8]

template<std::integral I>
requires (!std::same_as<I, bool>)
dasmig::json_value::json_value ( I  n)
inline

An integer.

Definition at line 73 of file entitygen.hpp.

◆ json_value() [8/8]

template<std::floating_point F>
dasmig::json_value::json_value ( F  d)
inline

A number; a non-finite one is null.

Definition at line 77 of file entitygen.hpp.

Member Function Documentation

◆ get_array()

const array * dasmig::json_value::get_array ( ) const
inline

The array held, or null when this is not an array.

Definition at line 84 of file entitygen.hpp.

◆ get_object() [1/2]

object * dasmig::json_value::get_object ( )
inline

The object held, or null when this is not an object.

Definition at line 88 of file entitygen.hpp.

◆ get_object() [2/2]

const object * dasmig::json_value::get_object ( ) const
inline

The object held, or null when this is not an object.

Definition at line 86 of file entitygen.hpp.

◆ write()

void dasmig::json_value::write ( core::json_writer &  w) const
inline

Write this value.

Parameters
wWriter positioned where a value is allowed.

Definition at line 92 of file entitygen.hpp.


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