24 void printName() { std::cout <<
"printName: Foo" << std::endl; }
33 virtual void printName() { std::cout <<
"printName: BarBase" << std::endl; }
36 class Bar :
public BarBase
42 void printName()
override { std::cout <<
"class: Bar" << std::endl; }
45 std::cout <<
"specificBarMethod: reached." << std::endl;
61 std::cout <<
"RTTI Foo (static): " << id_foo->className << std::endl;
64 Bar::Ptr pBar = std::make_shared<Bar>();
71 std::cout <<
"Is Foo? => " << (
IS_DERIVED(*pObj,
Foo) ?
"Yes\n" :
"No\n");
72 std::cout <<
"Is BarBase? => " 74 std::cout <<
"Is Bar? => " << (
IS_DERIVED(*pObj,
Bar) ?
"Yes\n" :
"No\n");
78 pBar2->specificBarMethod();
105 for (
const auto& cl : allClasses)
107 std::cout <<
"Known class: " << cl->className <<
", children of " 108 << (cl->getBaseClass ? cl->getBaseClass()->className
120 pBar->specificBarMethod();
135 catch (
const std::exception& e)
void printName() override
void Test_UserTypesFactory()
#define DEFINE_VIRTUAL_MRPT_OBJECT(class_name)
This declaration must be inserted in virtual CObject classes definition:
IMPLEMENTS_MRPT_OBJECT(CMultiObjMotionOpt_Scalarization, CMultiObjectiveMotionOptimizerBase, mrpt::nav) CMultiObjMotionOpt_Scalarization
Virtual base to provide a compiler-independent RTTI system.
IMPLEMENTS_VIRTUAL_MRPT_OBJECT(CMultiObjectiveMotionOptimizerBase, CObject, mrpt::nav) CMultiObjectiveMotionOptimizerBase
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
#define IS_DERIVED(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is an instance of the given ...
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class...
void registerClassCustomName(const char *customName, const TRuntimeClassId *pNewClass)
Mostly for internal use within mrpt sources, to handle exceptional cases with multiple serialization ...
#define CLASS_ID_NAMESPACE(class_name, namespaceName)
mrpt::rtti::CObject::Ptr classFactory(const std::string &className)
Creates an object given by its registered name.
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
static CAST_TO::Ptr from(const CAST_FROM_PTR &ptr)
void registerClass(const mrpt::rtti::TRuntimeClassId *pNewClass)
Register a class into the MRPT internal list of "CObject" descendents.
void Test_UserTypes()
[example-define-class]
#define DEFINE_MRPT_OBJECT(class_name, NameSpace)
This declaration must be inserted in all CObject classes definition, within the class declaration...
std::vector< const mrpt::rtti::TRuntimeClassId * > getAllRegisteredClasses()
Returns a list with all the classes registered in the system through mrpt::rtti::registerClass.