![]() |
GenericContainer
GenericContaine a tool for C++ programming
|
This module provides interface with JSON files. More...
Functions | |
bool | GC_namespace::file_JSON_to_GC (string const &file_name_JSON, GenericContainer &gc) |
bool | GC_namespace::JSON_to_GC (istream_type &file_JSON, GenericContainer &gc) |
bool | GC_namespace::JSON_to_GC (string const &JSON, GenericContainer &gc) |
bool | GC_namespace::JSON_to_GC (vector< string > const &JSON, GenericContainer &gc) |
void | GC_namespace::GC_to_JSON (GenericContainer const &gc, vector< string > &JSON) |
void | GC_namespace::GC_to_JSON (GenericContainer const &gc, ostream_type &file_JSON) |
This module provides interface with JSON files.
The GenericContainer (GC) module offers a flexible container for storing various data types such as booleans, integers, floating-point numbers, complex numbers, and strings. It also supports structured data types such as vectors and maps. The C++ interface allows for seamless interaction with the container, enabling users to perform operations like adding elements, retrieving data, and managing hierarchical structures.
This tutorial explains how to use the GenericContainer
JSON interface for converting between JSON data and the GenericContainer
object.
The GenericContainer
is a flexible structure that can store various data types like booleans, integers, floating-point numbers, complex numbers, strings, vectors, and maps. The interface provides multiple ways to convert JSON files, streams, or strings into GenericContainer
objects and vice versa.
There are several ways to load JSON data into a GenericContainer
.
The file_JSON_to_GC
function reads JSON data from a file and populates a GenericContainer
. This is useful for handling configuration files or other data stored in JSON format.
Example:
The JSON_to_GC
function allows loading JSON data from an input stream, such as a file stream or a string stream.
Example:
You can convert a JSON string directly into a GenericContainer
using the JSON_to_GC
function.
Example:
If you have multiple JSON strings in a vector, you can load them into a GenericContainer
using the JSON_to_GC
function.
Example:
You can also convert a GenericContainer
back to JSON format.
The GC_to_JSON
function converts the contents of a GenericContainer
into a vector of JSON strings.
Example:
You can write the contents of a GenericContainer
to an output stream (e.g., a file) in JSON format using the GC_to_JSON
function.
Example:
bool GC_namespace::file_JSON_to_GC | ( | string const & | file_name_JSON, |
GenericContainer & | gc ) |
Convert a JSON file to a GenericContainer
.
This function reads JSON data from the provided input stream and populates the given GenericContainer
with the parsed data.
[in] | file_name_JSON | Input file name containing JSON data. |
[out] | gc | The GenericContainer to be populated. |
void GC_namespace::GC_to_JSON | ( | GenericContainer const & | gc, |
ostream_type & | file_JSON ) |
Convert a GenericContainer
to a JSON file stream.
This function converts the contents of the provided GenericContainer
into JSON format and writes it to the specified output stream.
[in] | gc | The GenericContainer to convert. |
[out] | file_JSON | Output stream to write the JSON data. |
void GC_namespace::GC_to_JSON | ( | GenericContainer const & | gc, |
vector< string > & | JSON ) |
Convert a GenericContainer
to a vector of JSON strings.
This function converts the contents of the provided GenericContainer
into YAML format and stores it in the specified vector.
[in] | gc | The GenericContainer to convert. |
[out] | JSON | Vector to store the resulting JSON strings. |
bool GC_namespace::JSON_to_GC | ( | istream_type & | file_JSON, |
GenericContainer & | gc ) |
Convert a JSON file stream to a GenericContainer
.
This function reads JSON data from the provided input stream and populates the given GenericContainer
with the parsed data.
[in] | file_JSON | Input stream containing JSON data. |
[out] | gc | The GenericContainer to be populated. |
bool GC_namespace::JSON_to_GC | ( | string const & | JSON, |
GenericContainer & | gc ) |
Convert a JSON string to a GenericContainer
.
This function parses the given JSON string and populates the specified GenericContainer
with the resulting data.
[in] | JSON | The JSON string to parse. |
[out] | gc | The GenericContainer to be populated. |
bool GC_namespace::JSON_to_GC | ( | vector< string > const & | JSON, |
GenericContainer & | gc ) |
Convert a vector of JSON strings to a GenericContainer
.
This function parses each string in the given vector as YAML and populates the specified GenericContainer
with the resulting data.
[in] | JSON | Vector containing JSON strings to parse. |
[out] | gc | The GenericContainer to be populated. |