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
825
842 pointer_type & set_pointer( pointer_type value );
843
859 GenericContainer & free_pointer();
860
880 void get_keys( vec_string_type & keys ) const;
881
900 string get_keys() const;
901
917 bool_type & set_bool( bool_type value );
918
934 int_type & set_int( int_type value );
935
951 long_type & set_long( long_type value );
952
968 real_type & set_real( real_type value );
969
986 complex_type & set_complex( complex_type const & value );
987
1005 complex_type & set_complex( real_type re, real_type im );
1006
1022 string_type & set_string( string_view value );
1024
1025
1026
1027
1028
1036
1051 vec_pointer_type & set_vec_pointer( unsigned sz = 0 );
1052
1053 template <typename T>
1054 vec_pointer_type &
1056 static_assert(std::is_integral_v<T>, "set_vec_pointers() accepts only integral types!");
1057 return set_vec_pointer(static_cast<unsigned>(sz));
1058 }
1059
1074 vec_pointer_type & set_vec_pointer( vec_pointer_type const & v );
1075
1090 vec_bool_type & set_vec_bool( unsigned sz = 0 );
1091
1092 template <typename T>
1093 vec_bool_type &
1095 static_assert(std::is_integral_v<T>, "set_vec_bool() accepts only integral types!");
1096 return set_vec_bool(static_cast<unsigned>(sz));
1097 }
1098
1113 vec_bool_type & set_vec_bool( vec_bool_type const & v );
1114
1129 vec_int_type & set_vec_int( unsigned sz = 0 );
1130
1131 template <typename T>
1132 vec_int_type &
1133 set_vec_int( T sz ) {
1134 static_assert(std::is_integral_v<T>, "set_vec_ints() accepts only integral types!");
1135 return set_vec_int(static_cast<unsigned>(sz));
1136 }
1137
1152 vec_int_type & set_vec_int( vec_int_type const & v );
1153
1168 vec_long_type & set_vec_long( unsigned sz = 0 );
1169
1170 template <typename T>
1171 vec_long_type &
1173 static_assert(std::is_integral_v<T>, "set_vec_long() accepts only integral types!");
1174 return set_vec_long(static_cast<unsigned>(sz));
1175 }
1176
1191 vec_long_type & set_vec_long( vec_long_type const & v );
1192
1207 vec_real_type & set_vec_real( unsigned sz = 0 );
1208
1209 template <typename T>
1210 vec_real_type &
1212 static_assert(std::is_integral_v<T>, "set_vec_real() accepts only integral types!");
1213 return set_vec_real(static_cast<unsigned>(sz));
1214 }
1215
1230 vec_real_type & set_vec_real( vec_real_type const & v );
1231
1246 vec_complex_type & set_vec_complex( unsigned sz = 0 );
1247
1248 template <typename T>
1249 vec_complex_type &
1251 static_assert(std::is_integral_v<T>, "set_vec_complex() accepts only integral types!");
1252 return set_vec_complex(static_cast<unsigned>(sz));
1253 }
1254
1269 vec_complex_type & set_vec_complex( vec_complex_type const & v );
1270
1285 vec_string_type & set_vec_string( unsigned sz = 0 );
1286
1287 template <typename T>
1288 vec_string_type &
1290 static_assert(std::is_integral_v<T>, "set_vec_string() accepts only integral types!");
1291 return set_vec_string(static_cast<unsigned>(sz));
1292 }
1293
1308 vec_string_type & set_vec_string( vec_string_type const & v );
1309
1325 mat_int_type & set_mat_int( unsigned nr = 0, unsigned nc = 0 );
1326
1341 mat_int_type & set_mat_int( mat_int_type const & m );
1342
1358 mat_long_type & set_mat_long( unsigned nr = 0, unsigned nc = 0 );
1359
1374 mat_long_type & set_mat_long( mat_long_type const & m );
1375
1391 mat_real_type & set_mat_real( unsigned nr = 0, unsigned nc = 0 );
1392
1407 mat_real_type & set_mat_real( mat_real_type const & m );
1408
1424 mat_complex_type & set_mat_complex( unsigned nr = 0, unsigned nc = 0 );
1425
1440 mat_complex_type & set_mat_complex( mat_complex_type const & m );
1441
1448 void push_bool( bool b ) const;
1449
1456 void push_int( int_type i );
1457
1464 void push_long( long_type l );
1465
1472 void push_real( real_type r );
1473
1480 void push_complex( complex_type & c );
1481
1489 void push_complex( real_type re, real_type im );
1490
1497 void push_string( string_view s );
1498
1500
1501
1502
1503
1504
1505
1510
1523 vector_type & set_vector( unsigned sz = 0 );
1524
1535 map_type & set_map();
1536
1538
1539
1540
1541
1542
1543
1548
1580 TypeAllowed get_type() const { return m_data_type; }
1581
1591 string_view get_type_name() const { return to_string(get_type()); }
1592
1602 GenericContainer const & info( ostream_type & stream ) const;
1603
1612 string_type
1613 info() const {
1614 ostringstream sstr;
1615 this->info(sstr);
1616 return sstr.str();
1617 }
1618
1628 unsigned get_num_elements() const;
1629
1635 unsigned num_rows() const;
1639 unsigned get_numRows() const { return this->num_rows(); }
1640
1646 unsigned num_cols() const;
1650 unsigned get_numCols() const { return this->num_cols(); }
1651
1658 real_type get_number( string_view const where = "" ) const;
1659
1666 complex_type get_complex_number( string_view const where = "" ) const;
1667
1677 void get_complex_number( real_type & re, real_type & im ) const;
1678
1685 void * get_pvoid( string_view const where = "" ) const;
1686
1693 void ** get_ppvoid( string_view const where = "" ) const;
1694
1698 int_type const * get_int_pointer() const;
1699
1705 int_type * get_int_pointer();
1706
1712 long_type const * get_long_pointer() const;
1713
1719 long_type * get_long_pointer();
1720
1726 real_type const * get_real_pointer() const;
1727
1733 real_type * get_real_pointer();
1734
1740 complex_type const * get_complex_pointer() const;
1741
1747 complex_type * get_complex_pointer();
1748
1758 template <typename T>
1759 void
1760 get_value( T & v, string_view const where = "" ) const;
1761
1767 #ifdef GENERIC_CONTAINER_ON_WINDOWS
1768 template <typename T>
1769 T& get_pointer()
1770 { ck("get_pointer",GC_type::POINTER); return *reinterpret_cast<T*>(get_ppvoid()); }
1771
1775 template <typename T>
1776 T get_pointer() const
1777 { ck("get_pointer",GC_type::POINTER); return reinterpret_cast<T>(get_pvoid()); }
1778 #else
1779 template <typename T>
1781 { ck("get_pointer", GC_type::POINTER); return *static_cast<T*>(m_data.p); }
1782
1788 template <typename T>
1789 T get_pointer() const
1790 { ck("get_pointer",GC_type::POINTER); return reinterpret_cast<T>(m_data.p); }
1791 #endif
1792
1802 bool_type get_map_bool( string_view const key, string_view const where = "" ) const;
1803
1810 bool_type get_map_bool( std::initializer_list<string> args ) const;
1811
1821 bool_type get_map_bool( vec_string_type const & keys, string_view const where = "" ) const;
1822
1832 int_type get_map_int( string_view const key, string_view const where = "" ) const;
1833
1840 int_type get_map_int( std::initializer_list<string> args ) const;
1841
1852 int_type get_map_int( vec_string_type const & keys, string_view const where = "" ) const;
1853
1863 real_type get_map_number( string_view const key, string_view const where = "" ) const;
1864
1871 real_type get_map_number( std::initializer_list<string> args ) const;
1872
1883 real_type get_map_number( vec_string_type const & keys, string_view const where = "" ) const;
1884
1894 string const & get_map_string( string_view const key, string_view const where = "" ) const;
1895
1902 string const & get_map_string( std::initializer_list<string> args ) const;
1903
1914 string const & get_map_string( vec_string_type const & keys, string_view const where = "" ) const;
1915
1925 vec_real_type const & get_map_vec_real( string_view const key, string_view const where = "" ) const;
1926
1933 vec_real_type const & get_map_vec_real( std::initializer_list<string> args ) const;
1934
1945 vec_real_type const & get_map_vec_real( vec_string_type const & keys, string_view const where = "" ) const;
1946
1956 vec_complex_type const & get_map_vec_complex( string_view const key, string_view const where = "" ) const;
1957
1964 vec_complex_type const & get_map_vec_complex( std::initializer_list<string> args ) const;
1965
1976 vec_complex_type const & get_map_vec_complex( vec_string_type const & keys, string_view const where = "" ) const;
1977
1987 vec_string_type const & get_map_vec_string( string_view const key, string_view const where = "" ) const;
1988
1995 vec_string_type const & get_map_vec_string( std::initializer_list<string> args ) const;
1996
2007 vec_string_type const & get_map_vec_string( vec_string_type const & keys, string_view const where = "" ) const;
2008
2017 bool_type & get_bool( string_view const where = "" );
2018
2027 bool_type const & get_bool( string_view const where = "" ) const;
2028
2037 int_type & get_int( string_view const where = "" );
2038
2047 int_type const & get_int( string_view const where = "" ) const;
2048
2057 long_type & get_long( string_view const where = "" );
2058
2067 long_type const & get_long( string_view const where = "" ) const;
2068
2077 int_type get_as_int( string_view const where = "" ) const;
2078
2087 uint_type get_as_uint( string_view const where = "" ) const;
2088
2097 long_type get_as_long( string_view const where = "" ) const;
2098
2107 ulong_type get_as_ulong( string_view const where = "" ) const;
2108
2117 real_type & get_real( string_view const where = "" );
2118
2127 real_type const & get_real( string_view const where = "" ) const;
2128
2137 complex_type & get_complex( string_view const where = "" );
2138
2147 complex_type const & get_complex( string_view const where = "" ) const;
2148
2157 string_type & get_string( string_view const where = "" );
2158
2167 string_type const & get_string( string_view const where = "" ) const;
2168
2170
2171
2172
2173
2174
2175
2176
2177
2182
2183
2196 vector_type & get_vector( string_view const where = "" );
2197
2210 vector_type const & get_vector( string_view const where = "" ) const;
2211
2224 vec_pointer_type & get_vec_pointer( string_view const where = "" );
2225
2238 vec_pointer_type const & get_vec_pointer( string_view const where = "" ) const;
2239
2252 vec_bool_type & get_vec_bool( string_view const where = "" );
2253
2266 vec_bool_type const & get_vec_bool( string_view const where = "" ) const;
2267
2280 vec_int_type & get_vec_int( string_view = "" );
2281
2294 vec_int_type const & get_vec_int( string_view = "" ) const;
2295
2308 vec_long_type & get_vec_long( string_view = "" );
2309
2322 vec_long_type const & get_vec_long( string_view = "" ) const;
2323
2336 vec_real_type & get_vec_real( string_view = "" );
2337
2350 vec_real_type const & get_vec_real( string_view = "" ) const;
2351
2364 vec_complex_type & get_vec_complex( string_view = "" );
2365
2378 vec_complex_type const & get_vec_complex( string_view = "" ) const;
2379
2392 mat_int_type & get_mat_int( string_view = "" );
2393
2406 mat_int_type const & get_mat_int( string_view = "" ) const;
2407
2420 mat_long_type & get_mat_long( string_view = "" );
2421
2434 mat_long_type const & get_mat_long( string_view = "" ) const;
2435
2448 mat_real_type & get_mat_real( string_view = "" );
2449
2462 mat_real_type const & get_mat_real( string_view = "" ) const;
2463
2476 mat_complex_type & get_mat_complex( string_view = "" );
2477
2490 mat_complex_type const & get_mat_complex( string_view = "" ) const;
2491
2504 vec_string_type & get_vec_string( string_view = "" );
2505
2518 vec_string_type const & get_vec_string( string_view = "" ) const;
2519
2521
2522
2523
2524
2525
2526
2527
2532
2546 void copyto_vec_int( vec_int_type & v, string_view = "" ) const;
2547
2561 void copyto_vec_uint( vec_uint_type & v, string_view = "" ) const;
2562
2576 void copyto_vec_long( vec_long_type & v, string_view = "" ) const;
2577
2591 void copyto_vec_ulong( vec_ulong_type & v, string_view = "" ) const;
2592
2606 void copyto_vec_real( vec_real_type & v, string_view = "" ) const;
2607
2621 void copyto_vec_complex( vec_complex_type & v, string_view = "" ) const;
2622
2636 void copyto_vec_string( vec_string_type & v, string_view = "" ) const;
2637
2639
2640
2641
2642
2647
2661 void copyto_mat_int( mat_int_type & m, string_view = "" ) const;
2662
2676 void copyto_mat_long( mat_long_type & m, string_view = "" ) const;
2677
2691 void copyto_mat_real( mat_real_type & m, string_view = "" ) const;
2692
2706 void copyto_mat_complex( mat_complex_type & m, string_view = "" ) const;
2707
2709
2710
2711
2712
2713
2714
2719
2720
2735 real_type get_number_at( unsigned i, string_view = "" ) const;
2736
2751 complex_type get_complex_number_at( unsigned i, string_view = "" ) const;
2752
2769 void get_complex_number_at( unsigned i, real_type & re, real_type & im, string_view = "" ) const;
2770
2783 template <typename T>
2784 T& get_pointer_at( unsigned i )
2785 { return (*this)[i].get_pointer<T>(); }
2786
2799 template <typename T>
2800 T get_pointer_at( unsigned i ) const
2801 { return (*this)[i].get_pointer<T>(); }
2803
2816 bool_type get_bool_at( unsigned i );
2817
2818 template <typename T>
2819 bool_type
2821 static_assert(std::is_integral_v<T>, "get_bool_at() accepts only integral types!");
2822 return get_bool_at(static_cast<unsigned>(i));
2823 }
2824
2838 bool_type get_bool_at( unsigned i, string_view const where ) const;
2839
2852 int_type & get_int_at( unsigned i );
2853
2854 template <typename T>
2855 int_type &
2856 get_int_at( T i ) {
2857 static_assert(std::is_integral_v<T>, "get_int_at() accepts only integral types!");
2858 return get_int_at(static_cast<unsigned>(i));
2859 }
2860
2874 int_type const & get_int_at( unsigned i, string_view const where ) const;
2875
2888 long_type & get_long_at( unsigned i );
2889
2890 template <typename T>
2891 long_type &
2893 static_assert(std::is_integral_v<T>, "get_long_at() accepts only integral types!");
2894 return get_long_at(static_cast<unsigned>(i));
2895 }
2896
2910 long_type const & get_long_at( unsigned i, string_view const where ) const;
2911
2924 real_type & get_real_at( unsigned i );
2925
2926 template <typename T>
2928 static_assert(std::is_integral_v<T>, "get_real_at() accepts only integral types!");
2929 return get_real_at(static_cast<unsigned>(i));
2930 }
2931
2945 real_type const & get_real_at( unsigned i, string_view const where ) const;
2946
2959 complex_type & get_complex_at( unsigned i );
2960
2961 template <typename T>
2963 static_assert(std::is_integral_v<T>, "get_complex_at() accepts only integral types!");
2964 return get_complex_at(static_cast<unsigned>(i));
2965 }
2966
2980 complex_type const & get_complex_at( unsigned i, string_view const where ) const;
2981
2995 int_type & get_int_at( unsigned i, unsigned j );
2996
3011 int_type const & get_int_at( unsigned i, unsigned j, string_view const where ) const;
3012
3026 long_type & get_long_at( unsigned i, unsigned j );
3027
3042 long_type const & get_long_at( unsigned i, unsigned j, string_view const where ) const;
3043
3057 real_type & get_real_at( unsigned i, unsigned j );
3058
3073 real_type const & get_real_at( unsigned i, unsigned j, string_view const where ) const;
3074
3088 complex_type & get_complex_at( unsigned i, unsigned j );
3089
3104 complex_type const & get_complex_at( unsigned i, unsigned j, string_view const where ) const;
3105
3118 string_type & get_string_at( unsigned i );
3119
3120 template <typename T>
3121 string_type &
3123 static_assert(std::is_integral_v<T>, "get_string_at() accepts only integral types!");
3124 return get_string_at(static_cast<unsigned>(i));
3125 }
3126
3140 string_type const & get_string_at( unsigned i, string_view const where ) const;
3141
3154 GenericContainer & get_gc_at( unsigned i );
3155
3156 template <typename T>
3158 static_assert(std::is_integral_v<T>, "get_gc_at() accepts only integral types!");
3159 return get_gc_at(static_cast<unsigned>(i));
3160 }
3161
3175 GenericContainer const & get_gc_at( unsigned i, string_view const where ) const;
3176
3178
3179
3180
3181
3182
3183
3184
3185
3190
3209 map_type & get_map( string_view = "" );
3210
3229 map_type const & get_map( string_view = "" ) const;
3230
3232
3233
3234
3239
3252 GenericContainer & operator [] ( unsigned i );
3253
3266 GenericContainer const & operator [] ( unsigned i ) const;
3267
3280 GenericContainer & operator [] ( string_view s );
3281
3294 GenericContainer const & operator [] ( string_view s ) const;
3295
3313 GenericContainer & operator () ( unsigned i, string_view = "" );
3314
3332 GenericContainer const & operator () ( unsigned i, string_view = "" ) const;
3333
3347 GenericContainer & operator () ( string_view s, string_view = "" );
3348
3362 GenericContainer const & operator () ( string_view s, string_view = "" ) const;
3363
3378 GenericContainer & operator () ( vec_string_type const & vs, string_view = "" );
3379
3394 GenericContainer const & operator () ( vec_string_type const & vs, string_view = "" ) const;
3395
3397
3398
3399
3400
3401
3402
3403
3404
3405
3410
3422 void set( bool const & a ) { this->set_bool(a); }
3423
3435 void set( uint_type const & a ) { this->set_int(int_type(a)); }
3436
3448 void set( int_type const & a ) { this->set_int(a); }
3449
3461 void set( ulong_type const & a ) { this->set_long(long_type(a)); }
3462
3474 void set( long_type const & a ) { this->set_long(a); }
3475
3487 void set( float const & a ) { this->set_real(real_type(a)); }
3488
3500 void set( double const & a ) { this->set_real(real_type(a)); }
3501
3514 void set( complex<float> const & a )
3515 { this->set_complex(real_type(a.real()),real_type(a.imag())); }
3516
3529 void set( complex<double> const & a )
3530 { this->set_complex(real_type(a.real()),real_type(a.imag())); }
3531
3543 void set( char const * a ) { this->set_string(a); }
3544
3556 void set( string_view a ) { this->set_string(a); }
3557
3570 void set( pointer_type a ) { this->set_pointer(a); }
3571
3573
3574
3575
3576
3577
3586
3592 GenericContainer & operator = ( bool const & a )
3593 { this->set_bool(a); return * this; }
3594
3600 GenericContainer & operator = ( uint_type const & a )
3601 { this->set_int(int_type(a)); return * this; }
3602
3608 GenericContainer & operator = ( int_type const & a )
3609 { this->set_int(a); return * this; }
3610
3616 GenericContainer & operator = ( ulong_type const & a )
3617 { this->set_long(long_type(a)); return * this; }
3618
3624 GenericContainer & operator = ( long_type const & a )
3625 { this->set_long(a); return * this; }
3626
3632 GenericContainer & operator = ( float const & a )
3633 { this->set_real(real_type(a)); return * this; }
3634
3640 GenericContainer & operator = ( double const & a )
3641 { this->set_real(real_type(a)); return * this; }
3642
3648 GenericContainer & operator = ( complex<float> const & a )
3649 { this->set_complex(real_type(a.real()),real_type(a.imag())); return * this; }
3650
3656 GenericContainer & operator = ( complex<double> const & a )
3657 { this->set_complex(real_type(a.real()),real_type(a.imag())); return * this; }
3658
3664 GenericContainer & operator = ( vec_bool_type const & a );
3665
3671 GenericContainer & operator = ( vec_int_type const & a );
3672
3678 GenericContainer & operator = ( vec_long_type const & a );
3679
3685 GenericContainer & operator = ( vec_real_type const & a );
3686
3692 GenericContainer & operator = ( vec_complex_type const & a );
3693
3699 GenericContainer & operator = ( vec_string_type const & a );
3700
3706 GenericContainer & operator = ( mat_int_type const & a );
3707
3713 GenericContainer & operator = ( mat_long_type const & a );
3714
3720 GenericContainer & operator = ( mat_real_type const & a );
3721
3727 GenericContainer & operator = ( mat_complex_type const & a );
3728
3734 GenericContainer & operator = ( const char * a )
3735 { this->set_string(a); return * this; }
3736
3742 GenericContainer & operator = ( string const & a )
3743 { this->set_string(a); return * this; }
3744
3750 GenericContainer & operator = ( string_view a )
3751 { this->set_string(a); return * this; }
3752
3759 { this->set_pointer(a); return * this; }
3760
3766 GenericContainer const & operator = ( GenericContainer const & a )
3767 { this->clear(); this->from_gc( a ); return * this; }
3768
3774 void load( GenericContainer const & a ) { this->from_gc(a); }
3776
3784 GenericContainer const & promote_to_int();
3785
3789 GenericContainer const & promote_to_long();
3790
3794 GenericContainer const & promote_to_real();
3795
3800 GenericContainer const & promote_to_complex();
3801
3805 GenericContainer const & promote_to_vec_int();
3806
3810 GenericContainer const & promote_to_vec_long();
3811
3816 GenericContainer const & promote_to_vec_real();
3817
3822 GenericContainer const & promote_to_vec_complex();
3823
3828 GenericContainer const & promote_to_mat_int();
3829
3834 GenericContainer const & promote_to_mat_long();
3835
3840 GenericContainer const & promote_to_mat_real();
3841
3846 GenericContainer const & promote_to_mat_complex();
3847
3852 GenericContainer const & promote_to_vector();
3853
3855
3860
3865 GenericContainer( bool const & a )
3866 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3867
3873 : m_data_type(GC_type::NOTYPE) { *this = a; }
3874
3880 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3881
3887 : m_data_type(GC_type::NOTYPE) { *this = a; }
3888
3894 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3895
3900 GenericContainer( float const & a )
3901 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3902
3907 GenericContainer( double const & a )
3908 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3909
3914 GenericContainer( complex<float> const & a )
3915 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3916
3921 GenericContainer( complex<double> const & a )
3922 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3923
3928 GenericContainer( char const * a )
3929 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3930
3935 GenericContainer( string const & a )
3936 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3937
3942 GenericContainer( string_view a )
3943 : m_data_type(GC_type::NOTYPE) { this->operator=(a); }
3944
3950 : m_data_type(GC_type::NOTYPE) { this->set_pointer(a); }
3951
3957 : m_data_type(GC_type::NOTYPE) { this->from_gc(gc); }
3958
3960
3965
3970 bool exists( string_view s ) const;
3971
3977 bool exists( vec_string_type const & vs ) const;
3978
3985 string must_exists( vec_string_type const & vs, string_view const where ) const;
3986
3992 bool get_if_exists( string_view field, bool & value ) const;
3993
4000 bool get_if_exists( vec_string_type const & fields, bool & value ) const;
4001
4007 bool get_if_exists( string_view field, int_type & value ) const;
4008
4014 bool get_if_exists( string_view field, uint_type & value ) const;
4015
4021 bool get_if_exists( string_view field, long_type & value ) const;
4022
4028 bool get_if_exists( string_view field, ulong_type & value ) const;
4029
4035 bool get_if_exists( string_view field, real_type & value ) const;
4036
4042 bool get_if_exists( string_view field, complex_type & value ) const;
4043
4049 bool get_if_exists( string_view field, string_type & value ) const;
4050
4057 template <typename T>
4058 bool
4059 get_if_exists( vec_string_type const & fields, T & value ) const {
4060 for ( string_view field : fields ) {
4061 if ( get_if_exists( field, value ) ) return true;
4062 }
4063 return false;
4064 }
4065
4071 template <typename T>
4072 bool
4073 get_if_exists( char const field[], T & value ) const {
4074 string_type field_str(field);
4075 return get_if_exists( field_str, value );
4076 }
4077
4079
4084
4092 void
4093 print_content_types(
4094 ostream_type & stream,
4095 string_view prefix = "",
4096 string_view indent = " "
4097 ) const;
4098
4106 string
4107 compare_content( GenericContainer const & gc, string_view from = "" ) const;
4108
4116 void
4117 dump(
4118 ostream_type & stream,
4119 string_view prefix = "",
4120 string_view indent = " "
4121 ) const;
4122
4130 void
4132 ostream_type & stream,
4133 string_view prefix = "",
4134 string_view indent = " "
4135 ) const {
4136 this->dump( stream, prefix, indent );
4137 }
4138
4145 string_type
4147 string_view prefix = "",
4148 string_view indent = " "
4149 ) const {
4150 ostringstream ostr;
4151 ostr.precision(stream_number_precision);
4152 this->print(ostr,prefix,indent);
4153 return ostr.str();
4154 }
4155
4161 void to_gc( GenericContainer & gc ) const;
4162
4168 void from_gc( GenericContainer const & gc );
4169
4176 void merge( GenericContainer const & gc, string_view const where );
4177
4184 bool from_file( string_view file_name );
4185
4192 void to_yaml( ostream_type & stream, string_view prefix = "" ) const;
4193
4194 string
4195 to_yaml( string_view prefix = "" ) const
4196 { ostringstream ss; this->to_yaml( ss, prefix ); return ss.str(); }
4197
4204 bool from_yaml( istream_type & stream );
4205
4206 bool from_yaml( string const & data ) { istringstream ss(data); return this->from_yaml( ss ); }
4207
4214 void to_json( ostream_type & stream, string_view prefix = "" ) const;
4215
4216 string
4217 to_json( string_view prefix = "" ) const
4218 { ostringstream ss; this->to_json( ss, prefix ); return ss.str();}
4219
4226 bool from_json( istream_type & stream );
4227 bool from_json2( istream_type & stream );
4228
4229 bool from_json( string const & data ) { istringstream ss(data); return this->from_json( ss ); }
4230
4237 bool to_toml( ostream_type & stream ) const;
4238
4239 string
4240 to_toml() const
4241 { ostringstream ss; this->to_toml( ss ); return ss.str();}
4242
4249 bool from_toml( istream_type & stream );
4250
4251 bool from_toml( string const & data ) { istringstream ss(data); return this->from_toml( ss ); }
4252
4257 void collapse();
4258
4280 GenericContainer const &
4281 write_formatted_data( ostream_type & stream, char const delimiter = '\t' ) const;
4282
4286 GenericContainer const &
4287 writeFormattedData( ostream_type & stream, char const delimiter = '\t' ) const {
4288 return this->write_formatted_data( stream, delimiter );
4289 }
4290
4310 istream_type & stream,
4311 char const commentChars[] = "#%",
4312 char const delimiters[] = " \t"
4313 );
4314
4320 istream_type & stream,
4321 char const commentChars[] = "#%",
4322 char const delimiters[] = " \t"
4323 ) {
4324 return read_formatted_data( stream, commentChars, delimiters );
4325 }
4326
4345 char const fname[],
4346 char const commentChars[] = "#%",
4347 char const delimiters[] = " \t"
4348 );
4349
4355 char const fname[],
4356 char const commentChars[] = "#%",
4357 char const delimiters[] = " \t"
4358 ) {
4359 return read_formatted_data( fname, commentChars, delimiters );
4360 }
4361
4382 istream_type & stream,
4383 char const commentChars[] = "#%",
4384 char const delimiters[] = " \t",
4385 GenericContainer ptr_pars[] = nullptr
4386 );
4387
4393 istream_type & stream,
4394 char const commentChars[] = "#%",
4395 char const delimiters[] = " \t",
4396 GenericContainer ptr_pars[] = nullptr
4397 ) {
4398 return read_formatted_data2( stream, commentChars, delimiters, ptr_pars );
4399 }
4400
4420 char const fname[],
4421 char const commentChars[] = "#%",
4422 char const delimiters[] = " \t",
4423 GenericContainer ptr_pars[] = nullptr
4424 );
4425
4431 char const fname[],
4432 char const commentChars[] = "#%",
4433 char const delimiters[] = " \t",
4434 GenericContainer ptr_pars[] = nullptr
4435 ) {
4436 return read_formatted_data2( fname, commentChars, delimiters, ptr_pars );
4437 }
4438
4439
4444
4449 int32_t mem_size() const;
4450
4459 int32_t serialize( int32_t buffer_dim, uint8_t * buffer ) const;
4460
4468 int32_t serialize( vector<uint8_t> & buffer ) const;
4469
4478 int32_t de_serialize( int32_t buffer_dim, uint8_t const * buffer );
4479
4487 int32_t de_serialize( vector<uint8_t> const & buffer );
4488
4490
4496 static
4497 void
4498 exception( string_view const where ) GC_NO_RETURN;
4499
4500 };
4501
4502 // -------------------------------------------------------
4503 // support functions
4512 void
4514 vec_string_type const & headers,
4515 vector_type const & data,
4516 ostream_type & stream,
4517 char delimiter = '\t'
4518 );
4519
4523 inline
4524 void
4526 vec_string_type const & headers,
4527 vector_type const & data,
4528 ostream_type & stream,
4529 char delimiter = '\t'
4530 ) {
4531 write_table( headers, data, stream, delimiter );
4532 }
4533
4542 void
4544 vec_string_type const & headers,
4545 mat_real_type const & data,
4546 ostream_type & stream,
4547 char delimiter = '\t'
4548 );
4549
4553 inline
4554 void
4556 vec_string_type const & headers,
4557 mat_real_type const & data,
4558 ostream_type & stream,
4559 char delimiter = '\t'
4560 ) {
4561 write_table( headers, data, stream, delimiter );
4562 }
4563
4571 void
4573 vec_string_type const & headers,
4574 vector_type const & data,
4575 ostream_type & stream
4576 );
4577
4581 inline
4582 void
4584 vec_string_type const & headers,
4585 vector_type const & data,
4586 ostream_type & stream
4587 ) {
4588 write_table_formatted( headers, data, stream );
4589 }
4590
4598 void
4600 vec_string_type const & headers,
4601 mat_real_type const & data,
4602 ostream_type & stream
4603 );
4604
4608 inline
4609 void
4611 vec_string_type const & headers,
4612 mat_real_type const & data,
4613 ostream_type & stream
4614 ) {
4615 write_table_formatted( headers, data, stream );
4616 }
4617
4621 void string_escape( ostream_type & stream, string const & s );
4622
4623}
4624
4625#ifndef DOXYGEN_SHOULD_SKIP_THIS
4626
4627 // do not define alias GC if use X11
4628 #ifndef XlibSpecificationRelease
4629 namespace GC = GC_namespace;
4630 #endif
4631
4632 // for backward compatibility
4633 namespace GenericContainerNamespace = GC_namespace;
4634
4635#endif
4636
4637#ifdef __clang__
4638#pragma clang diagnostic pop
4639#endif
4640
4641#endif
4642
4643//
4644// eof: GenericContainer.hh
4645//
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)
Definition GenericContainer.hh:4251
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
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:3921
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:4059
GenericContainer(double const &a)
Definition GenericContainer.hh:3907
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:2800
bool_type get_bool_at(unsigned i)
Definition GenericContainer.cc:2925
bool_type get_bool_at(T i)
Definition GenericContainer.hh:2820
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)
Definition GenericContainer.cc:3780
void set(uint_type const &a)
Definition GenericContainer.hh:3435
GC_namespace::bool_type bool_type
Alias for boolean type.
Definition GenericContainer.hh:618
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:4392
GC_namespace::complex_type complex_type
Alias for complex number type.
Definition GenericContainer.hh:624
bool from_json(istream_type &stream)
GenericContainer(bool const &a)
Definition GenericContainer.hh:3865
int32_t de_serialize(vector< uint8_t > const &buffer)
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
GenericContainer(complex< float > const &a)
Definition GenericContainer.hh:3914
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:4217
GenericContainer(pointer_type a)
Definition GenericContainer.hh:3949
void set(double const &a)
Definition GenericContainer.hh:3500
vec_string_type & set_vec_string(T sz)
Definition GenericContainer.hh:1289
GenericContainer & readFormattedData(char const fname[], char const commentChars[]="#%", char const delimiters[]=" \t")
Definition GenericContainer.hh:4354
vec_long_type & set_vec_long(T sz)
Definition GenericContainer.hh:1172
void set(bool const &a)
Definition GenericContainer.hh:3422
void set(complex< double > const &a)
Definition GenericContainer.hh:3529
bool from_json(string const &data)
Definition GenericContainer.hh:4229
void get_value(T &v, string_view const where="") const
Get the stored value.
GenericContainer(long_type const &a)
Definition GenericContainer.hh:3893
int32_t serialize(vector< uint8_t > &buffer) const
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:3900
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:4430
void set(string_view a)
Definition GenericContainer.hh:3556
GenericContainer & get_gc_at(T i)
Definition GenericContainer.hh:3157
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:1250
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
GenericContainer(GenericContainer const &gc)
Definition GenericContainer.hh:3956
string_type info() const
Print information about the kind of data stored as a string.
Definition GenericContainer.hh:1613
complex_type & get_complex_at(unsigned i)
Definition GenericContainer.cc:3099
string to_toml() const
Definition GenericContainer.hh:4240
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:3461
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
T & get_pointer_at(unsigned i)
Definition GenericContainer.hh:2784
~GenericContainer()
Destroys the GenericContainer and releases any allocated resources.
Definition GenericContainer.hh:779
void to_json(ostream_type &stream, string_view prefix="") const
complex_type & get_complex_at(T i)
Definition GenericContainer.hh:2962
GenericContainer(int_type const &a)
Definition GenericContainer.hh:3879
GenericContainer(uint_type const &a)
Definition GenericContainer.hh:3872
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:1789
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:3935
void dump(ostream_type &stream, string_view prefix="", string_view indent=" ") const
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:1591
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:3122
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:4319
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:3886
string to_yaml(string_view prefix="") const
Definition GenericContainer.hh:4195
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:3592
void print(ostream_type &stream, string_view prefix="", string_view indent=" ") const
Definition GenericContainer.hh:4131
void set(int_type const &a)
Definition GenericContainer.hh:3448
TypeAllowed get_type() const
Return an integer representing the type of data stored.
Definition GenericContainer.hh:1580
T & get_pointer()
Get the stored value as a pointer.
Definition GenericContainer.hh:1780
vec_real_type & set_vec_real(T sz)
Definition GenericContainer.hh:1211
void set(pointer_type a)
Definition GenericContainer.hh:3570
real_type & get_real_at(T i)
Definition GenericContainer.hh:2927
GenericContainer(char const *a)
Definition GenericContainer.hh:3928
void set(long_type const &a)
Definition GenericContainer.hh:3474
GenericContainer(string_view a)
Definition GenericContainer.hh:3942
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:3514
GC_namespace::vec_string_type vec_string_type
Alias for vector of strings type.
Definition GenericContainer.hh:634
bool from_yaml(istream_type &stream)
bool get_if_exists(char const field[], T &value) const
Definition GenericContainer.hh:4073
int32_t de_serialize(int32_t buffer_dim, uint8_t const *buffer)
Definition GenericContainerSerialize.cc:380
int_type & get_int_at(T i)
Definition GenericContainer.hh:2856
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:4287
bool from_yaml(string const &data)
Definition GenericContainer.hh:4206
vec_pointer_type & set_vec_pointer(T sz)
Definition GenericContainer.hh:1055
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)
string_type print(string_view prefix="", string_view indent=" ") const
Definition GenericContainer.hh:4146
unsigned get_numRows() const
Definition GenericContainer.hh:1639
void set(float const &a)
Definition GenericContainer.hh:3487
vec_int_type & set_vec_int(T sz)
Definition GenericContainer.hh:1133
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:3774
long_type & get_long_at(T i)
Definition GenericContainer.hh:2892
vec_bool_type & set_vec_bool(T sz)
Definition GenericContainer.hh:1094
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:1650
void set(char const *a)
Definition GenericContainer.hh:3543
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:4525
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:4583
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