reflect: insert xo/ subdir into include path

This commit is contained in:
Roland Conybeare 2023-10-06 16:53:47 -04:00
commit 6be9037f10
20 changed files with 179 additions and 184 deletions

View file

@ -5,8 +5,8 @@
#pragma once #pragma once
#include "reflect/TypeDescr.hpp" #include "TypeDescr.hpp"
#include "reflect/TaggedPtr.hpp" #include "TaggedPtr.hpp"
namespace xo { namespace xo {
namespace reflect { namespace reflect {
@ -26,28 +26,28 @@ namespace xo {
template<typename T> template<typename T>
static TypeDescrW establish() { static TypeDescrW establish() {
TypeDescrW td = TypeDescrBase::require(&typeid(T), TypeDescrW td = TypeDescrBase::require(&typeid(T),
type_name<T>(), type_name<T>(),
nullptr); nullptr);
#ifdef NOT_USING #ifdef NOT_USING
std::function<TaggedPtr (void *)> to_self_tp; std::function<TaggedPtr (void *)> to_self_tp;
if (std::is_base_of_v<SelfTagging, T>) { if (std::is_base_of_v<SelfTagging, T>) {
/* T is a descendant of SelfTagging (or T = SelfTagging); /* T is a descendant of SelfTagging (or T = SelfTagging);
* use SelfTagging.self_tp() * use SelfTagging.self_tp()
*/ */
to_self_tp = [](void * x) { return reinterpret_cast<T *>(x)->self_tp(); }; to_self_tp = [](void * x) { return reinterpret_cast<T *>(x)->self_tp(); };
} else { } else {
/* T is not a descendant of SelfTagging. /* T is not a descendant of SelfTagging.
* want to return * want to return
*/ */
to_self_tp = [td](void * x) { return TaggedPtr(td, x); }; to_self_tp = [td](void * x) { return TaggedPtr(td, x); };
} }
td->assign_to_self_tp(to_self_tp); td->assign_to_self_tp(to_self_tp);
#endif #endif
return td; return td;
} }
}; /*EstablishTypeDescr*/ }; /*EstablishTypeDescr*/

View file

@ -5,12 +5,12 @@
#pragma once #pragma once
#include "reflect/SelfTagging.hpp" #include "SelfTagging.hpp"
#include "reflect/EstablishTypeDescr.hpp" #include "EstablishTypeDescr.hpp"
#include "reflect/atomic/AtomicTdx.hpp" #include "atomic/AtomicTdx.hpp"
#include "reflect/pointer/PointerTdx.hpp" #include "pointer/PointerTdx.hpp"
#include "reflect/vector/VectorTdx.hpp" #include "vector/VectorTdx.hpp"
#include "reflect/struct/StructTdx.hpp" #include "struct/StructTdx.hpp"
#include "refcnt/Refcounted.hpp" #include "refcnt/Refcounted.hpp"
#include <vector> #include <vector>
#include <array> #include <array>
@ -22,7 +22,7 @@ namespace xo {
class EstablishTdx { class EstablishTdx {
public: public:
static std::unique_ptr<TypeDescrExtra> make() { return AtomicTdx::make(); } static std::unique_ptr<TypeDescrExtra> make() { return AtomicTdx::make(); }
}; /*EstablishTdx*/ }; /*EstablishTdx*/
// ----- xo::ref::rp<Object> ----- // ----- xo::ref::rp<Object> -----
@ -34,7 +34,7 @@ namespace xo {
}; /*EstablishTdx*/ }; /*EstablishTdx*/
// ----- std::array<Element, N> ----- // ----- std::array<Element, N> -----
/* definition provide after decl for Reflect {} below */ /* definition provide after decl for Reflect {} below */
template<typename Element, std::size_t N> template<typename Element, std::size_t N>
class EstablishTdx<std::array<Element, N>> { class EstablishTdx<std::array<Element, N>> {
@ -73,11 +73,11 @@ namespace xo {
class TaggedPtrMaker<SelfTagging> { class TaggedPtrMaker<SelfTagging> {
public: public:
static TaggedPtr make_tp(SelfTagging * x) { static TaggedPtr make_tp(SelfTagging * x) {
return x->self_tp(); return x->self_tp();
} /*make_tp*/ } /*make_tp*/
static TaggedRcptr make_rctp(SelfTagging * x) { static TaggedRcptr make_rctp(SelfTagging * x) {
return x->self_tp(); return x->self_tp();
} /*make_rctp*/ } /*make_rctp*/
}; /*TaggedPtrMaker*/ }; /*TaggedPtrMaker*/
@ -113,35 +113,35 @@ namespace xo {
* implemented in specialized header (like [reflect/struct/VectorTdx.hpp]) to * implemented in specialized header (like [reflect/struct/VectorTdx.hpp]) to
* refer to reflection info for T without having to pull in all the * refer to reflection info for T without having to pull in all the
* headers needed to properly reflect T (like this [reflect/Reflect.hpp]) * headers needed to properly reflect T (like this [reflect/Reflect.hpp])
* *
*/ */
template<typename T> template<typename T>
static TypeDescrW require() { static TypeDescrW require() {
TypeDescrW retval_td = EstablishTypeDescr::establish<T>(); TypeDescrW retval_td = EstablishTypeDescr::establish<T>();
/* mark TypeDescr for T as complete (even though it isn't quite yet), /* mark TypeDescr for T as complete (even though it isn't quite yet),
* so that when we encounter recursive types, reflection terminates. * so that when we encounter recursive types, reflection terminates.
* For example consider type resulting from code like * For example consider type resulting from code like
* *
* typename T; * typename T;
* using T = std::vector<T *>; * using T = std::vector<T *>;
* *
*/ */
if (retval_td->mark_complete()) { if (retval_td->mark_complete()) {
/* control here on 2nd+later calls to require<T>(). /* control here on 2nd+later calls to require<T>().
* in principle can immediately short-circuit. * in principle can immediately short-circuit.
*/ */
} else { } else {
/* control comes here the first time require<T>() runs */ /* control comes here the first time require<T>() runs */
auto final_tdx = EstablishTdx<T>::make(); auto final_tdx = EstablishTdx<T>::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; return retval_td;
} /*require*/ } /*require*/
/* Use: /* Use:

View file

@ -5,9 +5,9 @@
#pragma once #pragma once
#include "refcnt/Refcounted.hpp" #include "Refcounted.hpp"
#include "reflect/TypeDescr.hpp" #include "TypeDescr.hpp"
#include "reflect/TaggedRcptr.hpp" #include "TaggedRcptr.hpp"
namespace xo { namespace xo {
namespace reflect { namespace reflect {

View file

@ -2,10 +2,10 @@
#pragma once #pragma once
#include "reflect/Reflect.hpp" #include "Reflect.hpp"
#include "reflect/TypeDescr.hpp" #include "TypeDescr.hpp"
#include "reflect/struct/StructMember.hpp" #include "struct/StructMember.hpp"
#include "reflect/struct/StructTdx.hpp" #include "struct/StructTdx.hpp"
#include <vector> #include <vector>
namespace xo { namespace xo {
@ -16,7 +16,7 @@ namespace xo {
template<typename StructT> template<typename StructT>
struct SelfTagger<StructT, true> { struct SelfTagger<StructT, true> {
static TaggedPtr self_tp(void * object) { static TaggedPtr self_tp(void * object) {
return (reinterpret_cast<StructT *>(object))->self_tp(); return (reinterpret_cast<StructT *>(object))->self_tp();
} }
}; };
@ -35,7 +35,7 @@ namespace xo {
* REFLECT_LITERAL_MEMBER(sr, y_); * REFLECT_LITERAL_MEMBER(sr, y_);
* *
* // optional: regardless, reflection will be completed when sr goes out of scope * // optional: regardless, reflection will be completed when sr goes out of scope
* sr.require_complete(); * sr.require_complete();
*/ */
template<typename StructT> template<typename StructT>
class StructReflector { class StructReflector {
@ -45,68 +45,68 @@ namespace xo {
public: public:
StructReflector() : td_{EstablishTypeDescr::establish<StructT>()} {} StructReflector() : td_{EstablishTypeDescr::establish<StructT>()} {}
~StructReflector() { ~StructReflector() {
this->require_complete(); this->require_complete();
} }
bool is_complete() const { return s_reflected_flag; } bool is_complete() const { return s_reflected_flag; }
bool is_incomplete() const { return !s_reflected_flag; } bool is_incomplete() const { return !s_reflected_flag; }
template<typename OwnerT, typename MemberT> template<typename OwnerT, typename MemberT>
void reflect_member(std::string const & member_name, void reflect_member(std::string const & member_name,
MemberT OwnerT::* member_addr) { MemberT OwnerT::* member_addr) {
auto accessor auto accessor
(GeneralStructMemberAccessor<StructT, OwnerT, MemberT>::make(member_addr)); (GeneralStructMemberAccessor<StructT, OwnerT, MemberT>::make(member_addr));
/* used to do this in GeneralStructMemberAccessor<> ctor, /* used to do this in GeneralStructMemberAccessor<> ctor,
* but that introduces #include cycle * but that introduces #include cycle
*/ */
Reflect::require<MemberT>(); Reflect::require<MemberT>();
this->member_v_.emplace_back(member_name, std::move(accessor)); this->member_v_.emplace_back(member_name, std::move(accessor));
} /*reflect_member*/ } /*reflect_member*/
void require_complete() { void require_complete() {
if(!s_reflected_flag) { if(!s_reflected_flag) {
s_reflected_flag = true; s_reflected_flag = true;
constexpr bool have_to_self_tp = std::is_base_of_v<SelfTagging, StructT>; constexpr bool have_to_self_tp = std::is_base_of_v<SelfTagging, StructT>;
/* if self-tagging, can use .self_tp() to get most-derived tagged pointer */ /* if self-tagging, can use .self_tp() to get most-derived tagged pointer */
auto to_self_tp_fn auto to_self_tp_fn
= ([](void * object) = ([](void * object)
{ {
return SelfTagger<StructT, have_to_self_tp>::self_tp(object); return SelfTagger<StructT, have_to_self_tp>::self_tp(object);
}); });
auto tdx = StructTdx::make(std::move(this->member_v_), auto tdx = StructTdx::make(std::move(this->member_v_),
have_to_self_tp, have_to_self_tp,
to_self_tp_fn); to_self_tp_fn);
this->td_->assign_tdextra(std::move(tdx)); this->td_->assign_tdextra(std::move(tdx));
} }
} /*complete*/ } /*complete*/
template<typename AncestorT> template<typename AncestorT>
void adopt_ancestors() { void adopt_ancestors() {
assert(Reflect::is_reflected<AncestorT>()); assert(Reflect::is_reflected<AncestorT>());
TypeDescr ancestor_td = Reflect::require<AncestorT>(); TypeDescr ancestor_td = Reflect::require<AncestorT>();
/* requires that reflection of AncestorT has completed */ /* requires that reflection of AncestorT has completed */
{ {
assert(ancestor_td->is_struct()); assert(ancestor_td->is_struct());
assert(ancestor_td->complete_flag()); assert(ancestor_td->complete_flag());
} }
/* for structs, /* for structs,
* we know that object argument to TypeDescr::n_child() is unused * we know that object argument to TypeDescr::n_child() is unused
*/ */
for (uint32_t i = 0, n = ancestor_td->n_child(nullptr); i < n; ++i) { for (uint32_t i = 0, n = ancestor_td->n_child(nullptr); i < n; ++i) {
StructMember const & member = ancestor_td->struct_member(i); StructMember const & member = ancestor_td->struct_member(i);
this->member_v_.push_back(member.for_descendant<StructT, AncestorT>()); this->member_v_.push_back(member.for_descendant<StructT, AncestorT>());
} }
} /*adopt_ancestors*/ } /*adopt_ancestors*/
private: private:

View file

@ -2,8 +2,7 @@
#pragma once #pragma once
#include "reflect/TypeDescr.hpp" #include "TypeDescr.hpp"
//#include "reflect/EstablishTypeDescr.hpp"
#include <unordered_set> #include <unordered_set>
namespace xo { namespace xo {

View file

@ -5,7 +5,7 @@
#pragma once #pragma once
#include "reflect/TaggedPtr.hpp" #include "TaggedPtr.hpp"
// causes #include cycle, reflect/Reflect.hpp includes this header // causes #include cycle, reflect/Reflect.hpp includes this header
//#include "reflect/Reflect.hpp" //#include "reflect/Reflect.hpp"
#include "refcnt/Refcounted.hpp" #include "refcnt/Refcounted.hpp"
@ -20,22 +20,22 @@ namespace xo {
class TaggedRcptr : public TaggedPtr { class TaggedRcptr : public TaggedPtr {
public: public:
using Refcount = ref::Refcount; using Refcount = ref::Refcount;
public: public:
TaggedRcptr(TypeDescr td, Refcount * x) : TaggedPtr(td, x) { TaggedRcptr(TypeDescr td, Refcount * x) : TaggedPtr(td, x) {
ref::intrusive_ptr_add_ref(x); ref::intrusive_ptr_add_ref(x);
} }
TaggedRcptr(TaggedRcptr const & x) : TaggedPtr(x) { TaggedRcptr(TaggedRcptr const & x) : TaggedPtr(x) {
ref::intrusive_ptr_add_ref(x.rc_address()); ref::intrusive_ptr_add_ref(x.rc_address());
} }
TaggedRcptr(TaggedRcptr && x) : TaggedPtr(std::move(x)) { TaggedRcptr(TaggedRcptr && x) : TaggedPtr(std::move(x)) {
/* since we're moving from x, need to make sure x.dtor /* since we're moving from x, need to make sure x.dtor
* doesn't decrement refcount * doesn't decrement refcount
*/ */
x.assign_address(nullptr); x.assign_address(nullptr);
} }
~TaggedRcptr() { ~TaggedRcptr() {
ref::intrusive_ptr_release(this->rc_address()); ref::intrusive_ptr_release(this->rc_address());
} }
/* causes #include cycle, see [reflect/Reflect.hpp] */ /* causes #include cycle, see [reflect/Reflect.hpp] */
@ -46,37 +46,37 @@ namespace xo {
#endif #endif
Refcount * rc_address() const { Refcount * rc_address() const {
return reinterpret_cast<Refcount *>(this->address()); return reinterpret_cast<Refcount *>(this->address());
} /*rc_address*/ } /*rc_address*/
TaggedRcptr & operator=(TaggedRcptr const & rhs) { TaggedRcptr & operator=(TaggedRcptr const & rhs) {
Refcount * x = rhs.rc_address(); Refcount * x = rhs.rc_address();
Refcount * old = this->rc_address(); Refcount * old = this->rc_address();
TaggedPtr::operator=(rhs); TaggedPtr::operator=(rhs);
if (x != old) { if (x != old) {
intrusive_ptr_release(old); intrusive_ptr_release(old);
intrusive_ptr_add_ref(x); intrusive_ptr_add_ref(x);
} }
return *this; return *this;
} /*operator=*/ } /*operator=*/
TaggedRcptr & operator=(TaggedRcptr && rhs) { TaggedRcptr & operator=(TaggedRcptr && rhs) {
/* swap pointers + type descriptions; /* swap pointers + type descriptions;
* then don't need to touch refcounts * then don't need to touch refcounts
*/ */
std::swap(this->td_, rhs.td_); std::swap(this->td_, rhs.td_);
std::swap(this->address_, rhs.address_); std::swap(this->address_, rhs.address_);
return *this; return *this;
} /*operator=*/ } /*operator=*/
void display(std::ostream & os) const; void display(std::ostream & os) const;
std::string display_string() const; std::string display_string() const;
}; /*TaggedRcptr*/ }; /*TaggedRcptr*/
inline std::ostream & operator<<(std::ostream & os, TaggedRcptr const & x) { inline std::ostream & operator<<(std::ostream & os, TaggedRcptr const & x) {
x.display(os); x.display(os);
return os; return os;

View file

@ -3,7 +3,7 @@
#pragma once #pragma once
//#include "reflect/atomic/AtomicTdx.hpp" //#include "reflect/atomic/AtomicTdx.hpp"
#include "reflect/TypeDescrExtra.hpp" #include "TypeDescrExtra.hpp"
#include "cxxutil/demangle.hpp" #include "cxxutil/demangle.hpp"
#include <iostream> #include <iostream>
#include <typeinfo> #include <typeinfo>

View file

@ -2,7 +2,7 @@
#pragma once #pragma once
#include "reflect/Metatype.hpp" #include "Metatype.hpp"
#include <string> #include <string>
/* note: this file #include'd into TypeDescr.hpp */ /* note: this file #include'd into TypeDescr.hpp */
#include <cstdint> #include <cstdint>

View file

@ -2,7 +2,7 @@
#pragma once #pragma once
#include "reflect/TypeDescrExtra.hpp" #include "xo/reflect/TypeDescrExtra.hpp"
//#include "reflect/TaggedPtr.hpp" //#include "reflect/TaggedPtr.hpp"
#include <memory> #include <memory>

View file

@ -5,8 +5,8 @@
#pragma once #pragma once
#include "reflect/TypeDescrExtra.hpp" #include "xo/reflect/TypeDescrExtra.hpp"
#include "reflect/EstablishTypeDescr.hpp" #include "xo/reflect/EstablishTypeDescr.hpp"
#include "indentlog/scope.hpp" #include "indentlog/scope.hpp"
namespace xo { namespace xo {

View file

@ -2,10 +2,9 @@
#pragma once #pragma once
#include "reflect/TypeDescr.hpp" #include "xo/reflect/TypeDescr.hpp"
#include "reflect/EstablishTypeDescr.hpp" #include "xo/reflect/EstablishTypeDescr.hpp"
//#include "reflect/Reflect.hpp" #include "xo/reflect/TaggedPtr.hpp"
#include "reflect/TaggedPtr.hpp"
#include <string> #include <string>
#include <memory> #include <memory>
@ -14,7 +13,7 @@ namespace reflect {
class AbstractStructMemberAccessor { class AbstractStructMemberAccessor {
public: public:
virtual ~AbstractStructMemberAccessor() = default; virtual ~AbstractStructMemberAccessor() = default;
/* get tagged pointer referring to this member of the object at *struct_addr */ /* get tagged pointer referring to this member of the object at *struct_addr */
TaggedPtr member_tp(void * struct_addr) const; TaggedPtr member_tp(void * struct_addr) const;
@ -30,7 +29,7 @@ namespace reflect {
* .member_td() => Reflect::require<int>(); * .member_td() => Reflect::require<int>();
*/ */
virtual TypeDescr member_td() const = 0; virtual TypeDescr member_td() const = 0;
/* get address of a particular member, given parent address */ /* get address of a particular member, given parent address */
virtual void * address(void * struct_addr) const = 0; virtual void * address(void * struct_addr) const = 0;
@ -63,7 +62,7 @@ namespace reflect {
public: public:
GeneralStructMemberAccessor(Memptr memptr) : member_td_{EstablishTypeDescr::establish<MemberT>()}, GeneralStructMemberAccessor(Memptr memptr) : member_td_{EstablishTypeDescr::establish<MemberT>()},
memptr_{memptr} {} memptr_{memptr} {}
GeneralStructMemberAccessor(GeneralStructMemberAccessor const & x) = default; GeneralStructMemberAccessor(GeneralStructMemberAccessor const & x) = default;
virtual ~GeneralStructMemberAccessor() = default; virtual ~GeneralStructMemberAccessor() = default;
@ -78,7 +77,7 @@ namespace reflect {
return &(owner_addr->*memptr_); return &(owner_addr->*memptr_);
} /*address_impl*/ } /*address_impl*/
// ----- Inherited from AbstractStructMemberAccessor ----- // ----- Inherited from AbstractStructMemberAccessor -----
#ifdef OBSOLETE #ifdef OBSOLETE
@ -102,7 +101,7 @@ namespace reflect {
virtual std::unique_ptr<AbstractStructMemberAccessor> clone() const override { virtual std::unique_ptr<AbstractStructMemberAccessor> clone() const override {
return std::unique_ptr<AbstractStructMemberAccessor> return std::unique_ptr<AbstractStructMemberAccessor>
(new GeneralStructMemberAccessor(*this)); (new GeneralStructMemberAccessor(*this));
} /*clone*/ } /*clone*/
private: private:
@ -142,7 +141,7 @@ namespace reflect {
static std::unique_ptr<AncestorStructMemberAccessor> static std::unique_ptr<AncestorStructMemberAccessor>
adopt(std::unique_ptr<AbstractStructMemberAccessor> ancestor_accessor) { adopt(std::unique_ptr<AbstractStructMemberAccessor> ancestor_accessor) {
return std::unique_ptr<AncestorStructMemberAccessor> return std::unique_ptr<AncestorStructMemberAccessor>
(new AncestorStructMemberAccessor(std::move(ancestor_accessor))); (new AncestorStructMemberAccessor(std::move(ancestor_accessor)));
} /*adopt*/ } /*adopt*/
void * address_impl(StructT * self_addr) const { void * address_impl(StructT * self_addr) const {
@ -171,7 +170,7 @@ namespace reflect {
virtual std::unique_ptr<AbstractStructMemberAccessor> clone() const override { virtual std::unique_ptr<AbstractStructMemberAccessor> clone() const override {
return std::unique_ptr<AbstractStructMemberAccessor> return std::unique_ptr<AbstractStructMemberAccessor>
(new AncestorStructMemberAccessor(std::move(this->ancestor_accessor_->clone()))); (new AncestorStructMemberAccessor(std::move(this->ancestor_accessor_->clone())));
} /*clone*/ } /*clone*/
private: private:
@ -186,11 +185,11 @@ namespace reflect {
public: public:
StructMember() = default; StructMember() = default;
StructMember(std::string const & name, StructMember(std::string const & name,
std::unique_ptr<AbstractStructMemberAccessor> accessor) std::unique_ptr<AbstractStructMemberAccessor> accessor)
: member_name_{name}, accessor_{std::move(accessor)} {} : member_name_{name}, accessor_{std::move(accessor)} {}
StructMember(StructMember && x) StructMember(StructMember && x)
: member_name_{std::move(x.member_name_)}, : member_name_{std::move(x.member_name_)},
accessor_{std::move(x.accessor_)} {} accessor_{std::move(x.accessor_)} {}
static StructMember null(); static StructMember null();
@ -210,8 +209,8 @@ namespace reflect {
assert(EstablishTypeDescr::establish<StructT>() == this->get_struct_td()); assert(EstablishTypeDescr::establish<StructT>() == this->get_struct_td());
return StructMember(this->member_name(), return StructMember(this->member_name(),
std::move(AncestorStructMemberAccessor<DescendantT, StructT>::adopt std::move(AncestorStructMemberAccessor<DescendantT, StructT>::adopt
(std::move(this->accessor_->clone())))); (std::move(this->accessor_->clone()))));
} /*for_descendant*/ } /*for_descendant*/
StructMember & operator=(StructMember && x) { StructMember & operator=(StructMember && x) {

View file

@ -2,9 +2,10 @@
#pragma once #pragma once
#include "reflect/TypeDescrExtra.hpp" #include "xo/reflect/TypeDescrExtra.hpp"
#include "reflect/TaggedPtr.hpp" #include "xo/reflect/TaggedPtr.hpp"
#include "reflect/struct/StructMember.hpp" #include "StructMember.hpp"
//#include "xo/reflect/struct/StructMember.hpp"
#include <vector> #include <vector>
#include <functional> #include <functional>
#include <memory> #include <memory>

View file

@ -5,12 +5,8 @@
#pragma once #pragma once
#include "reflect/TypeDescrExtra.hpp" #include "xo/reflect/TypeDescrExtra.hpp"
//#include "reflect/TaggedPtr.hpp" #include "xo/reflect/EstablishTypeDescr.hpp"
#include "reflect/EstablishTypeDescr.hpp"
//#include "reflect/TaggedPtr.hpp"
//#include <vector>
//#include <memory>
namespace xo { namespace xo {
namespace reflect { namespace reflect {
@ -42,19 +38,19 @@ namespace xo {
using target_t = VectorT; using target_t = VectorT;
static std::unique_ptr<StlVectorTdx> make() { static std::unique_ptr<StlVectorTdx> make() {
return std::unique_ptr<StlVectorTdx>(new StlVectorTdx()); return std::unique_ptr<StlVectorTdx>(new StlVectorTdx());
} /*make*/ } /*make*/
virtual uint32_t n_child(void * object) const override { virtual uint32_t n_child(void * object) const override {
target_t * vec = reinterpret_cast<target_t *>(object); target_t * vec = reinterpret_cast<target_t *>(object);
return vec->size(); return vec->size();
} /*n_child*/ } /*n_child*/
virtual TaggedPtr child_tp(uint32_t i, void * object) const override { virtual TaggedPtr child_tp(uint32_t i, void * object) const override {
target_t * vec = reinterpret_cast<target_t *>(object); target_t * vec = reinterpret_cast<target_t *>(object);
return establish_most_derived_tp(&((*vec)[i])); return establish_most_derived_tp(&((*vec)[i]));
} /*child_tp*/ } /*child_tp*/
}; /*StlVectorTdx*/ }; /*StlVectorTdx*/
@ -66,9 +62,9 @@ namespace xo {
template<typename Element, std::size_t N> template<typename Element, std::size_t N>
using StdArrayTdx = StlVectorTdx<std::array<Element, N>>; using StdArrayTdx = StlVectorTdx<std::array<Element, N>>;
// ----- std::vector<Element> ----- // ----- std::vector<Element> -----
/* coordinates with EstablishTdx<std::vector<Element>>::make() /* coordinates with EstablishTdx<std::vector<Element>>::make()
* see [reflect/Reflect.hpp] * see [reflect/Reflect.hpp]
*/ */
@ -76,21 +72,21 @@ namespace xo {
class StdVectorTdx : public VectorTdx { class StdVectorTdx : public VectorTdx {
public: public:
using target_t = std::vector<Element>; using target_t = std::vector<Element>;
static std::unique_ptr<StdVectorTdx> make() { static std::unique_ptr<StdVectorTdx> make() {
return std::unique_ptr<StdVectorTdx>(new StdVectorTdx()); return std::unique_ptr<StdVectorTdx>(new StdVectorTdx());
} /*make*/ } /*make*/
virtual uint32_t n_child(void * object) const override { virtual uint32_t n_child(void * object) const override {
target_t * vec = reinterpret_cast<target_t *>(object); target_t * vec = reinterpret_cast<target_t *>(object);
return vec->size(); return vec->size();
} /*n_child*/ } /*n_child*/
virtual TaggedPtr child_tp(uint32_t i, void * object) const override { virtual TaggedPtr child_tp(uint32_t i, void * object) const override {
target_t * vec = reinterpret_cast<target_t *>(object); target_t * vec = reinterpret_cast<target_t *>(object);
return establish_most_derived_tp(&((*vec)[i])); return establish_most_derived_tp(&((*vec)[i]));
} }
}; /*StdVectorTdx*/ }; /*StdVectorTdx*/
} /*namespace reflect*/ } /*namespace reflect*/

View file

@ -3,12 +3,12 @@
* author: Roland Conybeare, Aug 2022 * author: Roland Conybeare, Aug 2022
*/ */
#include "reflect/Reflect.hpp" #include "xo/reflect/Reflect.hpp"
#include "reflect/StructReflector.hpp" #include "xo/reflect/StructReflector.hpp"
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
namespace xo { namespace xo {
using xo::reflect::Reflect; using xo::reflect::Reflect;
using xo::reflect::TaggedPtr; using xo::reflect::TaggedPtr;
@ -129,7 +129,7 @@ namespace xo {
REQUIRE(tp.get_child(2).td() == Reflect::require<double>()); REQUIRE(tp.get_child(2).td() == Reflect::require<double>());
REQUIRE(tp.get_child(2).address() == &(recd1.z_)); REQUIRE(tp.get_child(2).address() == &(recd1.z_));
REQUIRE(tp.get_child(3).is_universal_null()); REQUIRE(tp.get_child(3).is_universal_null());
REQUIRE(tp.get_child(3).td() == nullptr); REQUIRE(tp.get_child(3).td() == nullptr);
REQUIRE(tp.get_child(3).address() == nullptr); REQUIRE(tp.get_child(3).address() == nullptr);

View file

@ -3,7 +3,7 @@
* author: Roland Conybeare, Aug 2022 * author: Roland Conybeare, Aug 2022
*/ */
#include "reflect/Reflect.hpp" #include "xo/reflect/Reflect.hpp"
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
namespace xo { namespace xo {

View file

@ -3,7 +3,7 @@
* author: Roland Conybeare, Aug 2022 * author: Roland Conybeare, Aug 2022
*/ */
#include "reflect/Reflect.hpp" #include "xo/reflect/Reflect.hpp"
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
namespace xo { namespace xo {
@ -81,7 +81,7 @@ namespace xo {
REQUIRE(tp0.td()->metatype() == Metatype::mt_atomic); REQUIRE(tp0.td()->metatype() == Metatype::mt_atomic);
REQUIRE(tp0.recover_native<double>() == &(v[0])); REQUIRE(tp0.recover_native<double>() == &(v[0]));
REQUIRE(tp0.n_child() == 0); REQUIRE(tp0.n_child() == 0);
TaggedPtr tp1 = tp.get_child(1); TaggedPtr tp1 = tp.get_child(1);
REQUIRE(tp1.td()->complete_flag()); REQUIRE(tp1.td()->complete_flag());
@ -91,7 +91,7 @@ namespace xo {
REQUIRE(tp1.td()->metatype() == Metatype::mt_atomic); REQUIRE(tp1.td()->metatype() == Metatype::mt_atomic);
REQUIRE(tp1.recover_native<double>() == &(v[1])); REQUIRE(tp1.recover_native<double>() == &(v[1]));
REQUIRE(tp1.n_child() == 0); REQUIRE(tp1.n_child() == 0);
} /*TEST(std-vector-reflect-two)*/ } /*TEST(std-vector-reflect-two)*/
// ----- std::array ----- // ----- std::array -----
@ -163,7 +163,7 @@ namespace xo {
REQUIRE(tp0.td()->metatype() == Metatype::mt_atomic); REQUIRE(tp0.td()->metatype() == Metatype::mt_atomic);
REQUIRE(tp0.recover_native<double>() == &(v[0])); REQUIRE(tp0.recover_native<double>() == &(v[0]));
REQUIRE(tp0.n_child() == 0); REQUIRE(tp0.n_child() == 0);
TaggedPtr tp1 = tp.get_child(1); TaggedPtr tp1 = tp.get_child(1);
REQUIRE(tp1.td()->complete_flag()); REQUIRE(tp1.td()->complete_flag());
@ -173,7 +173,7 @@ namespace xo {
REQUIRE(tp1.td()->metatype() == Metatype::mt_atomic); REQUIRE(tp1.td()->metatype() == Metatype::mt_atomic);
REQUIRE(tp1.recover_native<double>() == &(v[1])); REQUIRE(tp1.recover_native<double>() == &(v[1]));
REQUIRE(tp1.n_child() == 0); REQUIRE(tp1.n_child() == 0);
} /*TEST(std-array-reflect-two)*/ } /*TEST(std-array-reflect-two)*/
} /*namespace ut*/ } /*namespace ut*/
} /*namespace xo*/ } /*namespace xo*/