Doxygen with github
Loading...
Searching...
No Matches
ksf::ksRtti Class Referenceabstract

Implements RTTI (run-time type information) for objects. More...

#include <ksRtti.h>

+ Inheritance diagram for ksf::ksRtti:

Public Member Functions

virtual ~ksRtti ()=default
 Destructor.
 
virtual const std::size_t getInstanceType () const =0
 Retrieves type ID of the object.
 
virtual bool isA (const std::size_t id) const
 Checks whether object is of given type.
 
template<typename TType >
TType * as ()
 Tries to cast object to the type provided as a template parameter.
 
template<typename TType >
const TType * as () const
 Tries to cast object to the type provided as a template parameter (const version).
 

Detailed Description

Implements RTTI (run-time type information) for objects.

This is a simple, fast, and lightweight implementation of the RTTI feature. It provides the ability to check whether an object is of a given type and to cast it to the type specified as a template parameter.

It is extensively used to implement components (ksComponent) and to easily manage components within the application (ksApplication).

Member Function Documentation

◆ as() [1/2]

template<typename TType >
TType * ksf::ksRtti::as ( )
inline

Tries to cast object to the type provided as a template parameter.

Template Parameters
TTypeTarget type.
Returns
Pointer to object of given type or nullptr if object is not of given type.

References isA().

◆ as() [2/2]

template<typename TType >
const TType * ksf::ksRtti::as ( ) const
inline

Tries to cast object to the type provided as a template parameter (const version).

Template Parameters
TTypeTarget type.
Returns
Const pointer to object of given type or nullptr if object is not of given type.

References isA().

◆ getInstanceType()

virtual const std::size_t ksf::ksRtti::getInstanceType ( ) const
pure virtual

◆ isA()

virtual bool ksf::ksRtti::isA ( const std::size_t id) const
inlinevirtual

Checks whether object is of given type.

Parameters
idType ID to check against.
Returns
True if object is of given type, otherwise false.

Reimplemented in ksf::comps::ksConfigProvider, ksf::comps::ksDevicePortal, ksf::comps::ksDevStatMqttReporter, ksf::comps::ksLed, ksf::comps::ksMqttConfigProvider, ksf::comps::ksMqttConnector, ksf::comps::ksResetButton, ksf::comps::ksWifiConfigurator, ksf::comps::ksWifiConnector, and ksf::ksComponent.

Referenced by as(), and as().


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