Initialize GenericContainer
using string = string;
using bool_type = bool;
using int_type = int32_t;
using long_type = int64_t;
using uint_type = uint32_t;
using ulong_type = uint64_t;
using real_type = double;
using complex_type = complex<real_type>;
using string_type = string;
using vec_pointer_type = vector<pointer_type>;
using vec_bool_type = vector<bool_type>;
using vec_int_type = vector<int_type>;
using vec_long_type = vector<long_type>;
using vec_real_type = vector<real_type>;
using vec_complex_type = vector<complex_type>;
using vec_string_type = vector<string_type>;
using vector_type = vector<GenericContainer>;
using map_type = map<string_type,GenericContainer>;
using vec_uint_type = vector<uint_type>;
using vec_ulong_type = vector<ulong_type>;
using mat_int_type = mat_type<int_type>;
using mat_long_type = mat_type<long_type>;
using mat_real_type = mat_type<real_type>;
using mat_complex_type = mat_type<complex_type>;
gc.clear();
gc.erase( "pippo" );
GC::vec_string_type keys;
gc.get_keys( keys );
string keys = gc.get_keys();
ENUM
This enum class defines the types that are allowed to be used in the GenericContainer. The types are categorized as simple types, vector types, matrix types, and complex types.
NOTYPE,
POINTER,
BOOL,
INTEGER,
LONG,
REAL,
COMPLEX,
STRING,
VEC_POINTER,
VEC_BOOL,
VEC_INTEGER,
VEC_LONG,
VEC_REAL,
VEC_COMPLEX,
VEC_STRING,
MAT_INTEGER,
MAT_LONG,
MAT_REAL,
MAT_COMPLEX,
VECTOR,
MAP
TypeAllowed t = gc.get_type();
string s = gc.get_type_name();
gc.info( std::cout );
string res = gc.info();
unsigned ne = gc.get_num_elements();
unsigned nr = gc.num_rows();
unsigned nr = gc.num_cols();
Scalars write
GenericContainer gc;
gc = 12;
gc.set_int(1);
gc.set_long(1);
Matrix
GC::mat_type m;
m.resize( num_row, num_col );
vector<double> C;
m.get_column( nc, C );
vector<double> R;
m.get_row( nr, R );
unsigned rows = m.num_rows();
unsigned cols = m.num_cols();
unsigned i=0, j=1;
double mij = m(i,j);
m.info( std::cout );
string res = m.info();
double * ptr = m.data();
Scalars write
int a{1};
gc.set_pointer( & a );
gc.free_pointer();
gc.set_bool( true );
gc.set_int( 12 );
gc.set_long( 2345 );
gc.set_real( 12.34 );
GC::complex_type c(2,3.4);
gc.set_complex( c );
GC::real_type re{1.2}, im{2.1}
gc.set_complex( re, im );
gc.set_string( "pippo" );
Scalars read
GC::real_type res = gc.get_number( "message if fail" );
GC::complex_type res = gc.get_complex_number( "message if fail" );
real_type re, im;
GC::complex_type res = gc.get_complex_number( re, im );
void * p = gc.get_pvoid( "message if fail" );
void ** p = gc.get_ppvoid( "message if fail" );
int_type * p = gc.get_int_pointer();
long_type * p = gc.get_long_pointer();
real_type * p = gc.get_real_pointer();
complex_type * p = gc.get_complex_pointer();
int res1;
double res2;
long res3;
gc1.get_value<int> ( res1, "message if fail" );
gc2.get_value<double>( res2, "message if fail" );
gc3.get_value<long> ( res3, "message if fail" );
int res1;
double res2;
long res3;
int * res1 = gc1.get_pointer<int> ( res1, "message if fail" );
double * res2 = gc2.get_pointer<double>( res2, "message if fail" );
long * res3 = gc3.get_pointer<int> ( res3, "message if fail" );
bool_type res = gc.get_bool( "message if fail" );
int_type res = gc.get_int( "message if fail" );
long_type res = gc.get_long( "message if fail" );
int_type res = gc.get_as_int( "message if fail" );
uint_type res = gc.get_as_uint( "message if fail" );
long_type res = gc.get_as_long( "message if fail" );
ulong_type res = gc.get_as_ulong( "message if fail" );
real_type res = gc.get_real( "message if fail" );
complex_type res = gc.get_complex( "message if fail" );
string_type res = gc.get_string( "message if fail" );
Vector write
gc.set_vec_pointer( 100 );
vec_pointer_type v;
gc.set_vec_pointer( v );
gc.set_vec_bool( 100 );
vec_bool_type v;
gc.set_vec_bool( v );
gc.set_vec_int( 100 );
vec_int_type v;
gc.set_vec_int( v );
gc.set_vec_long( 100 );
vec_long_type v;
gc.set_vec_long( v );
gc.set_vec_real( 100 );
vec_real_type v;
gc.set_vec_real( v );
gc.set_vec_complex( 100 );
vec_complex_type v;
gc.set_vec_complex( v );
gc.set_vec_string( 100 );
vec_string_type v;
gc.set_vec_string( v );
Push
gc.push_bool( true );
gc.push_int( 23 );
gc.push_long( 2345678998 );
gc.push_real( 12.34 );
complex_type c;
gc.push_complex( c );
gc.push_complex( 23.0, 34.0 );
gc.push_string("pippo");
Vector read
vector_type & res = gc.get_vector( "message if fail" );
vec_pointer_type & res = gc.get_vec_pointer( "message if fail" );
vec_bool_type & res = gc.get_vec_bool( "message if fail" );
vec_int_type & res = gc.get_vec_int( "message if fail" );
vec_long_type & res = gc.get_vec_long( "message if fail" );
vec_real_type & res = gc.get_vec_real( "message if fail" );
vec_complex_type & res = gc.get_vec_complex( "message if fail" );
vec_string_type & res = gc.get_vec_string( "message if fail" );
integer i{ 2 };
GenericContainer & GC = gc[i];
GenericContainer & GC = gc(i,"message if fail");
Map write
map_type & m = gc.set_map();
GenericContainer & GC = gc["key"];
GenericContainer & GC = gc("key", "message if fail" );
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
GenericContainer & GC = gc(keys, "message if fail" );
## Map read
\code{.cc}
map_type & m = gc.get_map( "message if fail" );
bool_type res = gc.get_map_bool( "key", "message if fail" );
bool_type res = gc.get_map_bool( std::initializer_list<string>{"pippo","pluto"});
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
bool_type res = gc.get_map_bool( keys, , "message if fail" );
int_type res = gc.get_map_int( "key", "message if fail" );
int_type res = gc.get_map_int( std::initializer_list<string>{"pippo","pluto"});
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
int_type res = gc.get_map_int( keys, , "message if fail" );
real_type res = gc.get_map_number( "key", "message if fail" );
real_type res = gc.get_map_int( std::initializer_list<string>{"pippo","pluto"});
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
real_type res = gc.get_map_number( keys, , "message if fail" );
string res = gc.get_map_string( "key", "message if fail" );
string res = gc.get_map_int( std::initializer_list<string>{"pippo","pluto"});
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
string res = gc.get_map_string( keys, , "message if fail" );
vec_real_type const & res = gc.get_map_vec_real( "key", "message if fail" );
vec_real_type const & res = gc.get_map_vec_real( std::initializer_list<string>{"pippo","pluto"});
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
vec_real_type const & res = gc.get_map_vec_real( keys, "message if fail" );
vec_complex_type const & res = gc.get_map_vec_complex( "key", "message if fail" );
vec_complex_type const & res = gc.get_map_vec_complex( std::initializer_list<string>{"pippo","pluto"});
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
vec_complex_type const & res = gc.get_map_vec_complex( keys, , "message if fail" );
vec_string_type const & res = gc.get_map_vec_string( "key", "message if fail" );
vec_complex_type const & res = gc.get_map_vec_string( std::initializer_list<string>{"pippo","pluto"});
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
vec_string_type const & res = gc.get_map_vec_string( keys, "message if fail" );
Matrix write
unsigned nr{2}, nc{3};
gc.set_mat_int( nr, nc );
gc.set_mat_int( m );
gc.set_mat_long( nr, nc );
gc.set_mat_long( m );
gc.set_mat_real( nr, nc );
gc.set_mat_real( m );
gc.set_mat_complex( nr, nc );
gc.set_mat_complex( m );
mat_type< int_type > mat_int_type
Definition GenericContainer.hh:469
mat_type< long_type > mat_long_type
Definition GenericContainer.hh:470
mat_type< real_type > mat_real_type
Definition GenericContainer.hh:471
mat_type< complex_type > mat_complex_type
Definition GenericContainer.hh:472
Matrix read
mat_int_type & m = gc.get_mat_int( "message if fail" );
mat_long_type & m = gc.get_mat_long( "message if fail" );
mat_real_type & m = gc.get_mat_real( "message if fail" );
mat_complex_type & m = gc.get_mat_complex( "message if fail" );
Conversion
vec_int_type v;
gc.copyto_vec_int( v, "message if fail" );
vec_uint_type v;
gc.copyto_vec_uint( v, "message if fail" );
vec_long_type v;
gc.copyto_vec_long( v, "message if fail" );
vec_ulong_type v;
gc.copyto_vec_ulong( v, "message if fail" );
vec_real_type v;
gc.copyto_vec_real( v, "message if fail" );
vec_complex_type v;
gc.copyto_vec_complex( v, "message if fail" );
vec_string_type v;
gc.copyto_vec_string( v, "message if fail" );
mat_int_type m;
gc.copyto_mat_int( m, "message if fail" );
mat_long_type m;
gc.copyto_mat_long( m, "message if fail" );
mat_real_type m;
gc.copyto_mat_real( m, "message if fail" );
mat_complex_type m;
gc.copyto_mat_complex( m, "message if fail" );
get at position
integer i;
real_type res = gc.get_number_at( i, "message if fail" );
complex_type res = gc.get_complex_number_at( i, "message if fail" );
complex_type re, im;
gc.get_complex_number_at( i, re, im, "message if fail" );
int * ip = gc.get_pointer_at<int>( i );
bool_type res = gc.get_bool_at( i, "message if fail" );
int_type res = gc.get_int_at( i, "message if fail" );
long_type res = gc.get_long_at( i, "message if fail" );
real_type res = gc.get_real_at( i, "message if fail" );
complex_type res = gc.get_complex_at( i, "message if fail" );
string res = gc.get_string_at( i, "message if fail" );
int_type res = gc.get_int_at( i, j, "message if fail" );
long_type res = gc.get_long_at( i, j, "message if fail" );
real_type res = gc.get_real_at( i, j, "message if fail" );
complex_type res = gc.get_complex_at( i, j, "message if fail" );
GC::GenericContainer GC = gc.get_gc_at( i, "message if fail" );
promotion
gc.promote_to_int();
gc.promote_to_long();
gc.promote_to_real();
gc.promote_to_complex();
gc.promote_to_vec_int();
gc.promote_to_vec_long();
gc.promote_to_vec_real();
gc.promote_to_vec_complex();
gc.promote_to_mat_int();
gc.promote_to_mat_long();
gc.promote_to_mat_real();
gc.promote_to_mat_complex();
gc.promote_to_vector();
Check
bool ok = gc.exists( "key" );
vec_string_type keys;
keys.push_back("pippo");
keys.push_back("pluto");
bool ok = gc.exists( keys );
string key = gc.must_exists( keys, "message if fail" );
bool ok = get_if_exists( "key", value );
bool ok = get_if_exists( keys, value );
## print and copy
\code{.cc}
gc.dump( std::cout );
gc.print( std::cout );
gc.print_content_types( std::cout );
string diff = gc.compare_content( gc1, "message if fail" );
gc.to_gc(gc1);
gc.from_gc(gc1);
gc.merge(gc1);
Serialization
int32_t buffer_dim{10000};
uint8_t bugger[buffer_dim];
int32_t byte_written = gc.serialize( buffer_dim, buffer );
vector<uint8_t> buffer(10000);
int32_t byte_written = gc.serialize( buffer );
int32_t buffer_dim{10000};
uint8_t bugger[buffer_dim];
int32_t byte_readed = de_serialize( buffer_dim, buffer );
vector<uint8_t> buffer(10000);
int32_t byte_readed = de_serialize( buffer );
Write
vec_string_type headers;
vector_type data;
gc.write_table( headers, data, std::cout, '\t' );
mat_real_type mat;
gc.write_table( headers, mat, std::cout, '\t' );
I/O
bool ok = gc.from_file( "file.json" );
ofstream file("out.yaml);
gc.to_yaml( file ); // Print the contents of the object in YAML syntax
file.close();
string yaml = gc.to_yaml();
ifstream file("in.yaml);
bool ok = gc.from_yaml( file );
file.close();
string data = "....";
bool ok = gc.from_yaml( data );
ofstream file("out.json);
gc.to_json( file ); // Print the contents of the object in JSON syntax
file.close();
string json = gc.to_json();
ifstream file("in.json);
bool ok = gc.from_json( file );
file.close();
string data = "....";
bool ok = gc.from_json( data );
ofstream file("out.toml);
gc.to_toml( file ); // Print the contents of the object in TOML syntax
file.close();
string toml = gc.to_toml();
ifstream file("in.toml);
bool ok = gc.from_toml( file );
file.close();
string data = "....";
bool ok = gc.from_toml( data );