26#ifndef GENERIC_CONTAINER_HH
27#define GENERIC_CONTAINER_HH
30#pragma clang diagnostic push
31#pragma clang diagnostic ignored "-Wpadded"
32#pragma clang diagnostic ignored "-Wc++98-compat"
33#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
34#pragma clang diagnostic ignored "-Wpoison-system-directories"
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
53 #define GC_DO_ERROR(MSG) { \
55 ost << "in GenericContainer: " << MSG << '\n'; \
56 GenericContainer::exception( ost.str().data() ); \
61 #define GC_ASSERT(COND,MSG) if ( !(COND) ) GC_DO_ERROR(MSG)
65 #define GC_WARNING(COND,MSG) \
67 cout << "On line: " << __LINE__ \
68 << " file: " << __FILE__ \
69 << " in GenericContainer\nWARNING: " << MSG << '\n'; \
74 #define GC_NO_RETURN __attribute__ ((noreturn))
90 using std::string_view;
95 using std::istringstream;
96 using std::ostringstream;
97 using std::runtime_error;
120 #ifndef DOXYGEN_SHOULD_SKIP_THIS
122 #if defined(GENERIC_CONTAINER_ON_WINDOWS) && defined(GENERIC_CONTAINER_USE_WINDOWS_TYPES)
133 typedef void* pointer_type;
135 using string = string;
136 using bool_type = bool;
137 using int_type = int32_t;
138 using long_type = int64_t;
139 using uint_type = uint32_t;
140 using ulong_type = uint64_t;
141 using real_type = double;
142 using complex_type = complex<real_type>;
143 using string_type = string;
144 using vec_pointer_type = vector<pointer_type>;
145 using vec_bool_type = vector<bool_type>;
146 using vec_int_type = vector<int_type>;
147 using vec_long_type = vector<long_type>;
148 using vec_real_type = vector<real_type>;
149 using vec_complex_type = vector<complex_type>;
150 using vec_string_type = vector<string_type>;
151 using vector_type = vector<GenericContainer>;
152 using map_type = map<string_type,GenericContainer>;
153 using vec_uint_type = vector<uint_type>;
154 using vec_ulong_type = vector<ulong_type>;
168 template <
typename TYPE>
170 unsigned m_num_rows{0};
171 unsigned m_num_cols{0};
172 typedef typename vector<TYPE>::size_type size_type;
192 { vector<TYPE>::resize(size_type(nr*nc)); }
207 resize(
unsigned const nr,
unsigned const nc ) {
210 vector<TYPE>::resize(size_type(nr*nc));
213 template <
typename T1,
typename T2>
216 static_assert(std::is_integral_v<T1>,
"resize() accepts only integral types!");
217 static_assert(std::is_integral_v<T1>,
"resize() accepts only integral types!");
218 resize(
static_cast<unsigned>(nr),
static_cast<unsigned>(nc) );
236 template <
typename T>
239 static_assert(std::is_integral_v<T>,
"get_column() accepts only integral types as first argument!");
263 void get_row(
unsigned nr, vector<TYPE> & R )
const;
265 template <
typename T>
267 get_row( T
const nr, vector<TYPE> & R )
const {
268 static_assert(std::is_integral_v<T>,
"get_row() accepts only integral types as first argument!");
269 get_row(
static_cast<unsigned>(nr), R );
276 getRow(
unsigned nr, vector<TYPE> & R )
const
294 template <
typename T>
297 static_assert(std::is_integral_v<T>,
"get_column() accepts only integral types as first argument!");
323 template <
typename T>
326 static_assert(std::is_integral_v<T>,
"get_row() accepts only integral types as first argument!");
327 get_row(
static_cast<unsigned>(nr), R );
348 [[nodiscard]]
unsigned num_rows()
const {
return m_num_rows; }
353 [[nodiscard]]
unsigned numRows()
const {
return m_num_rows; }
366 [[nodiscard]]
unsigned num_cols()
const {
return m_num_cols; }
371 [[nodiscard]]
unsigned numCols()
const {
return m_num_cols; }
445 TYPE *
data() {
return &vector<TYPE>::front(); }
458 TYPE
const *
data()
const {
return &vector<TYPE>::front(); }
462 #ifndef GENERIC_CONTAINER_ON_WINDOWS
463 extern template class mat_type<int_type>;
464 extern template class mat_type<long_type>;
465 extern template class mat_type<real_type>;
466 extern template class mat_type<complex_type>;
487 template <
typename TYPE>
501 template <
typename TYPE>
650 using DataStorage =
union {
680 void allocate_string();
683 void allocate_complex();
686 void allocate_vec_pointer(
unsigned sz);
689 void allocate_vec_bool(
unsigned sz);
692 void allocate_vec_int(
unsigned sz);
695 void allocate_vec_long(
unsigned sz);
698 void allocate_vec_real(
unsigned sz);
701 void allocate_vec_complex(
unsigned sz);
704 void allocate_mat_int(
unsigned nr,
unsigned nc);
707 void allocate_mat_long(
unsigned nr,
unsigned nc);
710 void allocate_mat_real(
unsigned nr,
unsigned nc);
713 void allocate_mat_complex(
unsigned nr,
unsigned nc);
716 void allocate_vec_string(
unsigned sz);
719 void allocate_vector(
unsigned sz);
734 #ifdef GENERIC_CONTAINER_ON_WINDOWS
735 bool simple_data()
const;
737 [[nodiscard]]
bool simple_data()
const {
return m_data_type <= GC_type::STRING; }
741 #ifdef GENERIC_CONTAINER_ON_WINDOWS
742 bool simple_vec_data()
const;
744 [[nodiscard]]
bool simple_vec_data()
const {
return m_data_type < GC_type::VEC_STRING; }
817 void erase( string_view name )
const;
838 bool empty()
const {
return this->m_data_type != GC_type::NOTYPE; }
863 pointer_type & set_pointer( pointer_type value );
901 void get_keys( vec_string_type & keys )
const;
921 string get_keys()
const;
938 bool_type & set_bool( bool_type value );
955 int_type & set_int( int_type value );
972 long_type & set_long( long_type value );
989 real_type & set_real( real_type value );
1007 complex_type & set_complex( complex_type
const & value );
1026 complex_type & set_complex( real_type re, real_type im );
1043 string_type & set_string( string_view value );
1072 vec_pointer_type & set_vec_pointer(
unsigned sz = 0 );
1074 template <
typename T>
1077 static_assert(std::is_integral_v<T>,
"set_vec_pointers() accepts only integral types!");
1095 vec_pointer_type & set_vec_pointer( vec_pointer_type
const & v );
1111 vec_bool_type & set_vec_bool(
unsigned sz = 0 );
1113 template <
typename T>
1116 static_assert(std::is_integral_v<T>,
"set_vec_bool() accepts only integral types!");
1134 vec_bool_type & set_vec_bool( vec_bool_type
const & v );
1150 vec_int_type & set_vec_int(
unsigned sz = 0 );
1152 template <
typename T>
1155 static_assert(std::is_integral_v<T>,
"set_vec_ints() accepts only integral types!");
1173 vec_int_type & set_vec_int( vec_int_type
const & v );
1189 vec_long_type & set_vec_long(
unsigned sz = 0 );
1191 template <
typename T>
1194 static_assert(std::is_integral_v<T>,
"set_vec_long() accepts only integral types!");
1212 vec_long_type & set_vec_long( vec_long_type
const & v );
1228 vec_real_type & set_vec_real(
unsigned sz = 0 );
1230 template <
typename T>
1233 static_assert(std::is_integral_v<T>,
"set_vec_real() accepts only integral types!");
1251 vec_real_type & set_vec_real( vec_real_type
const & v );
1267 vec_complex_type & set_vec_complex(
unsigned sz = 0 );
1269 template <
typename T>
1272 static_assert(std::is_integral_v<T>,
"set_vec_complex() accepts only integral types!");
1290 vec_complex_type & set_vec_complex( vec_complex_type
const & v );
1306 vec_string_type & set_vec_string(
unsigned sz = 0 );
1308 template <
typename T>
1311 static_assert(std::is_integral_v<T>,
"set_vec_string() accepts only integral types!");
1329 vec_string_type & set_vec_string( vec_string_type
const & v );
1346 mat_int_type & set_mat_int(
unsigned nr = 0,
unsigned nc = 0 );
1379 mat_long_type & set_mat_long(
unsigned nr = 0,
unsigned nc = 0 );
1412 mat_real_type & set_mat_real(
unsigned nr = 0,
unsigned nc = 0 );
1469 void push_bool(
bool b )
const;
1477 void push_int( int_type i );
1485 void push_long( long_type l );
1493 void push_real( real_type r );
1501 void push_complex( complex_type & c );
1510 void push_complex( real_type re, real_type im );
1518 void push_string( string_view s );
1544 vector_type & set_vector(
unsigned sz = 0 );
1556 map_type & set_map();
1649 unsigned get_num_elements()
const;
1656 unsigned num_rows()
const;
1667 unsigned num_cols()
const;
1679 real_type get_number( string_view
const where =
"" )
const;
1687 complex_type get_complex_number( string_view
const where =
"" )
const;
1698 void get_complex_number( real_type & re, real_type & im )
const;
1706 void * get_pvoid( string_view
const where =
"" )
const;
1714 void ** get_ppvoid( string_view
const where =
"" )
const;
1719 int_type
const * get_int_pointer()
const;
1726 int_type * get_int_pointer();
1733 long_type
const * get_long_pointer()
const;
1740 long_type * get_long_pointer();
1747 real_type
const * get_real_pointer()
const;
1754 real_type * get_real_pointer();
1761 complex_type
const * get_complex_pointer()
const;
1768 complex_type * get_complex_pointer();
1779 template <
typename T>
1788 #ifdef GENERIC_CONTAINER_ON_WINDOWS
1789 template <
typename T>
1791 { ck(
"get_pointer",GC_type::POINTER);
return *
reinterpret_cast<T*
>(
get_ppvoid()); }
1796 template <
typename T>
1797 T get_pointer()
const
1798 { ck(
"get_pointer",GC_type::POINTER);
return reinterpret_cast<T
>(get_pvoid()); }
1800 template <
typename T>
1802 { ck(
"get_pointer", GC_type::POINTER);
return *
static_cast<T*
>(m_data.p); }
1809 template <
typename T>
1811 { ck(
"get_pointer",GC_type::POINTER);
return reinterpret_cast<T
>(m_data.p); }
1823 bool_type get_map_bool( string_view
const key, string_view
const where =
"" )
const;
1831 bool_type get_map_bool( std::initializer_list<string> args )
const;
1842 bool_type get_map_bool( vec_string_type
const & keys, string_view
const where =
"" )
const;
1853 int_type get_map_int( string_view
const key, string_view
const where =
"" )
const;
1861 int_type get_map_int( std::initializer_list<string> args )
const;
1873 int_type get_map_int( vec_string_type
const & keys, string_view
const where =
"" )
const;
1884 real_type get_map_number( string_view
const key, string_view
const where =
"" )
const;
1892 real_type get_map_number( std::initializer_list<string> args )
const;
1904 real_type get_map_number( vec_string_type
const & keys, string_view
const where =
"" )
const;
1915 string const & get_map_string( string_view
const key, string_view
const where =
"" )
const;
1923 string const & get_map_string( std::initializer_list<string> args )
const;
1935 string const & get_map_string( vec_string_type
const & keys, string_view
const where =
"" )
const;
1946 vec_real_type
const & get_map_vec_real( string_view
const key, string_view
const where =
"" )
const;
1954 vec_real_type
const & get_map_vec_real( std::initializer_list<string> args )
const;
1966 vec_real_type
const & get_map_vec_real( vec_string_type
const & keys, string_view
const where =
"" )
const;
1977 vec_complex_type
const & get_map_vec_complex( string_view
const key, string_view
const where =
"" )
const;
1985 vec_complex_type
const & get_map_vec_complex( std::initializer_list<string> args )
const;
1997 vec_complex_type
const & get_map_vec_complex( vec_string_type
const & keys, string_view
const where =
"" )
const;
2008 vec_string_type
const & get_map_vec_string( string_view
const key, string_view
const where =
"" )
const;
2016 vec_string_type
const & get_map_vec_string( std::initializer_list<string> args )
const;
2028 vec_string_type
const & get_map_vec_string( vec_string_type
const & keys, string_view
const where =
"" )
const;
2038 bool_type & get_bool( string_view
const where =
"" );
2048 bool_type
const & get_bool( string_view
const where =
"" )
const;
2058 int_type & get_int( string_view
const where =
"" );
2068 int_type
const & get_int( string_view
const where =
"" )
const;
2078 long_type & get_long( string_view
const where =
"" );
2088 long_type
const & get_long( string_view
const where =
"" )
const;
2098 int_type get_as_int( string_view
const where =
"" )
const;
2108 uint_type get_as_uint( string_view
const where =
"" )
const;
2118 long_type get_as_long( string_view
const where =
"" )
const;
2128 ulong_type get_as_ulong( string_view
const where =
"" )
const;
2138 real_type & get_real( string_view
const where =
"" );
2148 real_type
const & get_real( string_view
const where =
"" )
const;
2158 complex_type & get_complex( string_view
const where =
"" );
2168 complex_type
const & get_complex( string_view
const where =
"" )
const;
2178 string_type & get_string( string_view
const where =
"" );
2188 string_type
const & get_string( string_view
const where =
"" )
const;
2217 vector_type & get_vector( string_view
const where =
"" );
2231 vector_type
const & get_vector( string_view
const where =
"" )
const;
2245 vec_pointer_type & get_vec_pointer( string_view
const where =
"" );
2259 vec_pointer_type
const & get_vec_pointer( string_view
const where =
"" )
const;
2273 vec_bool_type & get_vec_bool( string_view
const where =
"" );
2287 vec_bool_type
const & get_vec_bool( string_view
const where =
"" )
const;
2301 vec_int_type & get_vec_int( string_view =
"" );
2315 vec_int_type
const & get_vec_int( string_view =
"" )
const;
2329 vec_long_type & get_vec_long( string_view =
"" );
2343 vec_long_type
const & get_vec_long( string_view =
"" )
const;
2357 vec_real_type & get_vec_real( string_view =
"" );
2371 vec_real_type
const & get_vec_real( string_view =
"" )
const;
2385 vec_complex_type & get_vec_complex( string_view =
"" );
2399 vec_complex_type
const & get_vec_complex( string_view =
"" )
const;
2427 mat_int_type const & get_mat_int( string_view =
"" )
const;
2455 mat_long_type const & get_mat_long( string_view =
"" )
const;
2483 mat_real_type const & get_mat_real( string_view =
"" )
const;
2525 vec_string_type & get_vec_string( string_view =
"" );
2539 vec_string_type
const & get_vec_string( string_view =
"" )
const;
2567 void copyto_vec_int( vec_int_type & v, string_view =
"" )
const;
2582 void copyto_vec_uint( vec_uint_type & v, string_view =
"" )
const;
2597 void copyto_vec_long( vec_long_type & v, string_view =
"" )
const;
2612 void copyto_vec_ulong( vec_ulong_type & v, string_view =
"" )
const;
2627 void copyto_vec_real( vec_real_type & v, string_view =
"" )
const;
2642 void copyto_vec_complex( vec_complex_type & v, string_view =
"" )
const;
2657 void copyto_vec_string( vec_string_type & v, string_view =
"" )
const;
2682 void copyto_mat_int(
mat_int_type & m, string_view =
"" )
const;
2697 void copyto_mat_long(
mat_long_type & m, string_view =
"" )
const;
2712 void copyto_mat_real(
mat_real_type & m, string_view =
"" )
const;
2756 real_type get_number_at(
unsigned i, string_view =
"" )
const;
2772 complex_type get_complex_number_at(
unsigned i, string_view =
"" )
const;
2790 void get_complex_number_at(
unsigned i, real_type & re, real_type & im, string_view =
"" )
const;
2804 template <
typename T>
2806 {
return (*
this)[i].get_pointer<T>(); }
2820 template <
typename T>
2822 {
return (*
this)[i].get_pointer<T>(); }
2837 bool_type get_bool_at(
unsigned i );
2839 template <
typename T>
2842 static_assert(std::is_integral_v<T>,
"get_bool_at() accepts only integral types!");
2859 bool_type get_bool_at(
unsigned i, string_view
const where )
const;
2873 int_type & get_int_at(
unsigned i );
2875 template <
typename T>
2878 static_assert(std::is_integral_v<T>,
"get_int_at() accepts only integral types!");
2895 int_type
const & get_int_at(
unsigned i, string_view
const where )
const;
2909 long_type & get_long_at(
unsigned i );
2911 template <
typename T>
2914 static_assert(std::is_integral_v<T>,
"get_long_at() accepts only integral types!");
2931 long_type
const & get_long_at(
unsigned i, string_view
const where )
const;
2945 real_type & get_real_at(
unsigned i );
2947 template <
typename T>
2949 static_assert(std::is_integral_v<T>,
"get_real_at() accepts only integral types!");
2966 real_type
const & get_real_at(
unsigned i, string_view
const where )
const;
2980 complex_type & get_complex_at(
unsigned i );
2982 template <
typename T>
2984 static_assert(std::is_integral_v<T>,
"get_complex_at() accepts only integral types!");
3001 complex_type
const & get_complex_at(
unsigned i, string_view
const where )
const;
3016 int_type & get_int_at(
unsigned i,
unsigned j );
3032 int_type
const & get_int_at(
unsigned i,
unsigned j, string_view
const where )
const;
3047 long_type & get_long_at(
unsigned i,
unsigned j );
3063 long_type
const & get_long_at(
unsigned i,
unsigned j, string_view
const where )
const;
3078 real_type & get_real_at(
unsigned i,
unsigned j );
3094 real_type
const & get_real_at(
unsigned i,
unsigned j, string_view
const where )
const;
3109 complex_type & get_complex_at(
unsigned i,
unsigned j );
3125 complex_type
const & get_complex_at(
unsigned i,
unsigned j, string_view
const where )
const;
3139 string_type & get_string_at(
unsigned i );
3141 template <
typename T>
3144 static_assert(std::is_integral_v<T>,
"get_string_at() accepts only integral types!");
3161 string_type
const & get_string_at(
unsigned i, string_view
const where )
const;
3177 template <
typename T>
3179 static_assert(std::is_integral_v<T>,
"get_gc_at() accepts only integral types!");
3180 return get_gc_at(
static_cast<unsigned>(i));
3196 GenericContainer const & get_gc_at(
unsigned i, string_view
const where )
const;
3230 map_type & get_map( string_view =
"" );
3250 map_type
const & get_map( string_view =
"" )
const;
3353 GenericContainer const & operator () (
unsigned i, string_view =
"" )
const;
3383 GenericContainer const & operator () ( string_view s, string_view =
"" )
const;
3399 GenericContainer & operator () ( vec_string_type
const & vs, string_view =
"" );
3415 GenericContainer const & operator () ( vec_string_type
const & vs, string_view =
"" )
const;
3535 void set( complex<float>
const & a )
3550 void set( complex<double>
const & a )
3614 { this->
set_bool(a);
return *
this; }
3630 { this->
set_int(a);
return *
this; }
3646 { this->
set_long(a);
return *
this; }
3887 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3894 : m_data_type(GC_type::NOTYPE) { *
this = a; }
3901 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3908 : m_data_type(GC_type::NOTYPE) { *
this = a; }
3915 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3922 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3929 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3936 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3943 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3950 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3957 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3964 : m_data_type(GC_type::NOTYPE) { this->
operator=(a); }
3971 : m_data_type(GC_type::NOTYPE) { this->
set_pointer(a); }
3978 : m_data_type(GC_type::NOTYPE) { this->
from_gc(gc); }
3991 bool exists( string_view s )
const;
3998 bool exists( vec_string_type
const & vs )
const;
4006 string must_exists( vec_string_type
const & vs, string_view
const where )
const;
4013 bool get_if_exists( string_view field,
bool & value )
const;
4021 bool get_if_exists( vec_string_type
const & fields,
bool & value )
const;
4028 bool get_if_exists( string_view field, int_type & value )
const;
4035 bool get_if_exists( string_view field, uint_type & value )
const;
4042 bool get_if_exists( string_view field, long_type & value )
const;
4049 bool get_if_exists( string_view field, ulong_type & value )
const;
4056 bool get_if_exists( string_view field, real_type & value )
const;
4063 bool get_if_exists( string_view field, complex_type & value )
const;
4070 bool get_if_exists( string_view field, string_type & value )
const;
4078 template <
typename T>
4081 for ( string_view field : fields ) {
4092 template <
typename T>
4134 print_content_types(
4136 string_view prefix =
"",
4137 string_view indent =
" "
4167 compare_content(
GenericContainer const & gc, string_view from =
"" )
const;
4198 string_view prefix =
"",
4199 string_view indent =
" "
4231 string_view prefix =
"",
4232 string_view indent =
" "
4234 this->
dump( stream, prefix, indent );
4267 string_view prefix =
"",
4268 string_view indent =
" "
4272 this->
print(ostr,prefix,indent);
4352 bool from_file( string_view file_name );
4395 { ostringstream ss; this->
to_yaml( ss, prefix );
return ss.str(); }
4483 { ostringstream ss; this->
to_json( ss, prefix );
return ss.str();}
4552 { ostringstream ss; this->
to_toml( ss );
return ss.str();}
4672 char const commentChars[] =
"#%",
4673 char const delimiters[] =
" \t"
4682 char const commentChars[] =
"#%",
4683 char const delimiters[] =
" \t"
4707 char const commentChars[] =
"#%",
4708 char const delimiters[] =
" \t"
4717 char const commentChars[] =
"#%",
4718 char const delimiters[] =
" \t"
4744 char const commentChars[] =
"#%",
4745 char const delimiters[] =
" \t",
4755 char const commentChars[] =
"#%",
4756 char const delimiters[] =
" \t",
4782 char const commentChars[] =
"#%",
4783 char const delimiters[] =
" \t",
4793 char const commentChars[] =
"#%",
4794 char const delimiters[] =
" \t",
4810 int32_t mem_size()
const;
4833 int32_t serialize( int32_t buffer_dim, uint8_t * buffer )
const;
4871 std::vector<uint8_t>
4873 std::vector<uint8_t> buffer(
static_cast<std::size_t
>(
mem_size()) );
4874 serialize(
static_cast<int32_t
>(buffer.size()), buffer.data());
4897 int32_t de_serialize( int32_t buffer_dim, uint8_t
const * buffer );
4929 exception( string_view
const where ) GC_NO_RETURN;
4945 vec_string_type
const & headers,
4946 vector_type
const & data,
4948 char delimiter =
'\t'
4957 vec_string_type
const & headers,
4958 vector_type
const & data,
4960 char delimiter =
'\t'
4975 vec_string_type
const & headers,
4978 char delimiter =
'\t'
4987 vec_string_type
const & headers,
4990 char delimiter =
'\t'
5004 vec_string_type
const & headers,
5005 vector_type
const & data,
5015 vec_string_type
const & headers,
5016 vector_type
const & data,
5031 vec_string_type
const & headers,
5042 vec_string_type
const & headers,
5056#ifndef DOXYGEN_SHOULD_SKIP_THIS
5059 #ifndef XlibSpecificationRelease
5069#pragma clang diagnostic pop
GenericContainer & read_formatted_data2(istream_type &stream, char const commentChars[]="#%", char const delimiters[]=" \t", GenericContainer ptr_pars[]=nullptr)
GenericContainer & read_formatted_data(istream_type &stream, char const commentChars[]="#%", char const delimiters[]=" \t")
GenericContainer const & write_formatted_data(ostream_type &stream, char const delimiter='\t') const
The GenericContainer class provides a flexible container for storing heterogeneous data types.
Definition GenericContainer.hh:614
GC_namespace::vec_real_type vec_real_type
Alias for vector of real numbers type.
Definition GenericContainer.hh:632
bool from_toml(string const &data)
Loads the contents of the GenericContainer from a TOML-formatted stream.
Definition GenericContainer.hh:4591
GC_namespace::vec_ulong_type vec_ulong_type
Alias for vector of unsigned long integers type.
Definition GenericContainer.hh:631
bool to_toml(ostream_type &stream) const
Serializes the contents of the GenericContainer into TOML format and writes it to the provided output...
real_type & set_real(real_type value)
Set the data type to real_type and assign a floating-point value.
Definition GenericContainer.cc:963
GenericContainer(complex< double > const &a)
Definition GenericContainer.hh:3942
real_type & get_real_at(unsigned i)
Definition GenericContainer.cc:3048
bool get_if_exists(vec_string_type const &fields, T &value) const
Definition GenericContainer.hh:4080
GenericContainer(double const &a)
Definition GenericContainer.hh:3928
GC_namespace::vec_long_type vec_long_type
Alias for vector of long integers type.
Definition GenericContainer.hh:630
static void exception(string_view const where) GC_NO_RETURN
Definition GenericContainer.cc:3908
GC_namespace::uint_type uint_type
Alias for unsigned integer type.
Definition GenericContainer.hh:620
GenericContainer()
Constructs a GenericContainer with an initial empty state.
Definition GenericContainer.hh:761
GC_namespace::map_type map_type
Alias for map of GenericContainer type.
Definition GenericContainer.hh:636
T get_pointer_at(unsigned i) const
Return i-th generic pointer (if fails issue an error).
Definition GenericContainer.hh:2821
bool_type get_bool_at(unsigned i)
Definition GenericContainer.cc:2925
bool_type get_bool_at(T i)
Definition GenericContainer.hh:2841
GC_namespace::vec_bool_type vec_bool_type
Alias for vector of booleans type.
Definition GenericContainer.hh:627
GC_namespace::mat_real_type mat_real_type
Alias for matrix of real numbers type.
Definition GenericContainer.hh:639
void from_gc(GenericContainer const &gc)
Copies the contents from another GenericContainer into this object.
Definition GenericContainer.cc:3780
void set(uint_type const &a)
Definition GenericContainer.hh:3456
GC_namespace::bool_type bool_type
Alias for boolean type.
Definition GenericContainer.hh:618
bool empty() const
Checks whether the GenericContainer is empty.
Definition GenericContainer.hh:838
vec_pointer_type & set_vec_pointer(unsigned sz=0)
Set the data to vec_pointer_type, allocate and initialize.
Definition GenericContainer.cc:992
GC_namespace::vector_type vector_type
Alias for vector of GenericContainer type.
Definition GenericContainer.hh:635
GenericContainer const & info(ostream_type &stream) const
Print information about the kind of data stored to a stream.
Definition GenericContainer.cc:3187
GenericContainer & readFormattedData2(istream_type &stream, char const commentChars[]="#%", char const delimiters[]=" \t", GenericContainer ptr_pars[]=nullptr)
Definition GenericContainer.hh:4753
int32_t serialize(int32_t buffer_dim, uint8_t *buffer) const
Serializes the contents of the GenericContainer into a raw memory buffer.
Definition GenericContainerSerialize.cc:199
GC_namespace::complex_type complex_type
Alias for complex number type.
Definition GenericContainer.hh:624
bool from_json(istream_type &stream)
Returns a string containing the contents of the GenericContainer in JSON format.
GenericContainer(bool const &a)
Definition GenericContainer.hh:3886
int32_t de_serialize(vector< uint8_t > const &buffer)
Deserializes a GenericContainer from a byte vector.
GC_namespace::ulong_type ulong_type
Alias for unsigned long integer type.
Definition GenericContainer.hh:622
void to_yaml(ostream_type &stream, string_view prefix="") const
Serializes the contents of the GenericContainer into YAML format and writes it to the provided output...
GenericContainer(complex< float > const &a)
Definition GenericContainer.hh:3935
vec_bool_type & set_vec_bool(unsigned sz=0)
Set the data to vec_bool_type, allocate and initialize.
Definition GenericContainer.cc:1005
long_type & get_long_at(unsigned i)
Definition GenericContainer.cc:2996
string to_json(string_view prefix="") const
Definition GenericContainer.hh:4482
GenericContainer(pointer_type a)
Definition GenericContainer.hh:3970
void set(double const &a)
Definition GenericContainer.hh:3521
vec_string_type & set_vec_string(T sz)
Definition GenericContainer.hh:1310
GenericContainer & readFormattedData(char const fname[], char const commentChars[]="#%", char const delimiters[]=" \t")
Definition GenericContainer.hh:4715
vec_long_type & set_vec_long(T sz)
Definition GenericContainer.hh:1193
void set(bool const &a)
Definition GenericContainer.hh:3443
void set(complex< double > const &a)
Definition GenericContainer.hh:3550
bool from_json(string const &data)
Definition GenericContainer.hh:4506
void get_value(T &v, string_view const where="") const
Get the stored value.
GenericContainer(long_type const &a)
Definition GenericContainer.hh:3914
static GenericContainer gc_from_yaml(string const &yaml)
Creates a GenericContainer object from a JSON string.
Definition GenericContainer.hh:4454
int32_t serialize(vector< uint8_t > &buffer) const
Serializes the contents of the GenericContainer into a byte vector.
vec_complex_type & set_vec_complex(unsigned sz=0)
Set the data to vec_complex_type, allocate and initialize.
Definition GenericContainer.cc:1056
GenericContainer(float const &a)
Definition GenericContainer.hh:3921
vec_long_type & set_vec_long(unsigned sz=0)
Set the data to vec_long_type, allocate and initialize.
Definition GenericContainer.cc:1030
GenericContainer & readFormattedData2(char const fname[], char const commentChars[]="#%", char const delimiters[]=" \t", GenericContainer ptr_pars[]=nullptr)
Definition GenericContainer.hh:4791
void set(string_view a)
Definition GenericContainer.hh:3577
GenericContainer & get_gc_at(T i)
Definition GenericContainer.hh:3178
long_type & set_long(long_type value)
Set the data type to long_type and assign a long integer value.
Definition GenericContainer.cc:956
vec_complex_type & set_vec_complex(T sz)
Definition GenericContainer.hh:1271
static GenericContainer gc_from_toml(string const &toml)
Creates a GenericContainer object from a TOML string.
Definition GenericContainer.hh:4608
GC_namespace::real_type real_type
Alias for real (floating point) type.
Definition GenericContainer.hh:623
string_type & set_string(string_view value)
Set the data type to string_type, allocate memory, and assign a string value.
Definition GenericContainer.cc:986
std::vector< uint8_t > serialize() const
Serializes the contents of the GenericContainer and returns a byte vector.
Definition GenericContainer.hh:4872
GenericContainer(GenericContainer const &gc)
Definition GenericContainer.hh:3977
string_type info() const
Print information about the kind of data stored as a string.
Definition GenericContainer.hh:1634
complex_type & get_complex_at(unsigned i)
Definition GenericContainer.cc:3099
string to_toml() const
Definition GenericContainer.hh:4551
vec_int_type & set_vec_int(unsigned sz=0)
Set the data to vec_int_type, allocate and initialize.
Definition GenericContainer.cc:1017
void set(ulong_type const &a)
Definition GenericContainer.hh:3482
int_type & set_int(int_type value)
Set the data type to int_type and assign an integer value.
Definition GenericContainer.cc:949
GenericContainer & get_gc_at(unsigned i)
Definition GenericContainer.cc:3170
int32_t mem_size() const
Definition GenericContainerSerialize.cc:150
T & get_pointer_at(unsigned i)
Definition GenericContainer.hh:2805
~GenericContainer()
Destroys the GenericContainer and releases any allocated resources.
Definition GenericContainer.hh:779
void to_json(ostream_type &stream, string_view prefix="") const
Serializes the contents of the GenericContainer into JSON format and writes it to the provided output...
complex_type & get_complex_at(T i)
Definition GenericContainer.hh:2983
GenericContainer(int_type const &a)
Definition GenericContainer.hh:3900
GenericContainer(uint_type const &a)
Definition GenericContainer.hh:3893
unsigned num_rows() const
Return the number of rows in the internally stored matrix.
Definition GenericContainer.cc:674
T get_pointer() const
Get the stored value as a pointer (const version).
Definition GenericContainer.hh:1810
string_type & get_string_at(unsigned i)
Definition GenericContainer.cc:3149
GC_namespace::int_type int_type
Alias for integer type.
Definition GenericContainer.hh:619
GenericContainer(string const &a)
Definition GenericContainer.hh:3956
void dump(ostream_type &stream, string_view prefix="", string_view indent=" ") const
Dumps the full contents of the GenericContainer in a human-readable format.
Definition GenericContainer.cc:3429
complex_type & set_complex(complex_type const &value)
Set the data type to complex_type and assign a complex value.
Definition GenericContainer.cc:970
bool_type & set_bool(bool_type value)
Set the data type to bool_type and assign a boolean value.
Definition GenericContainer.cc:942
GC_namespace::mat_long_type mat_long_type
Alias for matrix of long integers type.
Definition GenericContainer.hh:638
string_view get_type_name() const
Return a string representing the type of data stored.
Definition GenericContainer.hh:1612
GC_namespace::vec_uint_type vec_uint_type
Alias for vector of unsigned integers type.
Definition GenericContainer.hh:629
string_type & get_string_at(T i)
Definition GenericContainer.hh:3143
GC_namespace::vec_int_type vec_int_type
Alias for vector of integers type.
Definition GenericContainer.hh:628
GenericContainer & readFormattedData(istream_type &stream, char const commentChars[]="#%", char const delimiters[]=" \t")
Definition GenericContainer.hh:4680
GC_namespace::string_type string_type
Alias for string type.
Definition GenericContainer.hh:625
vec_string_type & set_vec_string(unsigned sz=0)
Set the data to vec_string_type, allocate and initialize.
Definition GenericContainer.cc:1121
GC_namespace::pointer_type pointer_type
Alias for pointer type.
Definition GenericContainer.hh:617
GenericContainer(ulong_type const &a)
Definition GenericContainer.hh:3907
string to_yaml(string_view prefix="") const
Returns a string containing the contents of the GenericContainer in YAML format.
Definition GenericContainer.hh:4394
unsigned num_cols() const
Return the number of columns in the internally stored matrix.
Definition GenericContainer.cc:702
void clear()
Clears the content of the GenericContainer, resetting it to an empty state.
Definition GenericContainer.cc:592
vec_real_type & set_vec_real(unsigned sz=0)
Set the data to vec_real_type, allocate and initialize.
Definition GenericContainer.cc:1043
GenericContainer & operator=(bool const &a)
Definition GenericContainer.hh:3613
void print(ostream_type &stream, string_view prefix="", string_view indent=" ") const
Prints the contents of the GenericContainer in a human-readable format.
Definition GenericContainer.hh:4229
void set(int_type const &a)
Definition GenericContainer.hh:3469
TypeAllowed get_type() const
Return an integer representing the type of data stored.
Definition GenericContainer.hh:1601
T & get_pointer()
Get the stored value as a pointer.
Definition GenericContainer.hh:1801
vec_real_type & set_vec_real(T sz)
Definition GenericContainer.hh:1232
void set(pointer_type a)
Definition GenericContainer.hh:3591
real_type & get_real_at(T i)
Definition GenericContainer.hh:2948
GenericContainer(char const *a)
Definition GenericContainer.hh:3949
void set(long_type const &a)
Definition GenericContainer.hh:3495
GenericContainer(string_view a)
Definition GenericContainer.hh:3963
GC_namespace::vec_pointer_type vec_pointer_type
Alias for vector of pointers type.
Definition GenericContainer.hh:626
bool from_json2(istream_type &stream)
void set(complex< float > const &a)
Definition GenericContainer.hh:3535
GC_namespace::vec_string_type vec_string_type
Alias for vector of strings type.
Definition GenericContainer.hh:634
bool from_yaml(istream_type &stream)
Loads the contents of the GenericContainer from a YAML-formatted stream.
bool get_if_exists(char const field[], T &value) const
Definition GenericContainer.hh:4094
int_type & get_int_at(T i)
Definition GenericContainer.hh:2877
int_type & get_int_at(unsigned i)
Definition GenericContainer.cc:2947
GC_namespace::long_type long_type
Alias for long integer type.
Definition GenericContainer.hh:621
GenericContainer const & writeFormattedData(ostream_type &stream, char const delimiter='\t') const
Definition GenericContainer.hh:4648
bool from_yaml(string const &data)
Loads the contents of the GenericContainer from a YAML-formatted string.
Definition GenericContainer.hh:4437
vec_pointer_type & set_vec_pointer(T sz)
Definition GenericContainer.hh:1076
void ** get_ppvoid(string_view const where="") const
Return the stored data as a double pointer.
Definition GenericContainer.cc:1266
GC_namespace::mat_int_type mat_int_type
Alias for matrix of integers type.
Definition GenericContainer.hh:637
bool get_if_exists(string_view field, bool &value) const
Definition GenericContainer.cc:2584
bool from_toml(istream_type &stream)
Returns a string containing the contents of the GenericContainer in TOML format.
string_type print(string_view prefix="", string_view indent=" ") const
Returns a human-readable string representation of the GenericContainer.
Definition GenericContainer.hh:4266
unsigned get_numRows() const
Definition GenericContainer.hh:1660
void set(float const &a)
Definition GenericContainer.hh:3508
static GenericContainer gc_from_json(string const &json)
Creates a GenericContainer object from a JSON string.
Definition GenericContainer.hh:4524
vec_int_type & set_vec_int(T sz)
Definition GenericContainer.hh:1154
GC_namespace::mat_complex_type mat_complex_type
Alias for matrix of complex numbers type.
Definition GenericContainer.hh:640
void load(GenericContainer const &a)
Definition GenericContainer.hh:3795
long_type & get_long_at(T i)
Definition GenericContainer.hh:2913
vec_bool_type & set_vec_bool(T sz)
Definition GenericContainer.hh:1115
GC_namespace::vec_complex_type vec_complex_type
Alias for vector of complex numbers type.
Definition GenericContainer.hh:633
unsigned get_numCols() const
Definition GenericContainer.hh:1671
void set(char const *a)
Definition GenericContainer.hh:3564
pointer_type & set_pointer(pointer_type value)
Set the data type to pointer_type and assign a value.
Definition GenericContainer.cc:935
Generic matrix storage type.
Definition GenericContainer.hh:169
unsigned numRows() const
Definition GenericContainer.hh:353
void get_column(T const nc, TYPE *C) const
Definition GenericContainer.hh:296
void getColumn(unsigned nc, vector< TYPE > &C) const
Definition GenericContainer.hh:247
void get_column(T const nc, vector< TYPE > &C) const
Definition GenericContainer.hh:238
void resize(unsigned const nr, unsigned const nc)
Definition GenericContainer.hh:207
void getRow(unsigned nr, TYPE *R) const
Definition GenericContainer.hh:334
void get_row(unsigned nr, TYPE *R) const
Definition GenericContainer.cc:201
void info(ostream_type &stream) const
Definition GenericContainer.cc:212
void get_row(T const nr, TYPE *R) const
Definition GenericContainer.hh:325
void get_row(unsigned nr, vector< TYPE > &R) const
unsigned num_cols() const
Definition GenericContainer.hh:366
TYPE * data()
Definition GenericContainer.hh:445
mat_type(unsigned nr, unsigned nc)
Definition GenericContainer.hh:189
void getColumn(unsigned nc, TYPE *C) const
Definition GenericContainer.hh:305
void get_column(unsigned nc, TYPE *C) const
Definition GenericContainer.cc:177
void resize(T1 const nr, T2 const nc)
Definition GenericContainer.hh:215
void get_column(unsigned nc, vector< TYPE > &C) const
void get_row(T const nr, vector< TYPE > &R) const
Definition GenericContainer.hh:267
mat_type()=default
Default constructor that creates an empty matrix.
string_type info() const
Definition GenericContainer.hh:428
unsigned num_rows() const
Definition GenericContainer.hh:348
void getRow(unsigned nr, vector< TYPE > &R) const
Definition GenericContainer.hh:276
unsigned numCols() const
Definition GenericContainer.hh:371
TYPE const * data() const
Definition GenericContainer.hh:458
TYPE const & operator()(unsigned i, unsigned j) const
Definition GenericContainer.cc:140
Definition GenericContainer.cc:68
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
string_view to_string(GC_type const s)
Converts the GC_type enum value to a string representation.
Definition GenericContainer.cc:285
void string_escape(ostream_type &stream, string const &s)
unsigned stream_number_precision
Definition GenericContainer.cc:73
void writeTable(vec_string_type const &headers, vector_type const &data, ostream_type &stream, char delimiter='\t')
Definition GenericContainer.hh:4956
mat_type< complex_type > mat_complex_type
Definition GenericContainer.hh:472
enum class GC_type :int_type { 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
Enum class representing types allowed for the GenericContainer.
Definition GenericContainer.hh:517
std::basic_ostream< char > ostream_type
Alias for a character-based output stream.
Definition GenericContainer.hh:109
void writeTableFormatted(vec_string_type const &headers, vector_type const &data, ostream_type &stream)
Definition GenericContainer.hh:5014
void write_table(vec_string_type const &headers, vector_type const &data, ostream_type &stream, char delimiter='\t')
ostream_type & operator<<(ostream_type &s, vector< TYPE > const &v)
Overload of the operator<< for printing a vector of elements of a generic type.
void write_table_formatted(vec_string_type const &headers, vector_type const &data, ostream_type &stream)
std::basic_istream< char > istream_type
Alias for a character-based input stream.
Definition GenericContainer.hh:118