xo-reflect: + TypeDescr::lookup_by_name()

This commit is contained in:
Roland Conybeare 2024-06-18 17:15:08 -04:00
commit 6fc1fff9dc
2 changed files with 15 additions and 0 deletions

View file

@ -190,6 +190,8 @@ namespace xo {
std::unique_ptr<TypeDescrExtra> 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_; }

View file

@ -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)
{