Replace #include <stdio.h> with #include <cstdio> to solve gcc4mbed compiler problem

Fork of MbedJSONValue by Samuel Mokrani

Embed: (wiki syntax)

« Back to documentation index

MbedJSONValue Class Reference

MbedJSONValue Class Reference

MbedJSONValue class. More...

#include <MbedJSONValue.h>

Public Types

enum  Type {
  TypeNull, TypeBoolean, TypeInt, TypeDouble,
  TypeString, TypeArray, TypeObject
}
 

All types which can be used.

More...

Public Member Functions

 MbedJSONValue ()
 MbedJSONValue constructor of type TypeNull.
 MbedJSONValue (bool value)
 MbedJSONValue constructor of type TypeBoolean.
 MbedJSONValue (int value)
 MbedJSONValue constructor of type TypeInt.
 MbedJSONValue (double value)
 MbedJSONValue constructor of type TypeDouble.
 MbedJSONValue (std::string const &value)
 MbedJSONValue constructor of type TypeString.
 MbedJSONValue (const char *value)
 MbedJSONValue constructor of type TypeString.
 MbedJSONValue (MbedJSONValue const &rhs)
 Copy constructor.
 ~MbedJSONValue ()
 Destructor.
MbedJSONValueoperator= (MbedJSONValue const &rhs)
 = Operator overloading for an MbedJSONValue from an MbedJSONValue
MbedJSONValueoperator= (int const &rhs)
 = Operator overloading for an MbedJSONValue from an int
MbedJSONValueoperator= (bool const &rhs)
 = Operator overloading for an MbedJSONValue from a boolean
MbedJSONValueoperator= (double const &rhs)
 = Operator overloading for an MbedJSONValue from a double
MbedJSONValueoperator= (const char *rhs)
 = Operator overloading for an MbedJSONValue from a string
MbedJSONValueoperator[] (int i)
 [] Operator overloading for an MbedJSONValue.
MbedJSONValueoperator[] (std::string str)
 [] Operator overloading for an MbedJSONValue.
template<typename T >
const T & get () const
 Retrieve the value of an MbedJSONValue object.
template<typename T >
T & get ()
 Retrieve the value of an MbedJSONValue object.
Type const & getType () const
 Return the type of the MbedJSONValue object.
int size () const
 Return the size of an MbedJSONValue object (works for TypeString, TypeArray or TypeObject)
bool hasMember (char *name)
 Check for the existence in a TypeObject object of member identified by name.
std::string serialize ()
 Convert an MbedJSONValue in a JSON frame.

Detailed Description

MbedJSONValue class.

Example:

  • creation of an MbedJSONValue of type TypeObject containing two others MbedJSONValue: -one array of one string and one integer identified by "my_array" -a boolean identified by "my_boolean"
  • serialization in JSON format of this object
     #include "mbed.h"
     #include "MbedJSONValue.h"
     #include <string>
    
     int main() {          
    
       MbedJSONValue demo;
       std::string s;
    
       //fill the object
       demo["my_array"][0] = "demo_string";
       demo["my_array"][1] = 10;
       demo["my_boolean"] = false;
    
       //serialize it into a JSON string
       s = demo.serialize();
       printf("json: %s\r\n", s.c_str());
     }
    

Example:

  • creation of an MbedJSONValue from a JSON string
  • extraction of different values from this existing MbedJSONValue
     #include "mbed.h"
     #include "MbedJSONValue.h"
     #include <string>
    
     int main() {     
        MbedJSONValue demo;
    
       const  char * json = "{\"my_array\": [\"demo_string\", 10], \"my_boolean\": true}";
    
       //parse the previous string and fill the object demo
       parse(demo, json);
    
       std::string my_str;
       int my_int;
       bool my_bool;
    
       my_str = demo["my_array"][0].get<std::string>();
       my_int = demo["my_array"][1].get<int>();
       my_bool = demo["my_boolean"].get<bool>();
       
        printf("my_str: %s\r\n", my_str.c_str());
        printf("my_int: %d\r\n", my_int);
        printf("my_bool: %s\r\n", my_bool ? "true" : "false");
     }
    

Definition at line 101 of file MbedJSONValue.h.


Member Enumeration Documentation

enum Type

All types which can be used.

Enumerator:
TypeNull 

Null type

TypeBoolean 

Boolean

TypeInt 

Integer

TypeDouble 

Double

TypeString 

String

TypeArray 

Array (contains MbedJSONValue)

TypeObject 

Object (contains MbedJSONValue identified by a name)

Definition at line 108 of file MbedJSONValue.h.


Constructor & Destructor Documentation

MbedJSONValue constructor of type TypeNull.

Definition at line 121 of file MbedJSONValue.h.

MbedJSONValue ( bool  value )

