3D Forest
Software for analysis of Lidar data from forest environment.
Json Class Reference

#include <Json.hpp>

Classes

class  Data
 

Public Member Functions

 Json ()
 
 ~Json ()=default
 
 Json (bool in)
 
 Json (int in)
 
 Json (unsigned int in)
 
 Json (double in)
 
 Json (long in)
 
 Json (unsigned long in)
 
 Json (long long in)
 
 Json (unsigned long long in)
 
 Json (const char *in)
 
 Json (const std::string &in)
 
 Json (const std::vector< double > &in)
 
void clear ()
 
bool contains (const std::string &key) const
 
bool containsObject (const std::string &key) const
 
bool containsArray (const std::string &key) const
 
bool containsString (const std::string &key) const
 
bool containsNumber (const std::string &key) const
 
bool containsBool (const std::string &key) const
 
Jsonoperator[] (const std::string &key)
 
const Jsonoperator[] (const std::string &key) const
 
size_t size () const
 
Jsonoperator[] (size_t index)
 
const Jsonoperator[] (size_t index) const
 
const std::map< std::string, Json > & object () const
 
const std::vector< Json > & array () const
 
const std::string & string () const
 
double number () const
 
uint32_t uint32 () const
 
uint64_t uint64 () const
 
bool typeObject () const
 
bool typeArray () const
 
bool typeString () const
 
bool typeNumber () const
 
bool typeTrue () const
 
bool typeFalse () const
 
bool typeNull () const
 
std::string serialize (size_t indent=DEFAULT_INDENT) const
 
void deserialize (const std::string &in)
 
void deserialize (const char *in, size_t n)
 
void read (const std::string &fileName)
 
void write (const std::string &fileName, size_t indent=DEFAULT_INDENT)
 

Static Public Attributes

static const size_t DEFAULT_INDENT = 2
 

Private Types

enum  Type {
  TYPE_OBJECT , TYPE_ARRAY , TYPE_STRING , TYPE_NUMBER ,
  TYPE_TRUE , TYPE_FALSE , TYPE_NULL
}
 

Private Member Functions

void createObject ()
 
void createArray ()
 
void createArray (const std::vector< double > &in)
 
void createString (const std::string &in)
 
void createNumber (double in)
 
void createType (Type t)
 
void serialize (std::ostringstream &out) const
 
void serialize (std::ostringstream &out, const std::string &indent, const std::string &indentPlus) const
 
void deserialize (Json &obj, const char *in, size_t n, size_t &i)
 

Private Attributes

Type type_
 
Data data_
 

Friends

void fromJson (bool &out, const Json &in)
 
void fromJson (int &out, const Json &in)
 
void fromJson (unsigned int &out, const Json &in)
 
void fromJson (double &out, const Json &in)
 
void fromJson (long &out, const Json &in)
 
void fromJson (unsigned long &out, const Json &in)
 
void fromJson (long long &out, const Json &in)
 
void fromJson (unsigned long long &out, const Json &in)
 
void fromJson (std::string &out, const Json &in)
 
void toJson (Json &out, bool in)
 
void toJson (Json &out, int in)
 
void toJson (Json &out, unsigned int in)
 
void toJson (Json &out, double in)
 
void toJson (Json &out, long in)
 
void toJson (Json &out, unsigned long in)
 
void toJson (Json &out, long long in)
 
void toJson (Json &out, unsigned long long in)
 
void toJson (Json &out, const std::string &in)
 

Detailed Description

example deserialize:

