Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

JsonIO and Jsonize framework

 

class JsonIO

JsonIO represents a single JSON value in Jsonize framework. It is used as parameter for Jsonize global function. Jsonize global function has default templated definition that in turn calls Jsonize method of object. However, when implementation using method is not possible (e.g. for supported primitive types), global templated specialization of Jsonize can be used.

 

 

Public Method List

 

bool IsLoading() const

Returns true when retrieving data from JSON.

 


 

bool IsStoring() const

Returns true when storing data to JSON.

 


 

const Value& Get() const

Returns the value of JSON node when loading.

 


 

void Set(const Value& v)

Sets the value of JSON node when storing.

 


 

void Put(Value& v)

Retrieves JSON node data into v when storing - invoked to finish jsonization.

 


 

Value GetResult() const

Returns JSON node data into v when storing - invoked to finish jsonization.

 


 

template <class TJsonIO& operator()(const char *key, T& value)

Sets the JsonIO to represent JSON object (if it does not already), creates member key and jsonizes value into it (by calling global Jsonize function, whose general form invokes Jsonize method)..

 


 

JsonIO(const Value& src)

Sets JsonIO for retrieving data from src which is must be Json compatible Value.

 


 

JsonIO()

Creates JsonIO for storing data.

 

 

Jsonize Store/Load functions

 

template <class TValue StoreAsJsonValue(const T& var)

Converts var into JSON compatible Value (such that can be directly used with AsJson function).

 


 

template <class Tvoid LoadFromJsonValue(T& var, const Value& x)

Retrieves variable from JSON compatible Value. Can throw JsonizeError on error.

 


 

template <class TString StoreAsJson(const T& var, bool pretty = false)

Converts var into JSON text. If pretty is true, adds whitespaces to look better, otherwise the result is as compact as possible.

 


 

template <class Tbool LoadFromJson(T& var, const char *json)

Retrieves var from json text. Does not throw JsonizeError, returns false in case of error.

 


 

template <class Tbool StoreAsJsonFile(const T& var, const char *file = NULL, bool pretty = false)

Converts var into JSON file. If pretty is true, adds whitespaces to look better, otherwise the result is as compact as possible. If file is NULL, ConfigFile(GetExeTitle() + ".json") is used as the file path.

 


 

template <class Tbool LoadFromJsonFile(T& var, const char *file = NULL)

Retrieves var from json file. Does not throw JsonizeError, returns false in case of error. If file is NULL, ConfigFile(GetExeTitle() + ".json") is used as the file path.

 

 

Standard Jsonize template specializations

 

template <> void Jsonize(JsonIO& io, int& var)

template <> void Jsonize(JsonIO& io, int16& var)

template <> void Jsonize(JsonIO& io, int64& var)

template <> void Jsonize(JsonIO& io, double& var)

template <> void Jsonize(JsonIO& io, bool& var)

template <> void Jsonize(JsonIO& io, String& var)

template <> void Jsonize(JsonIO& io, WString& var)

template <> void Jsonize(JsonIO& io, Date& var)

template <> void Jsonize(JsonIO& io, Time& var)

Provides Jsonize template specialization to support var data type.

 

 

Special Jsonize variants

 

template <class K, class Vvoid StringMap(JsonIO& io, VectorMap<K, V, H>& map)

template <class K, class Vvoid StringMap(JsonIO& io, ArrayMap<K, V, H>& map)

The default Jsonize for Maps has to encode any type as key, which leads to somewhat unnatural results when key K is String or WString. StringMap alternative variant encodes map as JSON object with keys equal to map keys.

 


 

template <class Tvoid JsonizeBySerialize(JsonIO& jio, T& x)

This function encodes/retrieves Json by binary serializing the object and Jsonizing the hexadecimal data string.

 

Last edit by cxl on 02/18/2016. Do you want to contribute?. T++