From 58e143f1b1c18b902dc1741f1bbfc99d054bf295 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 26 Jun 2024 00:40:28 -0400 Subject: [PATCH] xo-reflect: + Object (cache TypeId for dispatching) --- include/xo/reflect/Object.hpp | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 include/xo/reflect/Object.hpp diff --git a/include/xo/reflect/Object.hpp b/include/xo/reflect/Object.hpp new file mode 100644 index 00000000..8fb8c156 --- /dev/null +++ b/include/xo/reflect/Object.hpp @@ -0,0 +1,44 @@ +** @file Object.hpp + * + * Author: Roland Conybeare + **/ + +#pragma once + +#include "xo/reflect/SelfTagging.hpp" +//#include + +namespace xo { + namespace reflect { + /** @class Object + * + * @brief A swiss-army-knife base class for runtime polymorphism. + * + * Promote using this: + * - for interpreter integration (see xo-expression / xo-jit) + * - to allow reasonably efficient type dispatching - + * don't need to pay for a function call to find out dispatching type. + **/ + class Object : public reflect::SelfTagging { + public: + using TypeId = xo::reflect::TypeId; + + Object(TypeId type_id) : type_id_{type_id} {} + + private: + /** unique id number for this object's type + * + * Caches the value of this->self_tp().td()->id() + * + * Notes: + * 1. may want to record metatype also + * 2. a few builtin types have well-known type_ids. + * see TypeDescrTable ctor in xo-reflect. + **/ + TypeId type_id_; + }; + } /*namespace obj*/ +} /*namespace xo*/ + + +/** end Object.hpp **/