42 bool derivedFrom(
const char* pBaseClass_name)
const;
79 return &T::GetRuntimeClassIdStatic();
84 #define CLASS_ID(T) mrpt::rtti::CLASS_ID_impl<T>() 86 #define CLASS_ID_TEMPLATE(class_name, T) mrpt::rtti::CLASS_ID_impl<T>() 87 #define CLASS_ID_NAMESPACE(class_name, namespaceName) \ 88 mrpt::rtti::CLASS_ID_impl<namespaceName::class_name>() 93 template <
typename PTR>
96 return p->GetRuntimeClass() == CLASS_ID_impl<T>();
102 #define IS_CLASS(ptrObj, class_name) \ 103 mrpt::rtti::IS_CLASS_impl<class_name>::check(ptrObj) 108 #define IS_DERIVED(ptrObj, class_name) \ 109 ((ptrObj)->GetRuntimeClass()->derivedFrom(CLASS_ID(class_name))) 175 #define DEFINE_MRPT_OBJECT(class_name) \ 179 static const mrpt::rtti::TRuntimeClassId* _GetBaseClass(); \ 180 static mrpt::rtti::CLASSINIT _init_##class_name; \ 181 static const mrpt::rtti::TRuntimeClassId runtimeClassId; \ 185 using Ptr = std::shared_ptr<class_name>; \ 186 using ConstPtr = std::shared_ptr<const class_name>; \ 187 using UniquePtr = std::unique_ptr<class_name>; \ 188 using ConstUniquePtr = std::unique_ptr<const class_name>; \ 189 static constexpr const char* className = #class_name; \ 190 static constexpr auto getClassName() \ 192 return mrpt::typemeta::literal(#class_name); \ 194 static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic(); \ 195 virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() \ 197 static mrpt::rtti::CObject* CreateObject(); \ 198 virtual mrpt::rtti::CObject* clone() const override; \ 199 template <typename... Args> \ 200 static Ptr Create(Args&&... args) \ 202 return mrpt::make_aligned_shared<class_name>( \ 203 std::forward<Args>(args)...); \ 205 template <typename... Args> \ 206 static UniquePtr CreateUnique(Args&&... args) \ 208 return std::make_unique<class_name>(std::forward<Args>(args)...); \ 212 MRPT_MAKE_ALIGNED_OPERATOR_NEW 216 #define IMPLEMENTS_MRPT_OBJECT(class_name, base, NameSpace) \ 217 mrpt::rtti::CObject* NameSpace::class_name::CreateObject() \ 219 return static_cast<mrpt::rtti::CObject*>(new NameSpace::class_name); \ 221 const mrpt::rtti::TRuntimeClassId* NameSpace::class_name::_GetBaseClass() \ 223 return CLASS_ID(base); \ 225 const mrpt::rtti::TRuntimeClassId& \ 226 NameSpace::class_name::GetRuntimeClassIdStatic() \ 228 return NameSpace::class_name::runtimeClassId; \ 230 const mrpt::rtti::TRuntimeClassId NameSpace::class_name::runtimeClassId = \ 231 {#class_name, NameSpace::class_name::CreateObject, \ 232 &class_name::_GetBaseClass}; \ 233 const mrpt::rtti::TRuntimeClassId* \ 234 NameSpace::class_name::GetRuntimeClass() const \ 236 return CLASS_ID_NAMESPACE(class_name, NameSpace); \ 238 mrpt::rtti::CLASSINIT NameSpace::class_name::_init_##class_name( \ 240 mrpt::rtti::CObject* NameSpace::class_name::clone() const \ 242 return static_cast<mrpt::rtti::CObject*>( \ 243 new NameSpace::class_name(*this)); \ 249 #define DEFINE_VIRTUAL_MRPT_OBJECT(class_name) \ 253 static const mrpt::rtti::TRuntimeClassId* _GetBaseClass(); \ 254 static const mrpt::rtti::TRuntimeClassId runtimeClassId; \ 257 using Ptr = std::shared_ptr<class_name>; \ 258 using ConstPtr = std::shared_ptr<const class_name>; \ 259 virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() \ 261 static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic(); \ 267 #define IMPLEMENTS_VIRTUAL_MRPT_OBJECT(class_name, base_class_name, NameSpace) \ 268 const mrpt::rtti::TRuntimeClassId* NameSpace::class_name::_GetBaseClass() \ 270 return CLASS_ID(base_class_name); \ 272 const mrpt::rtti::TRuntimeClassId NameSpace::class_name::runtimeClassId = \ 273 {#class_name, nullptr, &NameSpace::class_name::_GetBaseClass}; \ 274 const mrpt::rtti::TRuntimeClassId* \ 275 NameSpace::class_name::GetRuntimeClass() const \ 277 return CLASS_ID(class_name); \ 279 const mrpt::rtti::TRuntimeClassId& \ 280 NameSpace::class_name::GetRuntimeClassIdStatic() \ 282 return NameSpace::class_name::runtimeClassId; \ 307 template <
typename CAST_TO>
310 template <
typename CAST_FROM_PTR>
311 static typename CAST_TO::Ptr
from(
const CAST_FROM_PTR& ptr)
313 return std::dynamic_pointer_cast<CAST_TO>(ptr);
void registerAllPendingClasses()
Register all pending classes - to be called just before de-serializing an object, for example...
Auxiliary structure used for CObject-based RTTI.
constexpr const mrpt::rtti::TRuntimeClassId * CLASS_ID_impl()
std::vector< const TRuntimeClassId * > getAllRegisteredClassesChildrenOf(const TRuntimeClassId *parent_id)
Like getAllRegisteredClasses(), but filters the list to only include children clases of a given base ...
A structure that holds runtime class type information.
Converts a polymorphic smart pointer Base::Ptr to Derived::Ptr, in a way compatible with MRPT >=1...
The virtual base class of all MRPT classes with a unified RTTI system.
CLASSINIT(const mrpt::rtti::TRuntimeClassId *pNewClass)
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
virtual CObject * clone() const =0
Returns a deep copy (clone) of the object, indepently of its class.
static bool check(const PTR &p)
virtual const mrpt::rtti::TRuntimeClassId * GetRuntimeClass() const
Returns information about the class of an object in runtime.
A wrapper class for pointers that can be safely copied with "=" operator without problems.
GLsizei const GLchar ** string
void registerClassCustomName(const char *customName, const TRuntimeClassId *pNewClass)
Mostly for internal use within mrpt sources, to handle exceptional cases with multiple serialization ...
const TRuntimeClassId * findRegisteredClass(const std::string &className)
Return info about a given class by its name, or nullptr if the class is not registered.
mrpt::rtti::CObject * classFactory(const std::string &className)
Creates an object given by its registered name.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static const mrpt::rtti::TRuntimeClassId & GetRuntimeClassIdStatic()
static mrpt::rtti::TRuntimeClassId * _GetBaseClass()
bool derivedFrom(const TRuntimeClassId *pBaseClass) const
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.
static const mrpt::rtti::TRuntimeClassId runtimeClassId
mrpt::rtti::CObject * createObject() const
std::vector< const mrpt::rtti::TRuntimeClassId * > getAllRegisteredClasses()
Returns a list with all the classes registered in the system through mrpt::rtti::registerClass.
mrpt::rtti::CObject::Ptr classFactoryPtr(const std::string &className)
Like classFactory() but returns a smart pointer.
std::shared_ptr< CObject > Ptr
mrpt::rtti::CObject::Ptr duplicateGetSmartPtr() const
Returns a copy of the object, indepently of its class, as a smart pointer (the newly created object w...