Json obj;
obj.deserialize("{\"a\":5}");
std::cout << obj["a"].typeNumber() << "\n"; // 1
std::cout << obj["a"].number() << "\n"; // 5
JSON.
Definition Json.hpp:93
double number() const
Definition Json.hpp:488
bool typeNumber() const
Definition Json.hpp:144
void deserialize(const std::string &in)
Definition Json.cpp:78
example number:
Json obj;
obj["a"] = 5;
obj["b"] = 3.14;
std::cout << obj.serialize(0) << "\n"; // {"a":5,"b":3.14}
std::string serialize(size_t indent=DEFAULT_INDENT) const
Definition Json.cpp:56
example string:
Json obj;
obj["name"] = "John";
std::cout << obj["name"].typeString() << "\n"; // 1
std::cout << obj["name"].string() << "\n"; // John
std::cout << obj.serialize(0) << "\n"; // {"name":"John"}
bool typeString() const
Definition Json.hpp:143
const std::string & string() const
Definition Json.hpp:478
example array:
Json obj;
obj["dim"][0] = 10;
obj["dim"][1] = 20;
obj["scale"] = std::vector<double>{ 1, 2, 3 };
std::cout << obj.typeObject() << "\n"; // 1
std::cout << obj["dim"].typeArray() << "\n"; // 1
std::cout << obj["dim"].size() << "\n"; // 2
std::cout << obj["dim"][0].number() << "\n"; // 10
std::cout << obj["dim"][1].number() << "\n"; // 20
double area = 1.;
for (auto const &it : obj["dim"].array())
{
area *= it.number();
}
std::cout << area << "\n"; // 200
std::cout << obj.serialize(0) << "\n"; // {"dim":[10,20],"scale":[1,2,3]}
const std::vector< Json > & array() const
Definition Json.hpp:468
bool typeObject() const
Definition Json.hpp:141
bool typeArray() const
Definition Json.hpp:142
size_t size() const
Definition Json.hpp:418

Member Enumeration Documentation

◆ Type

enum Json::Type
private

JSON Data Type.

Enumerator
TYPE_OBJECT 
TYPE_ARRAY 
TYPE_STRING 
TYPE_NUMBER 
TYPE_TRUE 
TYPE_FALSE 
TYPE_NULL 

Constructor & Destructor Documentation

◆ Json() [1/12]

Json::Json ( )
inline

Referenced by operator[]().

◆ ~Json()

Json::~Json ( )
default

◆ Json() [2/12]

Json::Json ( bool in)
inline

◆ Json() [3/12]

Json::Json ( int in)
inline

◆ Json() [4/12]

Json::Json ( unsigned int in)
inline

◆ Json() [5/12]

Json::Json ( double in)
inline

◆ Json() [6/12]

Json::Json ( long in)
inline

◆ Json() [7/12]

Json::Json ( unsigned long in)
inline

◆ Json() [8/12]

Json::Json ( long long in)
inline

◆ Json() [9/12]

Json::Json ( unsigned long long in)
inline

◆ Json() [10/12]

Json::Json ( const char * in)
inline

◆ Json() [11/12]

Json::Json ( const std::string & in)
inline

◆ Json() [12/12]

Json::Json ( const std::vector< double > & in)
inline

Member Function Documentation

◆ array()

const std::vector< Json > & Json::array ( ) const
inline

◆ clear()

void Json::clear ( )

◆ contains()

bool Json::contains ( const std::string & key) const
inline

Referenced by Editor::openProject().

◆ containsArray()

bool Json::containsArray ( const std::string & key) const
inline

◆ containsBool()

bool Json::containsBool ( const std::string & key) const
inline

◆ containsNumber()

bool Json::containsNumber ( const std::string & key) const
inline

◆ containsObject()

bool Json::containsObject ( const std::string & key) const
inline

◆ containsString()

bool Json::containsString ( const std::string & key) const
inline

◆ createArray() [1/2]

void Json::createArray ( )
inlineprivate

◆ createArray() [2/2]

void Json::createArray ( const std::vector< double > & in)
inlineprivate

◆ createNumber()

void Json::createNumber ( double in)
inlineprivate

◆ createObject()

void Json::createObject ( )
inlineprivate

Referenced by deserialize(), and operator[]().

◆ createString()

void Json::createString ( const std::string & in)
inlineprivate

Referenced by deserialize(), Json(), and Json().

◆ createType()

void Json::createType ( Type t)
inlineprivate

Referenced by deserialize(), Json(), and Json().

