From 6fc1fff9dc6ef6432c02e6474a2c3b24b05a6c32 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 18 Jun 2024 17:15:08 -0400 Subject: [PATCH] xo-reflect: + TypeDescr::lookup_by_name() --- include/xo/reflect/TypeDescr.hpp | 2 ++ src/reflect/TypeDescr.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/xo/reflect/TypeDescr.hpp b/include/xo/reflect/TypeDescr.hpp index a0c307b..cd59697 100644 --- a/include/xo/reflect/TypeDescr.hpp +++ b/include/xo/reflect/TypeDescr.hpp @@ -190,6 +190,8 @@ namespace xo { std::unique_ptr tdextra); /* print table of reflected types to os */ + /** lookup type by canonical name **/ + static TypeDescr lookup_by_name(const std::string & canonical_name); static void print_reflected_types(std::ostream & os); TypeId id() const { return id_; } diff --git a/src/reflect/TypeDescr.cpp b/src/reflect/TypeDescr.cpp index c541ea0..7c2eb19 100644 --- a/src/reflect/TypeDescr.cpp +++ b/src/reflect/TypeDescr.cpp @@ -146,6 +146,19 @@ namespace xo { return new_slot.get(); } /*require*/ + TypeDescr + TypeDescrBase::lookup_by_name(const std::string & name) { + auto ix = s_canonical_type_table_map.find(name); + + if (ix == s_canonical_type_table_map.end()) { + throw std::runtime_error(tostr("TypeDescrBase::lookup_by_name" + ": no registered type with canonical name T", + xtag("T", name))); + } + + return ix->second; + } /*lookup_by_name*/ + void TypeDescrBase::print_reflected_types(std::ostream & os) {