xo-reflect: + TypeDescr:: n_child_fixed(), fixed_child_td(i)

This commit is contained in:
Roland Conybeare 2024-06-25 19:37:16 -04:00
commit 2b9aff3640
9 changed files with 56 additions and 2 deletions

View file

@ -305,7 +305,18 @@ namespace xo {
* .n_child() reports #of instance variables (that have been reflected)
*/
uint32_t n_child(void * object) const { return this->tdextra_->n_child(object); }
/** in some circumstances can use this with object=nullptr **/
/** number of children, if that number is fixed at compile time. otherwise 0
**/
uint32_t n_child_fixed() const { return this->tdextra_->n_child_fixed(); }
/** TypeDescr for i'th child, using only information available at compile time.
* e.g. for vectors/pointers, always returns ElementType.
**/
TypeDescr fixed_child_td(uint32_t i) const { return this->tdextra_->fixed_child_td(i); }
/** TaggedPtr to child @p i.
* Will report most-derived-type for type tag,
* so may refer to a proper subtype (e.g. derived class) of the type
* reported by @c fixed_child_td(i)
**/
TaggedPtr child_tp(uint32_t i, void * object) const;
/* require:

View file

@ -59,6 +59,12 @@ namespace xo {
* Will also return 0 for types like {bool, int, long} (because number is zero)
**/
virtual uint32_t n_child_fixed() const = 0;
/** type description for i'th child, based on information available at compile time.
* For vectors/pointers, this always refers to element type.
*
* nullptr for atomics
**/
virtual const TypeDescrBase * fixed_child_td(uint32_t i) const = 0;
virtual TaggedPtr child_tp(uint32_t i, void * object) const = 0;
/* require:
* .is_struct()

View file

@ -26,6 +26,7 @@ namespace xo {
virtual uint32_t n_child(void * /*object*/) const override { return 0; }
virtual uint32_t n_child_fixed() const override { return 0; }
virtual TaggedPtr child_tp(uint32_t /*i*/, void * /*object*/) const override;
virtual const TypeDescrBase * fixed_child_td(uint32_t /*i*/) const override;
virtual std::string const & struct_member_name(uint32_t i) const override;
//virtual StructMember const * struct_member(uint32_t /*i*/) const override { return nullptr; }

View file

@ -35,6 +35,7 @@ namespace xo {
virtual uint32_t n_child(void * /*object*/) const override { return 0; }
virtual uint32_t n_child_fixed() const override { return 0; }
virtual TaggedPtr child_tp(uint32_t i, void * object) const override;
virtual TypeDescr fixed_child_td(uint32_t i) const override;
const std::string & struct_member_name(uint32_t i) const override;
virtual const FunctionTdxInfo * fn_info() const override { return &info_; }

View file

@ -71,6 +71,7 @@ namespace xo {
virtual uint32_t n_child(void * /*object*/) const override { return this->member_v_.size(); }
virtual uint32_t n_child_fixed() const override { return this->member_v_.size(); }
virtual TaggedPtr child_tp(uint32_t i, void * object) const override;
virtual TypeDescr fixed_child_td(uint32_t i) const override;
virtual std::string const & struct_member_name(uint32_t i) const override;
virtual StructMember const * struct_member(uint32_t i) const override;

View file

@ -26,6 +26,7 @@ namespace xo {
virtual uint32_t n_child(void * object) const override = 0;
virtual uint32_t n_child_fixed() const override = 0;
virtual TaggedPtr child_tp(uint32_t i, void * object) const override = 0;
virtual TypeDescr fixed_child_td(uint32_t i) const override = 0;
/* (forbidden) */
virtual std::string const & struct_member_name(uint32_t i) const override;
}; /*VectorTdx*/
@ -33,6 +34,7 @@ namespace xo {
// ----- StlVectorTdx -----
/* require:
* - VectorT::value_type
* - VectorT.size()
* - VectorT[int] :: lvalue
*/
@ -60,6 +62,10 @@ namespace xo {
return establish_most_derived_tp(&((*vec)[i]));
} /*child_tp*/
virtual TypeDescr fixed_child_td(uint32_t /*i*/) const override {
return EstablishTypeDescr::establish<typename VectorT::value_type>();
}
}; /*StlVectorTdx*/
// ----- std::array<Element, N> -----
@ -105,6 +111,10 @@ namespace xo {
return establish_most_derived_tp(&((*vec)[i]));
}
virtual TypeDescr fixed_child_td(uint32_t /*i*/) const override {
return EstablishTypeDescr::establish<Element>();
}
}; /*StdVectorTdx*/
} /*namespace reflect*/