MbedJSONValue constructor of type TypeBoolean.

Parameters:
valuethe object created will be initialized with this boolean

Definition at line 128 of file MbedJSONValue.h.

MbedJSONValue ( int  value )

MbedJSONValue constructor of type TypeInt.

Parameters:
valuethe object created will be initialized with this integer

Definition at line 137 of file MbedJSONValue.h.

MbedJSONValue ( double  value )

MbedJSONValue constructor of type TypeDouble.

Parameters:
valuethe object created will be initialized with this double

Definition at line 146 of file MbedJSONValue.h.

MbedJSONValue ( std::string const &  value )

MbedJSONValue constructor of type TypeString.

Parameters:
valuethe object created will be initialized with this string

Definition at line 155 of file MbedJSONValue.h.

MbedJSONValue ( const char *  value )

MbedJSONValue constructor of type TypeString.

Parameters:
valuethe object created will be initialized with this string

Definition at line 164 of file MbedJSONValue.h.

MbedJSONValue ( MbedJSONValue const &  rhs )

Copy constructor.

Parameters:
rhsobject which will be copied

Definition at line 173 of file MbedJSONValue.h.

~MbedJSONValue (  )

Destructor.

Definition at line 178 of file MbedJSONValue.h.


Member Function Documentation

T& get (  )

Retrieve the value of an MbedJSONValue object.

Let's suppose that we have an MbedJSONValue of type TypeInt. To retrieve this integer, you have to do: my_obj.get<int>();

Returns:
A reference on the value of the object
const T& get (  ) const

Retrieve the value of an MbedJSONValue object.

Let's suppose that we have an MbedJSONValue of type TypeString. To retrieve this string, you have to do: my_obj.get<std::string>();

Returns:
A contant reference on the value of the object
Type const& getType (  ) const

Return the type of the MbedJSONValue object.

Returns:
type of the MbedJSONValue object

Definition at line 270 of file MbedJSONValue.h.

bool hasMember ( char *  name )

Check for the existence in a TypeObject object of member identified by name.

Parameters:
nameIdentifier
Returns:
true if the object is of type TypeObject AND contains a member named "name", false otherwise

Definition at line 31 of file MbedJSONValue.cpp.

MbedJSONValue & operator= ( MbedJSONValue const &  rhs )

= Operator overloading for an MbedJSONValue from an MbedJSONValue

Parameters:
rhsobject
Returns:
a reference on the MbedJSONValue affected

Definition at line 200 of file MbedJSONValue.cpp.

MbedJSONValue& operator= ( double const &  rhs )

= Operator overloading for an MbedJSONValue from a double

Parameters:
rhsdouble
Returns:
a reference on the MbedJSONValue affected

Definition at line 210 of file MbedJSONValue.h.

MbedJSONValue& operator= ( int const &  rhs )

= Operator overloading for an MbedJSONValue from an int

Parameters:
rhsinteger
Returns:
a reference on the MbedJSONValue affected

Definition at line 194 of file MbedJSONValue.h.

MbedJSONValue& operator= ( const char *  rhs )

= Operator overloading for an MbedJSONValue from a string

Parameters:
rhsstring
Returns:
a reference on the MbedJSONValue affected

Definition at line 218 of file MbedJSONValue.h.

MbedJSONValue& operator= ( bool const &  rhs )

= Operator overloading for an MbedJSONValue from a boolean

Parameters:
rhsboolean
Returns:
a reference on the MbedJSONValue affected

Definition at line 202 of file MbedJSONValue.h.

MbedJSONValue & operator[] ( int  i )

[] Operator overloading for an MbedJSONValue.

Each TypeObject object can contain an array of NB_TOKEN MbedJSONValue. This operator is useful to create an array or to retrieve an MbedJSONValue of an existing array.

Parameters:
iindex of the array
Returns:
a reference on the MbedJSONValue created or retrieved

Definition at line 137 of file MbedJSONValue.cpp.

MbedJSONValue & operator[] ( std::string  str )

[] Operator overloading for an MbedJSONValue.

Each TypeObject MbedJSONValue can contain NB_TOKEN MbedJSONValue IDENTIFIED BY A NAME This operator is useful to create a TypeObject MbedJSONValue or to retrieve an MbedJSONValue of an existing TypeObject.

Parameters:
stridentifier of the sub MbedJSONValue
Returns:
a reference on the MbedJSONValue created or retrieved

Definition at line 154 of file MbedJSONValue.cpp.

std::string serialize (  )

Convert an MbedJSONValue in a JSON frame.

Returns:
JSON string

Definition at line 72 of file MbedJSONValue.cpp.

int size (  ) const

Return the size of an MbedJSONValue object (works for TypeString, TypeArray or TypeObject)

Returns:
size

Definition at line 232 of file MbedJSONValue.cpp.