qxLib
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
qx::rtti_root< naming_strategy_t > Class Template Referenceabstract

Polymorphic base for qx class identity and inheritance queries. More...

#include <rtti.h>

Inheritance diagram for qx::rtti_root< naming_strategy_t >:
qx::rtti_pure_base qx::base_logger_stream qx::base_file_logger_stream qx::base_standard_streams_stream qx::debugger_logger_stream qx::error_context_stream qx::file_logger_stream_fopen qx::file_logger_stream_mapping qx::file_logger_stream_ofstream qx::cout_logger_stream qx::fwrite_logger_stream

Public Member Functions

template<class T >
bool is_derived_from () const noexcept
 Test exact identity or membership in the object's RTTI base chain. More...
 
template<class T >
bool is () const noexcept
 Compare the object's dynamic class identifier with T's identifier. More...
 
bool is (string_view svClassName) const noexcept
 Compare against the class name selected by the naming strategy. More...
 
bool is (const class_id &id) const noexcept
 Compare against the object's dynamic class identifier. More...
 
virtual bool is_derived_from_id (const class_id &id) const noexcept
 Test an identifier against the object's dynamic RTTI hierarchy. More...
 
virtual string_view get_class_name () const noexcept
 Get the name of the object's most-derived registered RTTI type. More...
 
virtual class_id get_class_id () const noexcept
 Get the identifier of the object's most-derived registered RTTI type. More...
 
virtual std::span< const class_id > get_inheritance_sequence () const =0
 Get the registered inheritance chain in base-to-derived order. More...
 

Static Public Member Functions

static constexpr bool is_derived_from_id_static (const class_id &id) noexcept
 Test an identifier against the declaring type's static RTTI hierarchy. More...
 
static constexpr string_view get_class_name_static () noexcept
 Apply the naming strategy to the declaring RTTI type's signature. More...
 
static constexpr class_id get_class_id_static () noexcept
 Create the declaring RTTI type's identifier from its type signature. More...
 

Protected Member Functions

virtual bool _is_base_id (const class_id &idBase) const noexcept
 Traverse identifiers treated as bases by derived RTTI classes. More...
 

Detailed Description

template<class naming_strategy_t = rtti_naming_strategy_class_name>
class qx::rtti_root< naming_strategy_t >

Polymorphic base for qx class identity and inheritance queries.

Derive an RTTI hierarchy from this type and use QX_RTTI_CLASS in each derived class to supply its identity and extend the inheritance chain. This system does not require compiler RTTI.

Static queries describe the type declaring them; virtual queries describe the object's most-derived registered type. is<T>() checks exact identity, while is_derived_from<T>() also accepts base types.

The naming strategy affects class names, not class identifiers. Names may be empty or shared by several types. The protected destructor prevents deleting an object directly through an rtti_root pointer.

Template Parameters
naming_strategy_t- strategy providing get_name(string_view) to transform the compiler-generated type signature into a class name
See also
rtti_naming_strategy.h
Author
Khrapov
Date
10.09.2021

Definition at line 68 of file rtti.h.

Member Function Documentation

◆ _is_base_id()

template<class naming_strategy_t >
bool qx::rtti_root< naming_strategy_t >::_is_base_id ( const class_id &  idBase) const
inlineprotectedvirtualnoexcept

Traverse identifiers treated as bases by derived RTTI classes.

Parameters
idBase- candidate identifier from an inheritance query
Return values
-true when an identifier matches during base-chain traversal

The root compares against its own identifier. Macro-generated overrides check their immediate base and continue recursively.

Definition at line 78 of file rtti.inl.

◆ get_class_id()

template<class naming_strategy_t >
class_id qx::rtti_root< naming_strategy_t >::get_class_id
inlinevirtualnoexcept

Get the identifier of the object's most-derived registered RTTI type.

Return values
-identifier used by exact-type comparisons and RTTI casts

Definition at line 72 of file rtti.inl.

◆ get_class_id_static()

template<class naming_strategy_t >
constexpr class_id qx::rtti_root< naming_strategy_t >::get_class_id_static
staticconstexprnoexcept

