From 57a75e380fd5e7bfec867d18f34d6e512c737c1c Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 19 Jun 2024 10:51:48 -0400 Subject: [PATCH] xo-reflect: + reflect builtin c++ types (int ..) automatically --- include/xo/reflect/TypeDescr.hpp | 15 +++++++++++++++ src/reflect/TypeDescr.cpp | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/xo/reflect/TypeDescr.hpp b/include/xo/reflect/TypeDescr.hpp index c85b2379..31c58063 100644 --- a/include/xo/reflect/TypeDescr.hpp +++ b/include/xo/reflect/TypeDescr.hpp @@ -200,6 +200,8 @@ namespace xo { /** print table of reflected types to 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_; } const std::type_info * native_typeinfo() const { return native_typeinfo_; } @@ -470,6 +472,19 @@ namespace xo { 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 xo*/ diff --git a/src/reflect/TypeDescr.cpp b/src/reflect/TypeDescr.cpp index 34cfa8e1..41f5204e 100644 --- a/src/reflect/TypeDescr.cpp +++ b/src/reflect/TypeDescr.cpp @@ -3,6 +3,7 @@ #include "TypeDescr.hpp" #include "TaggedPtr.hpp" #include "TypeDescrExtra.hpp" +#include "Reflect.hpp" #include "atomic/AtomicTdx.hpp" #include "function/FunctionTdx.hpp" #include "xo/indentlog/scope.hpp" @@ -301,6 +302,20 @@ namespace xo { this->complete_flag_ = true; this->tdextra_ = std::move(tdx); } /*assign_tdextra*/ + + TypeDescrTable::TypeDescrTable() { + Reflect::require(); + Reflect::require(); + Reflect::require(); + Reflect::require(); + Reflect::require(); + Reflect::require(); + Reflect::require(); + Reflect::require(); + } /*ctor*/ + + TypeDescrTable + TypeDescrTable::s_instance; } /*namespace reflect*/ } /*namespace xo*/