xo-reflect: + reflect builtin c++ types (int ..) automatically

This commit is contained in:
Roland Conybeare 2024-06-19 10:51:48 -04:00
commit 57a75e380f
2 changed files with 30 additions and 0 deletions

View file

@ -200,6 +200,8 @@ namespace xo {
/** print table of reflected types to os **/ /** print table of reflected types to os **/
static void print_reflected_types(std::ostream & os); static void print_reflected_types(std::ostream & os);
/** print table of function types to os **/
static void print_function_types(std::ostream & os);
TypeId id() const { return id_; } TypeId id() const { return id_; }
const std::type_info * native_typeinfo() const { return native_typeinfo_; } const std::type_info * native_typeinfo() const { return native_typeinfo_; }
@ -470,6 +472,19 @@ namespace xo {
return os; return os;
} }
class TypeDescrTable {
public:
TypeDescrTable * instance() { return &s_instance; }
private:
/** initialize with builtin atomic types:
* float, double, char, short, int, long, bool
**/
TypeDescrTable();
private:
static TypeDescrTable s_instance;
};
} /*namespace reflect*/ } /*namespace reflect*/
} /*namespace xo*/ } /*namespace xo*/

View file

@ -3,6 +3,7 @@
#include "TypeDescr.hpp" #include "TypeDescr.hpp"
#include "TaggedPtr.hpp" #include "TaggedPtr.hpp"
#include "TypeDescrExtra.hpp" #include "TypeDescrExtra.hpp"
#include "Reflect.hpp"
#include "atomic/AtomicTdx.hpp" #include "atomic/AtomicTdx.hpp"
#include "function/FunctionTdx.hpp" #include "function/FunctionTdx.hpp"
#include "xo/indentlog/scope.hpp" #include "xo/indentlog/scope.hpp"
@ -301,6 +302,20 @@ namespace xo {
this->complete_flag_ = true; this->complete_flag_ = true;
this->tdextra_ = std::move(tdx); this->tdextra_ = std::move(tdx);
} /*assign_tdextra*/ } /*assign_tdextra*/
TypeDescrTable::TypeDescrTable() {
Reflect::require<bool>();
Reflect::require<char>();
Reflect::require<short>();
Reflect::require<int>();
Reflect::require<long>();
Reflect::require<long long>();
Reflect::require<float>();
Reflect::require<double>();
} /*ctor*/
TypeDescrTable
TypeDescrTable::s_instance;
} /*namespace reflect*/ } /*namespace reflect*/
} /*namespace xo*/ } /*namespace xo*/