Create the declaring RTTI type's identifier from its type signature.

Note
The signature is compiler-dependent; identifiers are not a portable format for persisting type identity across different builds.
Return values
-identifier independent of the selected class-name representation

Definition at line 65 of file rtti.inl.

◆ get_class_name()

template<class naming_strategy_t >
string_view qx::rtti_root< naming_strategy_t >::get_class_name
inlinevirtualnoexcept

Get the name of the object's most-derived registered RTTI type.

Return values
-the naming strategy's result for the dynamic type; it may be empty

Definition at line 59 of file rtti.inl.

◆ get_class_name_static()

template<class naming_strategy_t >
constexpr string_view qx::rtti_root< naming_strategy_t >::get_class_name_static
staticconstexprnoexcept

Apply the naming strategy to the declaring RTTI type's signature.

Return values
-a class-name view that may be empty, depending on the strategy

Definition at line 53 of file rtti.inl.

◆ get_inheritance_sequence()

template<class naming_strategy_t = rtti_naming_strategy_class_name>
virtual std::span<const class_id> qx::rtti_root< naming_strategy_t >::get_inheritance_sequence ( ) const
pure virtual

Get the registered inheritance chain in base-to-derived order.

Return values
-identifiers from the rtti_root specialization through the dynamic type

QX_RTTI_CLASS returns a span backed by class-specific static storage, rather than storage owned by the object.

◆ is() [1/3]

template<class naming_strategy_t >
template<class T >
bool qx::rtti_root< naming_strategy_t >::is
inlinenoexcept

Compare the object's dynamic class identifier with T's identifier.

Template Parameters
T- candidate type exposing QX_RTTI_CLASS()
Return values
-true only when the identifiers match; base types are not accepted

Definition at line 23 of file rtti.inl.

◆ is() [2/3]

template<class naming_strategy_t >
bool qx::rtti_root< naming_strategy_t >::is ( const class_id &  id) const
inlinenoexcept

Compare against the object's dynamic class identifier.

Parameters
id- candidate for exact identity, not an inheritance query
Return values
-true when id equals get_class_id()

Definition at line 35 of file rtti.inl.

◆ is() [3/3]

template<class naming_strategy_t >
bool qx::rtti_root< naming_strategy_t >::is ( string_view  svClassName) const
inlinenoexcept

Compare against the class name selected by the naming strategy.

Note
Name equality does not imply type identity when the naming strategy produces duplicate names, such as rtti_naming_strategy_empty.
Parameters
svClassName- expected result of get_class_name(), not a base-class name
Return values
-true when the names match exactly

Definition at line 29 of file rtti.inl.

◆ is_derived_from()

template<class naming_strategy_t >
template<class T >
bool qx::rtti_root< naming_strategy_t >::is_derived_from
inlinenoexcept

Test exact identity or membership in the object's RTTI base chain.

Template Parameters
T- candidate type exposing QX_RTTI_CLASS()
Return values
-true for the object's registered type and its registered bases

Definition at line 15 of file rtti.inl.

◆ is_derived_from_id()

template<class naming_strategy_t >
bool qx::rtti_root< naming_strategy_t >::is_derived_from_id ( const class_id &  id) const
inlinevirtualnoexcept

Test an identifier against the object's dynamic RTTI hierarchy.

Parameters
id- candidate class identifier, including the object's own identifier
Return values
-true when id belongs to the registered type or one of its bases

Definition at line 41 of file rtti.inl.

◆ is_derived_from_id_static()

template<class naming_strategy_t >
constexpr bool qx::rtti_root< naming_strategy_t >::is_derived_from_id_static ( const class_id &  id)
staticconstexprnoexcept

Test an identifier against the declaring type's static RTTI hierarchy.

rtti_root matches only its own identifier; QX_RTTI_CLASS extends this comparison recursively through the declared base class.

Parameters
id- candidate class identifier to find in the static base chain
Return values
-true when id belongs to the declaring type or one of its bases

Definition at line 47 of file rtti.inl.


The documentation for this class was generated from the following files: