JsoNeat
Some JSON parse/iterate C++ classes build on top of Jsmn
Loading...
Searching...
No Matches
jsoneat::JsoNeat< input_type >::Iterator Class Reference

This has iterator functionality, but also provides lots of token related member functions. More...

#include </home/bertw/proj/mcu/libs/mbed-jsoneat/components/jsoneat/include/jsoneat/jsoneat.hh>

Collaboration diagram for jsoneat::JsoNeat< input_type >::Iterator:

Public Types

using iterator_category = std::forward_iterator_tag
 
using difference_type = std::ptrdiff_t
 
using value_type = jsmntok_t
 
using pointer = value_type *
 
using reference = value_type &
 
using container_type = JsoNeat
 

Public Member Functions

 Iterator (pointer ptr, container_type &container)
 
bool value_st_equal (const char *s, jsmntype_t type) const
 Test type and character string of value for being equal.
 
bool value_equals_null () const
 test for value being null pointer
 
bool value_equals_false () const
 test for value being boolean false
 
bool value_equals_true () const
 test for value being boolean true
 
input_type get_json ()
 get json text buffer
 
bool keyIsEqual (const char *key) const
 test if key matches
 
bool keyIsEqual (const char *key, jsmntype_t val_type) const
 test if both key and value-type matches
 
bool keyStartsWith (const char *key) const
 test if key matches
 
bool keyStartsWith (const char *key, jsmntype_t val_type) const
 test if both key and value-type matches
 
template<typename T >
bool getValue (T &dst) const
 Get value.
 
template<typename T >
bool takeValue (T &dst)
 Get value of key/value pair and advance iterator.
 
template<size_t size>
bool getValueAsString (char(&dst)[size]) const
 Get value as string instead of number or boolean.
 
bool getValueAsString (char *dst, size_t size) const
 Get value as string instead of number or boolean.
 
char * getValueAsString () const
 Get value as string null terminated string (in place)
 
template<typename T >
bool getValue (T &dst, const char *key) const
 Get value of key/value pair if key.
 
template<typename T >
bool takeValue (T &dst, const char *key)
 Get value of key/value pair and advance iterator.
 
template<typename T , std::size_t N>
bool takeValueArray (T(&dst)[N], const char *key)
 Get values from array and advance iterator.
 
template<typename T >
bool takeObject (T &dst, const char *key)
 Get object of key/value pair and advance iterator.
 
template<typename T , size_t N>
bool takeObjectArray (T(&dst)[N], const char *key)
 Get objects from array and advance iterator.
 
template<typename T , size_t N>
bool takeObjectArray (std::array< T, N > &dst, const char *key)
 Get objects from array and advance iterator.
 
reference operator* () const
 
pointer operator-> ()
 
Iterator operator+ (int n)
 
Iterator operator- (int n)
 
Iteratoroperator+= (int n)
 
Iteratoroperator-= (int n)
 
Iteratoroperator++ ()
 
Iterator operator++ (int)
 
reference operator[] (int idx)
 
 operator bool () const
 
bool skip_value ()
 skip this value (of an array)
 
bool skip_key_and_value ()
 skip this key/value pair (in and object)
 
bool skip_key ()
 skip this key
 

Friends

bool operator== (const Iterator &a, const Iterator &b)
 
bool operator!= (const Iterator &a, const Iterator &b)
 
bool operator< (const Iterator &a, const Iterator &b)
 
bool operator> (const Iterator &a, const Iterator &b)
 

Detailed Description

template<typename input_type = const char*>
class jsoneat::JsoNeat< input_type >::Iterator

This has iterator functionality, but also provides lots of token related member functions.

   With Jsmn, the token holds indexes of the original JSON buffer.
   Like a normal iterator, this struct holds a pointer to the token, which is an element of \ref m_tok_arr

   To access the actual JSON data (\ref m_json in class \ref JsoNeat), \ref m_container in this struct holds a
   references, which then can also be used to call member functions of JsoNeat object.

Member Function Documentation

◆ getValue() [1/2]

template<typename input_type = const char*>
template<typename T >
bool jsoneat::JsoNeat< input_type >::Iterator::getValue ( T &  dst) const
inline

Get value.

Parameters
dstvalue will be written to dst
Returns
false if value type is not JSMN_PRIMITIVE Or JSMN_STRING

◆ getValue() [2/2]

template<typename input_type = const char*>
template<typename T >
bool jsoneat::JsoNeat< input_type >::Iterator::getValue ( T &  dst,
const char *  key 
) const
inline

Get value of key/value pair if key.

Parameters
keykey to match or nullptr to match any key
dstvalue will be written to dst
Returns
false if key does not match, or value type is not JSMN_PRIMITIVE or JSMN_STRING

◆ getValueAsString() [1/3]

template<typename input_type = const char*>
char * jsoneat::JsoNeat< input_type >::Iterator::getValueAsString ( ) const
inline

Get value as string null terminated string (in place)

          This works only for non constant input_type, because it writes
          into the json text buffer to terminate strings.
Returns
pointer to null terminated string. If not JSMN_STRING or JSMN_PRIMITIVE it returns null

◆ getValueAsString() [2/3]

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::getValueAsString ( char *  dst,
size_t  size 
) const
inline

Get value as string instead of number or boolean.

Parameters
dstvalue will be written to dst
sizespace available in dst
Returns
false if value type is not JSMN_PRIMITIVE Or JSMN_STRING

◆ getValueAsString() [3/3]

template<typename input_type = const char*>
template<size_t size>
bool jsoneat::JsoNeat< input_type >::Iterator::getValueAsString ( char(&)  dst[size]) const
inline

Get value as string instead of number or boolean.

Parameters
dstvalue will be written to dst
Returns
false if value type is not JSMN_PRIMITIVE Or JSMN_STRING

◆ keyIsEqual() [1/2]

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::keyIsEqual ( const char *  key) const
inline

test if key matches

Parameters
keykey to match
Returns
false if key does not match or type is not JSMN_STRING
Here is the caller graph for this function:

◆ keyIsEqual() [2/2]

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::keyIsEqual ( const char *  key,
jsmntype_t  val_type 
) const
inline

test if both key and value-type matches

Parameters
keystring to match key or nullptr to match any key
val_typetype of value to match
Returns
false for mismatch or key type not JSMN_STRING
Here is the call graph for this function:

◆ keyStartsWith() [1/2]

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::keyStartsWith ( const char *  key) const
inline

test if key matches

Parameters
keykey to match
Returns
false if key does not match or type is not JSMN_STRING
Here is the caller graph for this function:

◆ keyStartsWith() [2/2]

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::keyStartsWith ( const char *  key,
jsmntype_t  val_type 
) const
inline

test if both key and value-type matches

Parameters
keystring to match key or nullptr to match any key
val_typetype of value to match
Returns
false for mismatch or key type not JSMN_STRING
Here is the call graph for this function:

◆ skip_key()

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::skip_key ( )
inline

skip this key

Returns
success.
Here is the caller graph for this function:

◆ skip_key_and_value()

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::skip_key_and_value ( )
inline

skip this key/value pair (in and object)

Returns
success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ skip_value()

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::skip_value ( )
inline

skip this value (of an array)

Returns
success.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ takeObject()

template<typename input_type = const char*>
template<typename T >
bool jsoneat::JsoNeat< input_type >::Iterator::takeObject ( T &  dst,
const char *  key 
)
inline

Get object of key/value pair and advance iterator.

Parameters
keykey to match or nullptr to match any key
dstobject will be written to dst
Returns
false if key does not match, or value type is not JSMN_OBJECT
Here is the call graph for this function:

◆ takeObjectArray() [1/2]

template<typename input_type = const char*>
template<typename T , size_t N>
bool jsoneat::JsoNeat< input_type >::Iterator::takeObjectArray ( std::array< T, N > &  dst,
const char *  key 
)
inline

Get objects from array and advance iterator.

Template Parameters
Ttype of array members
Narray_size
Parameters
keykey to match or nullptr to match any key
dstobjects will be written to array dst
Returns
success
Here is the call graph for this function:

◆ takeObjectArray() [2/2]

template<typename input_type = const char*>
template<typename T , size_t N>
bool jsoneat::JsoNeat< input_type >::Iterator::takeObjectArray ( T(&)  dst[N],
const char *  key 
)
inline

Get objects from array and advance iterator.

Template Parameters
Ttype of array members
Narray_size
Parameters
keykey to match or nullptr to match any key
dstobjects will be written to array dst
Returns
success
Here is the call graph for this function:

◆ takeValue() [1/2]

template<typename input_type = const char*>
template<typename T >
bool jsoneat::JsoNeat< input_type >::Iterator::takeValue ( T &  dst)
inline

Get value of key/value pair and advance iterator.

Parameters
dstvalue will be written to dst
Returns
false if value type is not JSMN_PRIMITIVE Or JSMN_STRING

◆ takeValue() [2/2]

template<typename input_type = const char*>
template<typename T >
bool jsoneat::JsoNeat< input_type >::Iterator::takeValue ( T &  dst,
const char *  key 
)
inline

Get value of key/value pair and advance iterator.

Parameters
keykey to match or nullptr to match any key
dstvalue will be written to dst
Returns
false if key does not match, or value type is not JSMN_PRIMITIVE or JSMN_STRING

◆ takeValueArray()

template<typename input_type = const char*>
template<typename T , std::size_t N>
bool jsoneat::JsoNeat< input_type >::Iterator::takeValueArray ( T(&)  dst[N],
const char *  key 
)
inline

Get values from array and advance iterator.

Template Parameters
Ttype of array members
Narray_size
Parameters
keykey to match or nullptr to match any key
dstvalues will be written to array dst
Returns
success
Here is the call graph for this function:

◆ value_equals_false()

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::value_equals_false ( ) const
inline

test for value being boolean false

Returns
true for match

◆ value_equals_null()

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::value_equals_null ( ) const
inline

test for value being null pointer

Returns
true for match

◆ value_equals_true()

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::value_equals_true ( ) const
inline

test for value being boolean true

Returns
true for match

◆ value_st_equal()

template<typename input_type = const char*>
bool jsoneat::JsoNeat< input_type >::Iterator::value_st_equal ( const char *  s,
jsmntype_t  type 
) const
inline

Test type and character string of value for being equal.

Parameters
sexpected string
typeexpected type
Returns
true for match

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