Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
sajson::value Class Reference

#include <sajson.h>

Public Member Functions

const char * as_cstring () const
 
std::string as_string () const
 
size_t find_object_key (const string &key) const
 
value get_array_element (size_t index) const
 
double get_double_value () const
 
bool get_int53_value (int64_t *out) const
 
int get_integer_value () const
 
size_t get_length () const
 
double get_number_value () const
 
string get_object_key (size_t index) const
 
value get_object_value (size_t index) const
 
size_t get_string_length () const
 
type get_type () const
 Returns the JSON value's type. More...
 
value get_value_of_key (const string &key) const
 

Private Member Functions

void assert_in_bounds (size_t i) const
 
void assert_type (type expected) const
 
void assert_type_2 (type e1, type e2) const
 
 value (type value_type_, const size_t *payload_, const char *text_)
 

Private Attributes

const size_t *const payload
 
const char *const text
 
const type value_type
 

Friends

class document
 

Detailed Description

Represents a JSON value. First, call get_type() to check its type, which determines which methods are available.

Note that value does not maintain any backing memory, only the corresponding document does. It is illegal to access a value after its document has been destroyed.

Definition at line 448 of file sajson.h.

Constructor & Destructor Documentation

◆ value()

sajson::value::value ( type  value_type_,
const size_t *  payload_,
const char *  text_ 
)
inlineexplicitprivate

Definition at line 617 of file sajson.h.

Member Function Documentation

◆ as_cstring()

const char* sajson::value::as_cstring ( ) const
inline

Returns a pointer to the beginning of a string value's data. WARNING: Calling this function and using the return value as a C-style string (that is, without also using get_string_length()) will cause the string to appear truncated if the string has embedded NULs. Only legal if get_type() is TYPE_STRING.

Definition at line 596 of file sajson.h.

◆ as_string()

std::string sajson::value::as_string ( ) const
inline

Returns a string's value as a std::string. Only legal if get_type() is TYPE_STRING.

Definition at line 604 of file sajson.h.

◆ assert_in_bounds()

void sajson::value::assert_in_bounds ( size_t  i) const
inlineprivate

Definition at line 631 of file sajson.h.

◆ assert_type()

void sajson::value::assert_type ( type  expected) const
inlineprivate

Definition at line 623 of file sajson.h.

◆ assert_type_2()

void sajson::value::assert_type_2 ( type  e1,
type  e2 
) const
inlineprivate

Definition at line 627 of file sajson.h.

◆ find_object_key()

size_t sajson::value::find_object_key ( const string key) const
inline

Given a string key, returns the index of the associated value if one exists. Returns get_length() if there is no such key. Note: sajson sorts object keys, so the running time is O(lg N). Only legal if get_type() is TYPE_OBJECT

Definition at line 507 of file sajson.h.

◆ get_array_element()

value sajson::value::get_array_element ( size_t  index) const
inline

Returns the nth element of an array. Calling with an out-of-bound index is undefined behavior. Only legal if get_type() is TYPE_ARRAY.

Definition at line 465 of file sajson.h.

◆ get_double_value()

double sajson::value::get_double_value ( ) const
inline

If a numeric value was parsed as a double, returns it. Only legal if get_type() is TYPE_DOUBLE.

Definition at line 534 of file sajson.h.

◆ get_int53_value()

bool sajson::value::get_int53_value ( int64_t *  out) const
inline

Returns true and writes to the output argument if the numeric value fits in a 53-bit integer. This is useful for timestamps and other situations where integral values with greater than 32-bit precision are used, as 64-bit values are not understood by all JSON implementations or languages. Returns false if the value is not an integer or not in range. Only legal if get_type() is TYPE_INTEGER or TYPE_DOUBLE.

Definition at line 557 of file sajson.h.

◆ get_integer_value()

int sajson::value::get_integer_value ( ) const
inline

If a numeric value was parsed as a 32-bit integer, returns it. Only legal if get_type() is TYPE_INTEGER.

Definition at line 527 of file sajson.h.

◆ get_length()

size_t sajson::value::get_length ( ) const
inline

Returns the length of the object or array. Only legal if get_type() is TYPE_ARRAY or TYPE_OBJECT.

Definition at line 457 of file sajson.h.

◆ get_number_value()

double sajson::value::get_number_value ( ) const
inline

Returns a numeric value as a double-precision float. Only legal if get_type() is TYPE_INTEGER or TYPE_DOUBLE.

Definition at line 541 of file sajson.h.

◆ get_object_key()

string sajson::value::get_object_key ( size_t  index) const
inline

Returns the nth key of an object. Calling with an out-of-bound index is undefined behavior. Only legal if get_type() is TYPE_OBJECT.

Definition at line 475 of file sajson.h.

◆ get_object_value()

value sajson::value::get_object_value ( size_t  index) const
inline

Returns the nth value of an object. Calling with an out-of-bound index is undefined behavior. Only legal if get_type() is TYPE_OBJECT.

Definition at line 483 of file sajson.h.

◆ get_string_length()

size_t sajson::value::get_string_length ( ) const
inline

Returns the length of the string. Only legal if get_type() is TYPE_STRING.

Definition at line 585 of file sajson.h.

◆ get_type()

type sajson::value::get_type ( ) const
inline

Returns the JSON value's type.

Definition at line 451 of file sajson.h.

◆ get_value_of_key()

value sajson::value::get_value_of_key ( const string key) const
inline

Given a string key, returns the value with that key or a null value if the key is not found. Running time is O(lg N). Only legal if get_type() is TYPE_OBJECT.

Definition at line 493 of file sajson.h.

Friends And Related Function Documentation

◆ document

friend class document
friend

Definition at line 639 of file sajson.h.

Member Data Documentation

◆ payload

const size_t* const sajson::value::payload
private

Definition at line 636 of file sajson.h.

◆ text

const char* const sajson::value::text
private

Definition at line 637 of file sajson.h.

◆ value_type

const type sajson::value::value_type
private

Definition at line 635 of file sajson.h.


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


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:23