GenericContainer
GenericContainer a tool for C++ programming
Loading...
Searching...
No Matches
GenericContainer.hh
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2013 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Enrico Bertolazzi |
14 | Dipartimento di Ingegneria Industriale |
15 | Università degli Studi di Trento |
16 | email: enrico.bertolazzi@unitn.it |
17 | |
18\*--------------------------------------------------------------------------*/
19
20//
21// file: GenericContainer.hh
22//
23
24#pragma once
25
26#ifndef GENERIC_CONTAINER_HH
27#define GENERIC_CONTAINER_HH
28
29#ifdef __clang__
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"
35#endif
36
37#include <iostream>
38#include <string>
39#include <string_view>
40#include <complex>
41#include <map>
42#include <deque>
43#include <vector>
44#include <sstream>
45#include <iomanip>
46#include <stdexcept>
47
49
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
51
52#ifndef GC_DO_ERROR
53 #define GC_DO_ERROR(MSG) { \
54 ostringstream ost; \
55 ost << "in GenericContainer: " << MSG << '\n'; \
56 GenericContainer::exception( ost.str().data() ); \
57 }
58#endif
59
60#ifndef GC_ASSERT
61 #define GC_ASSERT(COND,MSG) if ( !(COND) ) GC_DO_ERROR(MSG)
62#endif
63
64#ifndef GC_WARNING
65 #define GC_WARNING(COND,MSG) \
66 if ( !(COND) ) { \
67 cout << "On line: " << __LINE__ \
68 << " file: " << __FILE__ \
69 << " in GenericContainer\nWARNING: " << MSG << '\n'; \
70 }
71#endif
72
73#ifdef __GNUC__
74 #define GC_NO_RETURN __attribute__ ((noreturn))
75#else
76 #define GC_NO_RETURN
77#endif
78
79#endif
80
84namespace GC_namespace {
85
86 using std::cin;
87 using std::cout;
88 using std::endl;
89 using std::string;
90 using std::string_view;
91 using std::complex;
92 using std::vector;
93 using std::map;
94 using std::deque;
95 using std::istringstream;
96 using std::ostringstream;
97 using std::runtime_error;
98 using std::exception;
99
100 extern unsigned stream_number_precision;
101
109 using ostream_type = std::basic_ostream<char>;
110
118 using istream_type = std::basic_istream<char>;
119
120 #ifndef DOXYGEN_SHOULD_SKIP_THIS
121
122 #if defined(GENERIC_CONTAINER_ON_WINDOWS) && defined(GENERIC_CONTAINER_USE_WINDOWS_TYPES)
123 #else
124 using std::uint8_t;
125 using std::int32_t;
126 using std::int64_t;
127 using std::uint32_t;
128 using std::uint64_t;
129 #endif
130
131 class GenericContainer;
132
133 typedef void* pointer_type;
134
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>;
155
156 #endif
157
158 // ---------------------------------------------------------------------------
168 template <typename TYPE>
169 class mat_type : public vector<TYPE> {
170 unsigned m_num_rows{0};
171 unsigned m_num_cols{0};
172 typedef typename vector<TYPE>::size_type size_type;
173 public:
174
176 mat_type() = default;
177
189 mat_type( unsigned nr, unsigned nc )
190 : m_num_rows(nr)
191 , m_num_cols(nc)
192 { vector<TYPE>::resize(size_type(nr*nc)); }
193
206 void
207 resize( unsigned const nr, unsigned const nc ) {
208 m_num_rows = nr;
209 m_num_cols = nc;
210 vector<TYPE>::resize(size_type(nr*nc));
211 }
212
213 template <typename T1, typename T2>
214 void
215 resize( T1 const nr, T2 const nc ) {
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) );
219 }
220
234 void get_column( unsigned nc, vector<TYPE> & C ) const;
235
236 template <typename T>
237 void
238 get_column( T const nc, vector<TYPE> & C ) const {
239 static_assert(std::is_integral_v<T>, "get_column() accepts only integral types as first argument!");
240 get_column( static_cast<unsigned>(nc), C );
241 }
242
246 void
247 getColumn( unsigned nc, vector<TYPE> & C ) const
248 { this->get_column( nc, C ); }
249
263 void get_row( unsigned nr, vector<TYPE> & R ) const;
264
265 template <typename T>
266 void
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 );
270 }
271
275 void
276 getRow( unsigned nr, vector<TYPE> & R ) const
277 { this->get_row( nr, R ); }
278
292 void get_column( unsigned nc, TYPE * C ) const;
293
294 template <typename T>
295 void
296 get_column( T const nc, TYPE * C ) const {
297 static_assert(std::is_integral_v<T>, "get_column() accepts only integral types as first argument!");
298 get_column( static_cast<unsigned>(nc), C );
299 }
300
304 void
305 getColumn( unsigned nc, TYPE * C ) const
306 { get_column( nc, C ); }
307
321 void get_row( unsigned nr, TYPE * R ) const;
322
323 template <typename T>
324 void
325 get_row( T const nr, TYPE * R ) const {
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 );
328 }
329
333 void
334 getRow( unsigned nr, TYPE * R ) const
335 { this->get_row( nr, R ); }
336
348 [[nodiscard]] unsigned num_rows() const { return m_num_rows; }
349
353 [[nodiscard]] unsigned numRows() const { return m_num_rows; }
354
366 [[nodiscard]] unsigned num_cols() const { return m_num_cols; }
367
371 [[nodiscard]] unsigned numCols() const { return m_num_cols; }
372
386 TYPE const & operator () ( unsigned i, unsigned j ) const;
387
401 TYPE & operator () ( unsigned i, unsigned j );
402
414 void info( ostream_type & stream ) const;
415
427 string_type
428 info() const {
429 ostringstream ostr;
430 this->info(ostr);
431 return ostr.str();
432 }
433
445 TYPE * data() { return &vector<TYPE>::front(); }
446
458 TYPE const * data() const { return &vector<TYPE>::front(); }
459 };
460
461 // ---------------------------------------------------------------------------
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>;
467 #endif
468
473
474 string to_string( complex_type const & v );
475
487 template <typename TYPE>
488 ostream_type & operator << ( ostream_type & s, vector<TYPE> const & v );
489
501 template <typename TYPE>
503
504 // ---------------------------------------------------------------------------
505
517 using TypeAllowed = enum class GC_type : int_type {
518 NOTYPE,
519 POINTER,
520 BOOL,
521 INTEGER,
522 LONG,
523 REAL,
524 COMPLEX,
525 STRING,
526
527 // Vector types
528 VEC_POINTER,
529 VEC_BOOL,
530 VEC_INTEGER,
531 VEC_LONG,
532 VEC_REAL,
533 VEC_COMPLEX,
534 VEC_STRING,
535
536 // Matrix types
537 MAT_INTEGER,
538 MAT_LONG,
539 MAT_REAL,
540 MAT_COMPLEX,
541
542 // Complex types
543 VECTOR,
544 MAP
545 };
546
563 string_view to_string(GC_type s);
564
615 public:
616 // Import type aliases from namespace `GC_namespace`
617 using pointer_type = GC_namespace::pointer_type;
618 using bool_type = GC_namespace::bool_type;
619 using int_type = GC_namespace::int_type;
620 using uint_type = GC_namespace::uint_type;
621 using long_type = GC_namespace::long_type;
622 using ulong_type = GC_namespace::ulong_type;
623 using real_type = GC_namespace::real_type;
624 using complex_type = GC_namespace::complex_type;
625 using string_type = GC_namespace::string_type;
626 using vec_pointer_type = GC_namespace::vec_pointer_type;
627 using vec_bool_type = GC_namespace::vec_bool_type;
628 using vec_int_type = GC_namespace::vec_int_type;
629 using vec_uint_type = GC_namespace::vec_uint_type;
630 using vec_long_type = GC_namespace::vec_long_type;
631 using vec_ulong_type = GC_namespace::vec_ulong_type;
632 using vec_real_type = GC_namespace::vec_real_type;
633 using vec_complex_type = GC_namespace::vec_complex_type;
634 using vec_string_type = GC_namespace::vec_string_type;
635 using vector_type = GC_namespace::vector_type;
636 using map_type = GC_namespace::map_type;
641
642 private:
643
650 using DataStorage = union {
651 pointer_type p;
652 bool_type b;
653 int_type i;
654 long_type l;
655 real_type r;
656 complex_type * c;
657 string_type * s;
658
659 vec_pointer_type * v_p;
660 vec_bool_type * v_b;
661 vec_int_type * v_i;
662 vec_long_type * v_l;
663 vec_real_type * v_r;
664 vec_complex_type * v_c;
665 vec_string_type * v_s;
666
667 mat_int_type * m_i;
668 mat_long_type * m_l;
669 mat_real_type * m_r;
670 mat_complex_type * m_c;
671
672 vector_type * v;
673 map_type * m;
674 };
675
676 DataStorage m_data;
677 TypeAllowed m_data_type{GC_type::NOTYPE};
678
680 void allocate_string();
681
683 void allocate_complex();
684
686 void allocate_vec_pointer(unsigned sz);
687
689 void allocate_vec_bool(unsigned sz);
690
692 void allocate_vec_int(unsigned sz);
693
695 void allocate_vec_long(unsigned sz);
696
698 void allocate_vec_real(unsigned sz);
699
701 void allocate_vec_complex(unsigned sz);
702
704 void allocate_mat_int(unsigned nr, unsigned nc);
705
707 void allocate_mat_long(unsigned nr, unsigned nc);
708
710 void allocate_mat_real(unsigned nr, unsigned nc);
711
713 void allocate_mat_complex(unsigned nr, unsigned nc);
714
716 void allocate_vec_string(unsigned sz);
717
719 void allocate_vector(unsigned sz);
720
722 void allocate_map();
723
725 void ck( string_view, TypeAllowed) const;
726
728 [[nodiscard]] int ck(TypeAllowed) const;
729
731 void ck_or_set(string_view, TypeAllowed);
732
734 #ifdef GENERIC_CONTAINER_ON_WINDOWS
735 bool simple_data() const;
736 #else
737 [[nodiscard]] bool simple_data() const { return m_data_type <= GC_type::STRING; }
738 #endif
739
741 #ifdef GENERIC_CONTAINER_ON_WINDOWS
742 bool simple_vec_data() const;
743 #else
744 [[nodiscard]] bool simple_vec_data() const { return m_data_type < GC_type::VEC_STRING; }
745 #endif
746
747 public:
748
761 GenericContainer() : m_data_type(GC_type::NOTYPE) {}
762
780
796 void clear();
797
817 void erase( string_view name ) const;
818
838 bool empty() const { return this->m_data_type != GC_type::NOTYPE; }
839
846
863 pointer_type & set_pointer( pointer_type value );
864
880 GenericContainer & free_pointer();
881
901 void get_keys( vec_string_type & keys ) const;
902
921 string get_keys() const;
922
938 bool_type & set_bool( bool_type value );
939
955 int_type & set_int( int_type value );
956
972 long_type & set_long( long_type value );
973
989 real_type & set_real( real_type value );
990
1007 complex_type & set_complex( complex_type const & value );
1008
1026 complex_type & set_complex( real_type re, real_type im );
1027
1043 string_type & set_string( string_view value );
1045
1046
1047
1048
1049
1057
1072 vec_pointer_type & set_vec_pointer( unsigned sz = 0 );
1073
1074 template <typename T>
1075 vec_pointer_type &
1077 static_assert(std::is_integral_v<T>, "set_vec_pointers() accepts only integral types!");
1078 return set_vec_pointer(static_cast<unsigned>(sz));
1079 }
1080
1095 vec_pointer_type & set_vec_pointer( vec_pointer_type const & v );
1096
1111 vec_bool_type & set_vec_bool( unsigned sz = 0 );
1112
1113 template <typename T>
1114 vec_bool_type &
1116 static_assert(std::is_integral_v<T>, "set_vec_bool() accepts only integral types!");
1117 return set_vec_bool(static_cast<unsigned>(sz));
1118 }
1119
1134 vec_bool_type & set_vec_bool( vec_bool_type const & v );
1135
1150 vec_int_type & set_vec_int( unsigned sz = 0 );
1151
1152 template <typename T>
1153 vec_int_type &
1154 set_vec_int( T sz ) {
1155 static_assert(std::is_integral_v<T>, "set_vec_ints() accepts only integral types!");
1156 return set_vec_int(static_cast<unsigned>(sz));
1157 }
1158
1173 vec_int_type & set_vec_int( vec_int_type const & v );
1174
1189 vec_long_type & set_vec_long( unsigned sz = 0 );
1190
1191 template <typename T>
1192 vec_long_type &
1194 static_assert(std::is_integral_v<T>, "set_vec_long() accepts only integral types!");
1195 return set_vec_long(static_cast<unsigned>(sz));
1196 }
1197
1212 vec_long_type & set_vec_long( vec_long_type const & v );
1213
1228 vec_real_type & set_vec_real( unsigned sz = 0 );
1229
1230 template <typename T>
1231 vec_real_type &
1233 static_assert(std::is_integral_v<T>, "set_vec_real() accepts only integral types!");
1234 return set_vec_real(static_cast<unsigned>(sz));
1235 }
1236
1251 vec_real_type & set_vec_real( vec_real_type const & v );
1252
1267 vec_complex_type & set_vec_complex( unsigned sz = 0 );
1268
1269 template <typename T>
1270 vec_complex_type &
1272 static_assert(std::is_integral_v<T>, "set_vec_complex() accepts only integral types!");
1273 return set_vec_complex(static_cast<unsigned>(sz));
1274 }
1275
1290 vec_complex_type & set_vec_complex( vec_complex_type const & v );
1291
1306 vec_string_type & set_vec_string( unsigned sz = 0 );
1307
1308 template <typename T>
1309 vec_string_type &
1311 static_assert(std::is_integral_v<T>, "set_vec_string() accepts only integral types!");
1312 return set_vec_string(static_cast<unsigned>(sz));
1313 }
1314
1329 vec_string_type & set_vec_string( vec_string_type const & v );
1330
1346 mat_int_type & set_mat_int( unsigned nr = 0, unsigned nc = 0 );
1347
1362 mat_int_type & set_mat_int( mat_int_type const & m );
1363
1379 mat_long_type & set_mat_long( unsigned nr = 0, unsigned nc = 0 );
1380
1395 mat_long_type & set_mat_long( mat_long_type const & m );
1396
1412 mat_real_type & set_mat_real( unsigned nr = 0, unsigned nc = 0 );
1413
1428 mat_real_type & set_mat_real( mat_real_type const & m );
1429
1445 mat_complex_type & set_mat_complex( unsigned nr = 0, unsigned nc = 0 );
1446
1461 mat_complex_type & set_mat_complex( mat_complex_type const & m );
1462
1469 void push_bool( bool b ) const;
1470
1477 void push_int( int_type i );
1478
1485 void push_long( long_type l );
1486
1493 void push_real( real_type r );
1494
1501 void push_complex( complex_type & c );
1502
1510 void push_complex( real_type re, real_type im );
1511
1518 void push_string( string_view s );
1519
1521
1522
1523
1524
1525
1526
1531
1544 vector_type & set_vector( unsigned sz = 0 );
1545
1556 map_type & set_map();
1557
1559
1560
1561
1562
1563
1564
1569
1601 TypeAllowed get_type() const { return m_data_type; }
1602
1612 string_view get_type_name() const { return to_string(get_type()); }
1613
1623 GenericContainer const & info( ostream_type & stream ) const;
1624
1633 string_type
1634 info() const {
1635 ostringstream sstr;
1636 this->info(sstr);
1637 return sstr.str();
1638 }
1639
1649 unsigned get_num_elements() const;
1650
1656 unsigned num_rows() const;
1660 unsigned get_numRows() const { return this->num_rows(); }
1661
1667 unsigned num_cols() const;
1671 unsigned get_numCols() const { return this->num_cols(); }
1672
1679 real_type get_number( string_view const where = "" ) const;
1680
1687 complex_type get_complex_number( string_view const where = "" ) const;
1688
1698 void get_complex_number( real_type & re, real_type & im ) const;
1699
1706 void * get_pvoid( string_view const where = "" ) const;
1707
1714 void ** get_ppvoid( string_view const where = "" ) const;
1715
1719 int_type const * get_int_pointer() const;
1720
1726 int_type * get_int_pointer();
1727
1733 long_type const * get_long_pointer() const;
1734
1740 long_type * get_long_pointer();
1741
1747 real_type const * get_real_pointer() const;
1748
1754 real_type * get_real_pointer();
1755
1761 complex_type const * get_complex_pointer() const;
1762
1768 complex_type * get_complex_pointer();
1769
1779 template <typename T>
1780 void
1781 get_value( T & v, string_view const where = "" ) const;
1782
1788 #ifdef GENERIC_CONTAINER_ON_WINDOWS
1789 template <typename T>
1790 T& get_pointer()
1791 { ck("get_pointer",GC_type::POINTER); return *reinterpret_cast<T*>(get_ppvoid()); }
1792
1796 template <typename T>
1797 T get_pointer() const
1798 { ck("get_pointer",GC_type::POINTER); return reinterpret_cast<T>(get_pvoid()); }
1799 #else
1800 template <typename T>
1802 { ck("get_pointer", GC_type::POINTER); return *static_cast<T*>(m_data.p); }
1803
1809 template <typename T>
1810 T get_pointer() const
1811 { ck("get_pointer",GC_type::POINTER); return reinterpret_cast<T>(m_data.p); }
1812 #endif
1813
1823 bool_type get_map_bool( string_view const key, string_view const where = "" ) const;
1824
1831 bool_type get_map_bool( std::initializer_list<string> args ) const;
1832
1842 bool_type get_map_bool( vec_string_type const & keys, string_view const where = "" ) const;
1843
1853 int_type get_map_int( string_view const key, string_view const where = "" ) const;
1854
1861 int_type get_map_int( std::initializer_list<string> args ) const;
1862
1873 int_type get_map_int( vec_string_type const & keys, string_view const where = "" ) const;
1874
1884 real_type get_map_number( string_view const key, string_view const where = "" ) const;
1885
1892 real_type get_map_number( std::initializer_list<string> args ) const;
1893
1904 real_type get_map_number( vec_string_type const & keys, string_view const where = "" ) const;
1905
1915 string const & get_map_string( string_view const key, string_view const where = "" ) const;
1916
1923 string const & get_map_string( std::initializer_list<string> args ) const;
1924
1935 string const & get_map_string( vec_string_type const & keys, string_view const where = "" ) const;
1936
1946 vec_real_type const & get_map_vec_real( string_view const key, string_view const where = "" ) const;
1947
1954 vec_real_type const & get_map_vec_real( std::initializer_list<string> args ) const;
1955
1966 vec_real_type const & get_map_vec_real( vec_string_type const & keys, string_view const where = "" ) const;
1967
1977 vec_complex_type const & get_map_vec_complex( string_view const key, string_view const where = "" ) const;
1978
1985 vec_complex_type const & get_map_vec_complex( std::initializer_list<string> args ) const;
1986
1997 vec_complex_type const & get_map_vec_complex( vec_string_type const & keys, string_view const where = "" ) const;
1998
2008 vec_string_type const & get_map_vec_string( string_view const key, string_view const where = "" ) const;
2009
2016 vec_string_type const & get_map_vec_string( std::initializer_list<string> args ) const;
2017
2028 vec_string_type const & get_map_vec_string( vec_string_type const & keys, string_view const where = "" ) const;
2029
2038 bool_type & get_bool( string_view const where = "" );
2039
2048 bool_type const & get_bool( string_view const where = "" ) const;
2049
2058 int_type & get_int( string_view const where = "" );
2059
2068 int_type const & get_int( string_view const where = "" ) const;
2069
2078 long_type & get_long( string_view const where = "" );
2079
2088 long_type const & get_long( string_view const where = "" ) const;
2089
2098 int_type get_as_int( string_view const where = "" ) const;
2099
2108 uint_type get_as_uint( string_view const where = "" ) const;
2109
2118 long_type get_as_long( string_view const where = "" ) const;
2119
2128 ulong_type get_as_ulong( string_view const where = "" ) const;
2129
2138 real_type & get_real( string_view const where = "" );
2139
2148 real_type const & get_real( string_view const where = "" ) const;
2149
2158 complex_type & get_complex( string_view const where = "" );
2159
2168 complex_type const & get_complex( string_view const where = "" ) const;
2169
2178 string_type & get_string( string_view const where = "" );
2179
2188 string_type const & get_string( string_view const where = "" ) const;
2189
2191
2192
2193
2194
2195
2196
2197
2198
2203
2204
2217 vector_type & get_vector( string_view const where = "" );
2218
2231 vector_type const & get_vector( string_view const where = "" ) const;
2232
2245 vec_pointer_type & get_vec_pointer( string_view const where = "" );
2246
2259 vec_pointer_type const & get_vec_pointer( string_view const where = "" ) const;
2260
2273 vec_bool_type & get_vec_bool( string_view const where = "" );
2274
2287 vec_bool_type const & get_vec_bool( string_view const where = "" ) const;
2288
2301 vec_int_type & get_vec_int( string_view = "" );
2302
2315 vec_int_type const & get_vec_int( string_view = "" ) const;
2316
2329 vec_long_type & get_vec_long( string_view = "" );
2330
2343 vec_long_type const & get_vec_long( string_view = "" ) const;
2344
2357 vec_real_type & get_vec_real( string_view = "" );
2358
2371 vec_real_type const & get_vec_real( string_view = "" ) const;
2372
2385 vec_complex_type & get_vec_complex( string_view = "" );
2386
2399 vec_complex_type const & get_vec_complex( string_view = "" ) const;
2400
2413 mat_int_type & get_mat_int( string_view = "" );
2414
2427 mat_int_type const & get_mat_int( string_view = "" ) const;
2428
2441 mat_long_type & get_mat_long( string_view = "" );
2442
2455 mat_long_type const & get_mat_long( string_view = "" ) const;
2456
2469 mat_real_type & get_mat_real( string_view = "" );
2470
2483 mat_real_type const & get_mat_real( string_view = "" ) const;
2484
2497 mat_complex_type & get_mat_complex( string_view = "" );
2498
2511 mat_complex_type const & get_mat_complex( string_view = "" ) const;
2512
2525 vec_string_type & get_vec_string( string_view = "" );
2526
2539 vec_string_type const & get_vec_string( string_view = "" ) const;
2540
2542
2543
2544
2545
2546
2547
2548
2553
2567 void copyto_vec_int( vec_int_type & v, string_view = "" ) const;
2568
2582 void copyto_vec_uint( vec_uint_type & v, string_view = "" ) const;
2583
2597 void copyto_vec_long( vec_long_type & v, string_view = "" ) const;
2598
2612 void copyto_vec_ulong( vec_ulong_type & v, string_view = "" ) const;
2613
2627 void copyto_vec_real( vec_real_type & v, string_view = "" ) const;
2628
2642 void copyto_vec_complex( vec_complex_type & v, string_view = "" ) const;
2643
2657 void copyto_vec_string( vec_string_type & v, string_view = "" ) const;
2658
2660
2661
2662
2663
2668
2682 void copyto_mat_int( mat_int_type & m, string_view = "" ) const;
2683
2697 void copyto_mat_long( mat_long_type & m, string_view = "" ) const;
2698
2712 void copyto_mat_real( mat_real_type & m, string_view = "" ) const;
2713
2727 void copyto_mat_complex( mat_complex_type & m, string_view = "" ) const;
2728
2730
2731
2732
2733
2734
2735
2740
2741
2756 real_type get_number_at( unsigned i, string_view = "" ) const;
2757
2772 complex_type get_complex_number_at( unsigned i, string_view = "" ) const;
2773
2790 void get_complex_number_at( unsigned i, real_type & re, real_type & im, string_view = "" ) const;
2791
2804 template <typename T>
2805 T& get_pointer_at( unsigned i )
2806 { return (*this)[i].get_pointer<T>(); }
2807
2820 template <typename T>
2821 T get_pointer_at( unsigned i ) const
2822 { return (*this)[i].get_pointer<T>(); }
2824
2837 bool_type get_bool_at( unsigned i );
2838
2839 template <typename T>
2840 bool_type
2842 static_assert(std::is_integral_v<T>, "get_bool_at() accepts only integral types!");
2843 return get_bool_at(static_cast<unsigned>(i));
2844 }
2845
2859 bool_type get_bool_at( unsigned i, string_view const where ) const;
2860
2873 int_type & get_int_at( unsigned i );
2874
2875 template <typename T>
2876 int_type &
2877 get_int_at( T i ) {
2878 static_assert(std::is_integral_v<T>, "get_int_at() accepts only integral types!");
2879 return get_int_at(static_cast<unsigned>(i));
2880 }
2881
2895 int_type const & get_int_at( unsigned i, string_view const where ) const;
2896
2909 long_type & get_long_at( unsigned i );
2910
2911 template <typename T>
2912 long_type &
2914 static_assert(std::is_integral_v<T>, "get_long_at() accepts only integral types!");
2915 return get_long_at(static_cast<unsigned>(i));
2916 }
2917
2931 long_type const & get_long_at( unsigned i, string_view const where ) const;
2932
2945 real_type & get_real_at( unsigned i );
2946
2947 template <typename T>
2949 static_assert(std::is_integral_v<T>, "get_real_at() accepts only integral types!");
2950 return get_real_at(static_cast<unsigned>(i));
2951 }
2952
2966 real_type const & get_real_at( unsigned i, string_view const where ) const;
2967
2980 complex_type & get_complex_at( unsigned i );
2981
2982 template <typename T>
2984 static_assert(std::is_integral_v<T>, "get_complex_at() accepts only integral types!");
2985 return get_complex_at(static_cast<unsigned>(i));
2986 }
2987
3001 complex_type const & get_complex_at( unsigned i, string_view const where ) const;
3002
3016 int_type & get_int_at( unsigned i, unsigned j );
3017
3032 int_type const & get_int_at( unsigned i, unsigned j, string_view const where ) const;
3033
3047 long_type & get_long_at( unsigned i, unsigned j );
3048
3063 long_type const & get_long_at( unsigned i, unsigned j, string_view const where ) const;
3064
3078 real_type & get_real_at( unsigned i, unsigned j );
3079
3094 real_type const & get_real_at( unsigned i, unsigned j, string_view const where ) const;
3095
3109 complex_type & get_complex_at( unsigned i, unsigned j );
3110
3125 complex_type const & get_complex_at( unsigned i, unsigned j, string_view const where ) const;
3126
3139 string_type & get_string_at( unsigned i );
3140
3141 template <typename T>
3142 string_type &
3144 static_assert(std::is_integral_v<T>, "get_string_at() accepts only integral types!");
3145 return get_string_at(static_cast<unsigned>(i));
3146 }
3147
3161 string_type const & get_string_at( unsigned i, string_view const where ) const;
3162
3175 GenericContainer & get_gc_at( unsigned i );
3176
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));
3181 }
3182
3196 GenericContainer const & get_gc_at( unsigned i, string_view const where ) const;
3197
3199
3200
3201
3202
3203
3204
3205
3206
3211
3230 map_type & get_map( string_view = "" );
3231
3250 map_type const & get_map( string_view = "" ) const;
3251
3253
3254
3255
3260
3273 GenericContainer & operator [] ( unsigned i );
3274
3287 GenericContainer const & operator [] ( unsigned i ) const;
3288
3301 GenericContainer & operator [] ( string_view s );
3302
3315 GenericContainer const & operator [] ( string_view s ) const;
3316
3334 GenericContainer & operator () ( unsigned i, string_view = "" );
3335
3353 GenericContainer const & operator () ( unsigned i, string_view = "" ) const;
3354
3368 GenericContainer & operator () ( string_view s, string_view = "" );
3369
3383 GenericContainer const & operator () ( string_view s, string_view = "" ) const;
3384
3399 GenericContainer & operator () ( vec_string_type const & vs, string_view = "" );
3400
3415 GenericContainer const & operator () ( vec_string_type const & vs, string_view = "" ) const;
3416
3418
3419
3420
3421
3422
3423
3424
3425
3426
3431
3443 void set( bool const & a ) { this->set_bool(a); }
3444
3456 void set( uint_type const & a ) { this->set_int(int_type(a)); }
3457
3469 void set( int_type const & a ) { this->set_int(a); }
3470
3482 void set( ulong_type const & a ) { this->set_long(long_type(a)); }
3483
3495 void set( long_type const & a ) { this->set_long(a); }
3496
3508 void set( float const & a ) { this->set_real(real_type(a)); }
3509
3521 void set( double const & a ) { this->set_real(real_type(a)); }
3522
3535 void set( complex<float> const & a )
3536 { this->set_complex(real_type(a.real()),real_type(a.imag())); }
3537
3550 void set( complex<double> const & a )
3551 { this->set_complex(real_type(a.real()),real_type(a.imag())); }
3552
3564 void set( char const * a ) { this->set_string(a); }
3565
3577 void set( string_view a ) { this->set_string(a); }
3578
3591 void set( pointer_type a ) { this->set_pointer(a); }
3592
3594
3595
3596
3597
3598
3607
3613 GenericContainer & operator = ( bool const & a )
3614 { this->set_bool(a); return * this; }
3615
3621 GenericContainer & operator = ( uint_type const & a )
3622 { this->set_int(int_type(a)); return * this; }
3623
3629 GenericContainer & operator = ( int_type const & a )
3630 { this->set_int(a); return * this; }
3631
3637 GenericContainer & operator = ( ulong_type const & a )
3638 { this->set_long(long_type(a)); return * this; }
3639
3645 GenericContainer & operator = ( long_type const & a )
3646 { this->set_long(a); return * this; }
3647
3653 GenericContainer & operator = ( float const & a )
3654 { this->set_real(real_type(a)); return * this; }
3655
3661 GenericContainer & operator = ( double const & a )
3662 { this->set_real(real_type(a)); return * this; }
3663
3669 GenericContainer & operator = ( complex<float> const & a )
3670 { this->set_complex(real_type(a.real()),real_type(a.imag())); return * this; }
3671
3677 GenericContainer & operator = ( complex<double> const & a )
3678 { this->set_complex(real_type(a.real()),real_type(a.imag())); return * this; }
3679
3685 GenericContainer & operator = ( vec_bool_type const & a );
3686
3692 GenericContainer & operator = ( vec_int_type const & a );
3693
3699 GenericContainer & operator = ( vec_long_type const & a );
3700
3706 GenericContainer & operator = ( vec_real_type const & a );
3707
3713 GenericContainer & operator = ( vec_complex_type const & a );
3714
3720 GenericContainer & operator = ( vec_string_type const & a );
3721
3727 GenericContainer & operator = ( mat_int_type const & a );
3728
3734 GenericContainer & operator = ( mat_long_type const & a );
3735
3741 GenericContainer & operator = ( mat_real_type const & a );
3742
3748 GenericContainer & operator = ( mat_complex_type const & a );
3749
3755 GenericContainer & operator = ( const char * a )
3756 { this->set_string(a); return * this; }
3757
3763 GenericContainer & operator = ( string const & a )
3764 { this->set_string(a); return * this; }
3765
3771 GenericContainer & operator = ( string_view a )
3772 { this->set_string(a); return * this; }
3773
3780 { this->set_pointer(a); return * this; }
3781
3787 GenericContainer const & operator = ( GenericContainer const & a )
3788 { this->clear(); this->from_gc( a ); return * this; }
3789
3795 void load( GenericContainer const & a ) { this->from_gc(a); }
3797
3805 GenericContainer const & promote_to_int();
3806
3810 GenericContainer const & promote_to_long();
3811
3815 GenericContainer const & promote_to_real();
3816
3821 GenericContainer const & promote_to_complex();
3822
3826 GenericContainer const & promote_to_vec_int();
3827
3831 GenericContainer const & promote_to_vec_long();
3832
3837 GenericContainer const & promote_to_vec_real();
3838
3843 GenericContainer const & promote_to_vec_complex();
3844
3849 GenericContainer const & promote_to_mat_int();
3850
3855 GenericContainer const & promote_to_mat_long();
3856
3861 GenericContainer const & promote_to_mat_real();
3862
3867 GenericContainer const & promote_to_mat_complex();
3868
3873 GenericContainer const & promote_to_vector();
3874
3876
3881
3886 GenericContainer( bool const & a )
3887 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3888
3894 : m_data_type(GC_type::NOTYPE) { *this = a; }
3895
3901 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3902
3908 : m_data_type(GC_type::NOTYPE) { *this = a; }
3909
3915 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3916
3921 GenericContainer( float const & a )
3922 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3923
3928 GenericContainer( double const & a )
3929 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3930
3935 GenericContainer( complex<float> const & a )
3936 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3937
3942 GenericContainer( complex<double> const & a )
3943 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3944
3949 GenericContainer( char const * a )
3950 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3951
3956 GenericContainer( string const & a )
3957 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3958
3963 GenericContainer( string_view a )
3964 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3965
3971 : m_data_type(GC_type::NOTYPE) { this->set_pointer(a); }
3972
3978 : m_data_type(GC_type::NOTYPE) { this->from_gc(gc); }
3979
3981
3986
3991 bool exists( string_view s ) const;
3992
3998 bool exists( vec_string_type const & vs ) const;
3999
4006 string must_exists( vec_string_type const & vs, string_view const where ) const;
4007
4013 bool get_if_exists( string_view field, bool & value ) const;
4014
4021 bool get_if_exists( vec_string_type const & fields, bool & value ) const;
4022
4028 bool get_if_exists( string_view field, int_type & value ) const;
4029
4035 bool get_if_exists( string_view field, uint_type & value ) const;
4036
4042 bool get_if_exists( string_view field, long_type & value ) const;
4043
4049 bool get_if_exists( string_view field, ulong_type & value ) const;
4050
4056 bool get_if_exists( string_view field, real_type & value ) const;
4057
4063 bool get_if_exists( string_view field, complex_type & value ) const;
4064
4070 bool get_if_exists( string_view field, string_type & value ) const;
4071
4078 template <typename T>
4079 bool
4080 get_if_exists( vec_string_type const & fields, T & value ) const {
4081 for ( string_view field : fields ) {
4082 if ( get_if_exists( field, value ) ) return true;
4083 }
4084 return false;
4085 }
4086
4092 template <typename T>
4093 bool
4094 get_if_exists( char const field[], T & value ) const {
4095 string_type field_str(field);
4096 return get_if_exists( field_str, value );
4097 }
4098
4100
4105
4133 void
4134 print_content_types(
4135 ostream_type & stream,
4136 string_view prefix = "",
4137 string_view indent = " "
4138 ) const;
4139
4166 string
4167 compare_content( GenericContainer const & gc, string_view from = "" ) const;
4168
4195 void
4196 dump(
4197 ostream_type & stream,
4198 string_view prefix = "",
4199 string_view indent = " "
4200 ) const;
4201
4228 void
4230 ostream_type & stream,
4231 string_view prefix = "",
4232 string_view indent = " "
4233 ) const {
4234 this->dump( stream, prefix, indent );
4235 }
4236
4265 string_type
4267 string_view prefix = "",
4268 string_view indent = " "
4269 ) const {
4270 ostringstream ostr;
4271 ostr.precision(stream_number_precision);
4272 this->print(ostr,prefix,indent);
4273 return ostr.str();
4274 }
4275
4292 void to_gc( GenericContainer & gc ) const;
4293
4310 void from_gc( GenericContainer const & gc );
4311
4331 void merge( GenericContainer const & gc, string_view const where );
4332
4352 bool from_file( string_view file_name );
4353
4373 void to_yaml( ostream_type & stream, string_view prefix = "" ) const;
4374
4393 string
4394 to_yaml( string_view prefix = "" ) const
4395 { ostringstream ss; this->to_yaml( ss, prefix ); return ss.str(); }
4396
4417 bool from_yaml( istream_type & stream );
4418
4437 bool from_yaml( string const & data ) { istringstream ss(data); return this->from_yaml( ss ); }
4438
4453 static
4454 GenericContainer gc_from_yaml( string const & yaml ) {
4456 gc.from_yaml(yaml);
4457 return gc;
4458 }
4459
4479 void to_json( ostream_type & stream, string_view prefix = "" ) const;
4480
4481 string
4482 to_json( string_view prefix = "" ) const
4483 { ostringstream ss; this->to_json( ss, prefix ); return ss.str();}
4484
4503 bool from_json( istream_type & stream );
4504 bool from_json2( istream_type & stream );
4505
4506 bool from_json( string const & data ) { istringstream ss(data); return this->from_json( ss ); }
4507
4523 static
4524 GenericContainer gc_from_json( string const & json ) {
4526 gc.from_json(json);
4527 return gc;
4528 }
4529
4548 bool to_toml( ostream_type & stream ) const;
4549
4550 string
4551 to_toml() const
4552 { ostringstream ss; this->to_toml( ss ); return ss.str();}
4553
4571 bool from_toml( istream_type & stream );
4572
4591 bool from_toml( string const & data ) { istringstream ss(data); return this->from_toml( ss ); }
4592
4607 static
4608 GenericContainer gc_from_toml( string const & toml ) {
4610 gc.from_toml(toml);
4611 return gc;
4612 }
4613
4618 void collapse();
4619
4641 GenericContainer const &
4642 write_formatted_data( ostream_type & stream, char const delimiter = '\t' ) const;
4643
4647 GenericContainer const &
4648 writeFormattedData( ostream_type & stream, char const delimiter = '\t' ) const {
4649 return this->write_formatted_data( stream, delimiter );
4650 }
4651
4671 istream_type & stream,
4672 char const commentChars[] = "#%",
4673 char const delimiters[] = " \t"
4674 );
4675
4681 istream_type & stream,
4682 char const commentChars[] = "#%",
4683 char const delimiters[] = " \t"
4684 ) {
4685 return read_formatted_data( stream, commentChars, delimiters );
4686 }
4687
4706 char const fname[],
4707 char const commentChars[] = "#%",
4708 char const delimiters[] = " \t"
4709 );
4710
4716 char const fname[],
4717 char const commentChars[] = "#%",
4718 char const delimiters[] = " \t"
4719 ) {
4720 return read_formatted_data( fname, commentChars, delimiters );
4721 }
4722
4743 istream_type & stream,
4744 char const commentChars[] = "#%",
4745 char const delimiters[] = " \t",
4746 GenericContainer ptr_pars[] = nullptr
4747 );
4748
4754 istream_type & stream,
4755 char const commentChars[] = "#%",
4756 char const delimiters[] = " \t",
4757 GenericContainer ptr_pars[] = nullptr
4758 ) {
4759 return read_formatted_data2( stream, commentChars, delimiters, ptr_pars );
4760 }
4761
4781 char const fname[],
4782 char const commentChars[] = "#%",
4783 char const delimiters[] = " \t",
4784 GenericContainer ptr_pars[] = nullptr
4785 );
4786
4792 char const fname[],
4793 char const commentChars[] = "#%",
4794 char const delimiters[] = " \t",
4795 GenericContainer ptr_pars[] = nullptr
4796 ) {
4797 return read_formatted_data2( fname, commentChars, delimiters, ptr_pars );
4798 }
4799
4800
4805
4810 int32_t mem_size() const;
4811
4833 int32_t serialize( int32_t buffer_dim, uint8_t * buffer ) const;
4834
4853 int32_t serialize( vector<uint8_t> & buffer ) const;
4854
4871 std::vector<uint8_t>
4872 serialize() const {
4873 std::vector<uint8_t> buffer( static_cast<std::size_t>(mem_size()) ); // allocate required space
4874 serialize(static_cast<int32_t>(buffer.size()), buffer.data());
4875 return buffer;
4876 }
4877
4897 int32_t de_serialize( int32_t buffer_dim, uint8_t const * buffer );
4898
4918 int32_t de_serialize( vector<uint8_t> const & buffer );
4919
4921
4927 static
4928 void
4929 exception( string_view const where ) GC_NO_RETURN;
4930
4931 };
4932
4933 // -------------------------------------------------------
4934 // support functions
4943 void
4945 vec_string_type const & headers,
4946 vector_type const & data,
4947 ostream_type & stream,
4948 char delimiter = '\t'
4949 );
4950
4954 inline
4955 void
4957 vec_string_type const & headers,
4958 vector_type const & data,
4959 ostream_type & stream,
4960 char delimiter = '\t'
4961 ) {
4962 write_table( headers, data, stream, delimiter );
4963 }
4964
4973 void
4975 vec_string_type const & headers,
4976 mat_real_type const & data,
4977 ostream_type & stream,
4978 char delimiter = '\t'
4979 );
4980
4984 inline
4985 void
4987 vec_string_type const & headers,
4988 mat_real_type const & data,
4989 ostream_type & stream,
4990 char delimiter = '\t'
4991 ) {
4992 write_table( headers, data, stream, delimiter );
4993 }
4994
5002 void
5004 vec_string_type const & headers,
5005 vector_type const & data,
5006 ostream_type & stream
5007 );
5008
5012 inline
5013 void
5015 vec_string_type const & headers,
5016 vector_type const & data,
5017 ostream_type & stream
5018 ) {
5019 write_table_formatted( headers, data, stream );
5020 }
5021
5029 void
5031 vec_string_type const & headers,
5032 mat_real_type const & data,
5033 ostream_type & stream
5034 );
5035
5039 inline
5040 void
5042 vec_string_type const & headers,
5043 mat_real_type const & data,
5044 ostream_type & stream
5045 ) {
5046 write_table_formatted( headers, data, stream );
5047 }
5048
5052 void string_escape( ostream_type & stream, string const & s );
5053
5054}
5055
5056#ifndef DOXYGEN_SHOULD_SKIP_THIS
5057
5058 // do not define alias GC if use X11
5059 #ifndef XlibSpecificationRelease
5060 namespace GC = GC_namespace;
5061 #endif
5062
5063 // for backward compatibility
5064 namespace GenericContainerNamespace = GC_namespace;
5065
5066#endif
5067
5068#ifdef __clang__
5069#pragma clang diagnostic pop
5070#endif
5071
5072#endif
5073
5074//
5075// eof: GenericContainer.hh
5076//
void collapse()
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