From 9718be824b6270f445ec79f62c6dfc89ba1dde9c Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 6 Oct 2023 17:05:28 -0400 Subject: [PATCH] cosmetic: indentation --- include/xo/reflect/Reflect.hpp | 352 +++++++++++++++---------------- include/xo/reflect/TypeDescr.hpp | 119 ++++++----- 2 files changed, 235 insertions(+), 236 deletions(-) diff --git a/include/xo/reflect/Reflect.hpp b/include/xo/reflect/Reflect.hpp index a6e6fe5e..478078ad 100644 --- a/include/xo/reflect/Reflect.hpp +++ b/include/xo/reflect/Reflect.hpp @@ -17,219 +17,219 @@ #include // for std::pair<> namespace xo { - namespace reflect { - template - class EstablishTdx { - public: - static std::unique_ptr make() { return AtomicTdx::make(); } - }; /*EstablishTdx*/ + namespace reflect { + template + class EstablishTdx { + public: + static std::unique_ptr make() { return AtomicTdx::make(); } + }; /*EstablishTdx*/ - // ----- xo::ref::rp ----- + // ----- xo::ref::rp ----- - /* definition provide after decl for Reflect {} below */ - template - class EstablishTdx> { - public: - static std::unique_ptr make(); - }; /*EstablishTdx*/ + /* definition provide after decl for Reflect {} below */ + template + class EstablishTdx> { + public: + static std::unique_ptr make(); + }; /*EstablishTdx*/ - // ----- std::array ----- + // ----- std::array ----- - /* definition provide after decl for Reflect {} below */ - template - class EstablishTdx> { - public: - static std::unique_ptr make(); - }; /*EstablishTdx*/ + /* definition provide after decl for Reflect {} below */ + template + class EstablishTdx> { + public: + static std::unique_ptr make(); + }; /*EstablishTdx*/ - // ----- std::vector ----- + // ----- std::vector ----- - /* definition provide after decl for Reflect {} below */ - template - class EstablishTdx> { - public: - static std::unique_ptr make(); - }; /*EstablishTdx*/ + /* definition provide after decl for Reflect {} below */ + template + class EstablishTdx> { + public: + static std::unique_ptr make(); + }; /*EstablishTdx*/ - // ----- std::pair ----- + // ----- std::pair ----- - /* definition provide after decl for Reflect {} below */ - template - class EstablishTdx> { - public: - static std::unique_ptr make(); - }; /*EstablishTdx*/ + /* definition provide after decl for Reflect {} below */ + template + class EstablishTdx> { + public: + static std::unique_ptr make(); + }; /*EstablishTdx*/ - // ----- MakeTagged ----- + // ----- MakeTagged ----- - template - class TaggedPtrMaker { - public: - static TaggedPtr make_tp(T * x); - static TaggedRcptr make_rctp(T * x); - }; + template + class TaggedPtrMaker { + public: + static TaggedPtr make_tp(T * x); + static TaggedRcptr make_rctp(T * x); + }; - template<> - class TaggedPtrMaker { - public: - static TaggedPtr make_tp(SelfTagging * x) { - return x->self_tp(); - } /*make_tp*/ + template<> + class TaggedPtrMaker { + public: + static TaggedPtr make_tp(SelfTagging * x) { + return x->self_tp(); + } /*make_tp*/ - static TaggedRcptr make_rctp(SelfTagging * x) { - return x->self_tp(); - } /*make_rctp*/ - }; /*TaggedPtrMaker*/ + static TaggedRcptr make_rctp(SelfTagging * x) { + return x->self_tp(); + } /*make_rctp*/ + }; /*TaggedPtrMaker*/ - // ----- Reflect ----- + // ----- Reflect ----- - class Reflect { - public: - /* Use: - * using mytype = ...; - * if (Reflect::is_reflected()) { ... } - */ - template - static bool is_reflected() { return TypeDescrBase::is_reflected(&typeid(T)); } + class Reflect { + public: + /* Use: + * using mytype = ...; + * if (Reflect::is_reflected()) { ... } + */ + template + static bool is_reflected() { return TypeDescrBase::is_reflected(&typeid(T)); } - /* Use: - * using mytype = ...; - * TypeDescrW td = Reflect::require(); - * - * Note: - * To avoid cyclic header dependencies - * (between EstablishTypeDescr.hpp <-> {vector/VectorTdx.hpp etc.}, - * we use a 2-stage setup process: - * - * 1. EstablishTypeDescr::establish() creates a TypeDescr* object - * with lowest-common-denominator .tdextra AtomicTdx. - * (see [reflect/EstablishTypeDescr.hpp]) - * - * 2. Reflect::require() upgrades .tdextra to suitable implementation - * depending on T; this means also need to visit reflection info - * (TypeDescr objects) for nested types to upgrade them too. - * - * This allows template-fu for a compound type (like std::vector), - * implemented in specialized header (like [reflect/struct/VectorTdx.hpp]) to - * refer to reflection info for T without having to pull in all the - * headers needed to properly reflect T (like this [reflect/Reflect.hpp]) - * - */ - template - static TypeDescrW require() { - TypeDescrW retval_td = EstablishTypeDescr::establish(); + /* Use: + * using mytype = ...; + * TypeDescrW td = Reflect::require(); + * + * Note: + * To avoid cyclic header dependencies + * (between EstablishTypeDescr.hpp <-> {vector/VectorTdx.hpp etc.}, + * we use a 2-stage setup process: + * + * 1. EstablishTypeDescr::establish() creates a TypeDescr* object + * with lowest-common-denominator .tdextra AtomicTdx. + * (see [reflect/EstablishTypeDescr.hpp]) + * + * 2. Reflect::require() upgrades .tdextra to suitable implementation + * depending on T; this means also need to visit reflection info + * (TypeDescr objects) for nested types to upgrade them too. + * + * This allows template-fu for a compound type (like std::vector), + * implemented in specialized header (like [reflect/struct/VectorTdx.hpp]) to + * refer to reflection info for T without having to pull in all the + * headers needed to properly reflect T (like this [reflect/Reflect.hpp]) + * + */ + template + static TypeDescrW require() { + TypeDescrW retval_td = EstablishTypeDescr::establish(); - /* mark TypeDescr for T as complete (even though it isn't quite yet), - * so that when we encounter recursive types, reflection terminates. - * For example consider type resulting from code like - * - * typename T; - * using T = std::vector; - * - */ - if (retval_td->mark_complete()) { - /* control here on 2nd+later calls to require(). - * in principle can immediately short-circuit. - */ - } else { - /* control comes here the first time require() runs */ + /* mark TypeDescr for T as complete (even though it isn't quite yet), + * so that when we encounter recursive types, reflection terminates. + * For example consider type resulting from code like + * + * typename T; + * using T = std::vector; + * + */ + if (retval_td->mark_complete()) { + /* control here on 2nd+later calls to require(). + * in principle can immediately short-circuit. + */ + } else { + /* control comes here the first time require() runs */ - auto final_tdx = EstablishTdx::make(); + auto final_tdx = EstablishTdx::make(); - retval_td->assign_tdextra(std::move(final_tdx)); + retval_td->assign_tdextra(std::move(final_tdx)); - /* also need to require for each child */ - } + /* also need to require for each child */ + } - return retval_td; - } /*require*/ + return retval_td; + } /*require*/ - /* Use: - * T * xyz = ...; - * TaggedPtr xyz_tp = Reflect::make_tp(xyz); - */ - template - static TaggedPtr make_tp(T * x) { return TaggedPtrMaker::make_tp(x); } + /* Use: + * T * xyz = ...; + * TaggedPtr xyz_tp = Reflect::make_tp(xyz); + */ + template + static TaggedPtr make_tp(T * x) { return TaggedPtrMaker::make_tp(x); } - template - static TaggedRcptr make_rctp(T * x) { return TaggedPtrMaker::make_rctp(x); } - }; /*Reflect*/ + template + static TaggedRcptr make_rctp(T * x) { return TaggedPtrMaker::make_rctp(x); } + }; /*Reflect*/ - // ----- MakeTagged ----- + // ----- MakeTagged ----- - template - TaggedPtr - TaggedPtrMaker::make_tp(T * x) { - return TaggedPtr(Reflect::require(), x); - } /*make_tp*/ + template + TaggedPtr + TaggedPtrMaker::make_tp(T * x) { + return TaggedPtr(Reflect::require(), x); + } /*make_tp*/ - template - TaggedRcptr - TaggedPtrMaker::make_rctp(T * x) { - return TaggedRcptr(Reflect::require(), x); - } /*make_rctp*/ + template + TaggedRcptr + TaggedPtrMaker::make_rctp(T * x) { + return TaggedRcptr(Reflect::require(), x); + } /*make_rctp*/ - // ----- xo::ref::rp ----- + // ----- xo::ref::rp ----- - /* declared above before - * class Reflect { .. } - */ - template - std::unique_ptr - EstablishTdx>::make() { - /* need to ensure Object is property reflected. - * - * In practice must be a class type, since has to store refcount - * + supply assoc'd incr/decr methods - */ - Reflect::require(); + /* declared above before + * class Reflect { .. } + */ + template + std::unique_ptr + EstablishTdx>::make() { + /* need to ensure Object is property reflected. + * + * In practice must be a class type, since has to store refcount + * + supply assoc'd incr/decr methods + */ + Reflect::require(); - return RefPointerTdx>::make(); - } /*make*/ + return RefPointerTdx>::make(); + } /*make*/ - // ----- std::array ----- + // ----- std::array ----- - /* declared above before - * class Reflect { .. } - */ - template - std::unique_ptr - EstablishTdx>::make() { - /* need to ensure Element is properly reflected */ - Reflect::require(); + /* declared above before + * class Reflect { .. } + */ + template + std::unique_ptr + EstablishTdx>::make() { + /* need to ensure Element is properly reflected */ + Reflect::require(); - return StdArrayTdx::make(); - } /*make*/ + return StdArrayTdx::make(); + } /*make*/ - // ----- std::vector ----- + // ----- std::vector ----- - /* declared above before - * class Reflect { .. } - */ - template - std::unique_ptr - EstablishTdx>::make() { - /* need to ensure Element is properly reflected */ - Reflect::require(); + /* declared above before + * class Reflect { .. } + */ + template + std::unique_ptr + EstablishTdx>::make() { + /* need to ensure Element is properly reflected */ + Reflect::require(); - return StdVectorTdx::make(); - } /*make*/ + return StdVectorTdx::make(); + } /*make*/ - // ----- std::pair ----- + // ----- std::pair ----- - /* declared above before - * class Reflect { .. } - */ - template - std::unique_ptr - EstablishTdx>::make() { - /* need to ensure Lhs, Rhs are properly reflected */ - Reflect::require(); - Reflect::require(); + /* declared above before + * class Reflect { .. } + */ + template + std::unique_ptr + EstablishTdx>::make() { + /* need to ensure Lhs, Rhs are properly reflected */ + Reflect::require(); + Reflect::require(); - return StructTdx::pair(); - } /*make*/ - } /*namespace reflect*/ + return StructTdx::pair(); + } /*make*/ + } /*namespace reflect*/ } /*namespace xo*/ /* end Reflect.hpp */ diff --git a/include/xo/reflect/TypeDescr.hpp b/include/xo/reflect/TypeDescr.hpp index da59c007..142a3287 100644 --- a/include/xo/reflect/TypeDescr.hpp +++ b/include/xo/reflect/TypeDescr.hpp @@ -2,7 +2,6 @@ #pragma once -//#include "reflect/atomic/AtomicTdx.hpp" #include "TypeDescrExtra.hpp" #include "cxxutil/demangle.hpp" #include @@ -16,80 +15,80 @@ #include namespace xo { - namespace reflect { - class TaggedPtr; /* see [reflect/TaggedPtr.hpp] */ + namespace reflect { + class TaggedPtr; /* see [reflect/TaggedPtr.hpp] */ - /* A reflected type is a type for which we keep information around at runtime - * Assign reflected types unique (within an executable) ids, - * allocating consecutively, starting from 1. - * Reserve 0 as a sentinel - */ - class TypeId { - public: - /* allocate a new TypeId value. - * promise: - * - retval.id() > 0 - */ - static TypeId allocate() { return TypeId(s_next_id++); } + /* A reflected type is a type for which we keep information around at runtime + * Assign reflected types unique (within an executable) ids, + * allocating consecutively, starting from 1. + * Reserve 0 as a sentinel + */ + class TypeId { + public: + /* allocate a new TypeId value. + * promise: + * - retval.id() > 0 + */ + static TypeId allocate() { return TypeId(s_next_id++); } - std::uint32_t id() const { return id_; } + std::uint32_t id() const { return id_; } - private: - explicit TypeId(std::uint32_t id) : id_{id} {} + private: + explicit TypeId(std::uint32_t id) : id_{id} {} - private: - static std::uint32_t s_next_id; + private: + static std::uint32_t s_next_id; - /* unique index# for this type. - * 0 reserved for sentinel - */ - std::uint32_t id_ = 0; - }; /*TypeId*/ + /* unique index# for this type. + * 0 reserved for sentinel + */ + std::uint32_t id_ = 0; + }; /*TypeId*/ - inline std::ostream & - operator<<(std::ostream & os, TypeId x) { - os << x.id(); - return os; - } /*operator<<*/ + inline std::ostream & + operator<<(std::ostream & os, TypeId x) { + os << x.id(); + return os; + } /*operator<<*/ - /* runtime description of a struct/class instance variable */ - class StructMember; + /* runtime description of a struct/class instance variable */ + class StructMember; - class TypeDescrBase; + class TypeDescrBase; - using TypeDescr = TypeDescrBase const *; - using TypeDescrW = TypeDescrBase *; + using TypeDescr = TypeDescrBase const *; + using TypeDescrW = TypeDescrBase *; - /* convenience wrapper for a std::type_info pointer. - * works properly with pybind11, since python doens't encounter - * native type_info pointer, it won't try to delete it. - */ - class TypeInfoRef { - public: - explicit TypeInfoRef(std::type_info const * tinfo) : tinfo_{tinfo} {} - TypeInfoRef(TypeInfoRef const & x) = default; + /* convenience wrapper for a std::type_info pointer. + * works properly with pybind11, since python doens't encounter + * native type_info pointer, it won't try to delete it. + */ + class TypeInfoRef { + public: + explicit TypeInfoRef(std::type_info const * tinfo) : tinfo_{tinfo} {} + TypeInfoRef(TypeInfoRef const & x) = default; - /* use: - * TypeInfoRef tinfo = TypeInfoRef::make(); - */ - template - TypeInfoRef make() { return TypeInfoRef(&typeid(T)); } + /* use: + * TypeInfoRef tinfo = TypeInfoRef::make(); + */ + template + TypeInfoRef make() { return TypeInfoRef(&typeid(T)); } - std::size_t hash_code() const { return this->tinfo_->hash_code(); } - char const * impl_name() const { return this->tinfo_->name(); } + std::size_t hash_code() const { return this->tinfo_->hash_code(); } + char const * impl_name() const { return this->tinfo_->name(); } - static bool is_equal(TypeInfoRef x, TypeInfoRef y) noexcept { - if (x.hash_code() != y.hash_code()) - return false; + static bool is_equal(TypeInfoRef x, TypeInfoRef y) noexcept { + if (x.hash_code() != y.hash_code()) + return false; - return ::strcmp(x.impl_name(), y.impl_name()) == 0; - } /*is_equal*/ + return ::strcmp(x.impl_name(), y.impl_name()) == 0; + } /*is_equal*/ - private: - /* native type_info object for encapsulated type */ - std::type_info const * tinfo_ = nullptr; - }; /*TypeInfoRef*/ - } /*namespace reflect*/ + private: + /* native type_info object for encapsulated type */ + std::type_info const * tinfo_ = nullptr; + }; /*TypeInfoRef*/ + } /*namespace reflect*/ } /*namespace xo*/ namespace std {