◆ deserialize() [1/3]

void Json::deserialize ( const char * in,
size_t n )

◆ deserialize() [2/3]

void Json::deserialize ( const std::string & in)

◆ deserialize() [3/3]

void Json::deserialize ( Json & obj,
const char * in,
size_t n,
size_t & i )
private

◆ number()

double Json::number ( ) const
inline

◆ object()

const std::map< std::string, Json > & Json::object ( ) const
inline

◆ operator[]() [1/4]

Json & Json::operator[] ( const std::string & key)
inline

◆ operator[]() [2/4]

const Json & Json::operator[] ( const std::string & key) const
inline

◆ operator[]() [3/4]

Json & Json::operator[] ( size_t index)
inline

◆ operator[]() [4/4]

const Json & Json::operator[] ( size_t index) const
inline

◆ read()

void Json::read ( const std::string & fileName)

Referenced by Editor::openProject().

◆ serialize() [1/3]

std::string Json::serialize ( size_t indent = DEFAULT_INDENT) const

Referenced by serialize(), and write().

◆ serialize() [2/3]

void Json::serialize ( std::ostringstream & out) const
private

◆ serialize() [3/3]

void Json::serialize ( std::ostringstream & out,
const std::string & indent,
const std::string & indentPlus ) const
private

◆ size()

size_t Json::size ( ) const
inline

◆ string()

const std::string & Json::string ( ) const
inline

◆ typeArray()

bool Json::typeArray ( ) const
inline

Referenced by array(), operator[](), operator[](), and size().

◆ typeFalse()

bool Json::typeFalse ( ) const
inline

◆ typeNull()

bool Json::typeNull ( ) const
inline

◆ typeNumber()

bool Json::typeNumber ( ) const
inline

Referenced by number(), uint32(), and uint64().

◆ typeObject()

◆ typeString()

bool Json::typeString ( ) const
inline

Referenced by string().

◆ typeTrue()

bool Json::typeTrue ( ) const
inline

◆ uint32()

uint32_t Json::uint32 ( ) const
inline

◆ uint64()

uint64_t Json::uint64 ( ) const
inline

◆ write()

void Json::write ( const std::string & fileName,
size_t indent = DEFAULT_INDENT )

Friends And Related Symbol Documentation

◆ fromJson [1/9]

void fromJson ( bool & out,
const Json & in )
friend

◆ fromJson [2/9]

void fromJson ( double & out,
const Json & in )
friend

◆ fromJson [3/9]

void fromJson ( int & out,
const Json & in )
friend

◆ fromJson [4/9]

void fromJson ( long & out,
const Json & in )
friend

◆ fromJson [5/9]

void fromJson ( long long & out,
const Json & in )
friend

◆ fromJson [6/9]

void fromJson ( std::string & out,
const Json & in )
friend

◆ fromJson [7/9]

void fromJson ( unsigned int & out,
const Json & in )
friend

◆ fromJson [8/9]

void fromJson ( unsigned long & out,
const Json & in )
friend

◆ fromJson [9/9]

void fromJson ( unsigned long long & out,
const Json & in )
friend

◆ toJson [1/9]

void toJson ( Json & out,
bool in )
friend

◆ toJson [2/9]

void toJson ( Json & out,
const std::string & in )
friend

◆ toJson [3/9]

void toJson ( Json & out,
double in )
friend

◆ toJson [4/9]

void toJson ( Json & out,
int in )
friend

◆ toJson [5/9]

void toJson ( Json & out,
long in )
friend

◆ toJson [6/9]

void toJson ( Json & out,
long long in )
friend

◆ toJson [7/9]

void toJson ( Json & out,
unsigned int in )
friend

◆ toJson [8/9]

void toJson ( Json & out,
unsigned long in )
friend

◆ toJson [9/9]

void toJson ( Json & out,
unsigned long long in )
friend

Member Data Documentation

◆ data_

◆ DEFAULT_INDENT

const size_t Json::DEFAULT_INDENT = 2
static

◆ type_


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