43 bool derivedFrom(
const char* pBaseClass_name)
const;
82 return &T::GetRuntimeClassIdStatic();
89 #define CLASS_ID(T) mrpt::rtti::CLASS_ID_impl<T>::get() 91 #define CLASS_ID_TEMPLATE(class_name, T) mrpt::rtti::CLASS_ID_impl<T>::get() 92 #define CLASS_ID_NAMESPACE(class_name, namespaceName) \ 93 mrpt::rtti::CLASS_ID_impl<namespaceName::class_name>::get() 98 template <
typename REF>
107 template <
bool is_copy_ctrtible>
112 template <
typename T>
121 template <
typename T>
124 throw std::runtime_error(
125 "clone(): Attempt to call copy ctor of non copy-constructible " 133 #define IS_CLASS(obj, class_name) \ 134 mrpt::rtti::IS_CLASS_impl<class_name>::check(obj) 138 #define IS_DERIVED(obj, class_name) \ 139 ((obj).GetRuntimeClass()->derivedFrom(CLASS_ID(class_name))) 207 #define DEFINE_MRPT_OBJECT(class_name) \ 211 static const mrpt::rtti::TRuntimeClassId* _GetBaseClass(); \ 212 static mrpt::rtti::CLASSINIT _init_##class_name; \ 213 static const mrpt::rtti::TRuntimeClassId runtimeClassId; \ 217 using Ptr = std::shared_ptr<class_name>; \ 218 using ConstPtr = std::shared_ptr<const class_name>; \ 219 using UniquePtr = std::unique_ptr<class_name>; \ 220 using ConstUniquePtr = std::unique_ptr<const class_name>; \ 221 static constexpr const char* className = #class_name; \ 222 static constexpr auto getClassName() \ 224 return mrpt::typemeta::literal(#class_name); \ 226 static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic(); \ 227 virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() \ 229 virtual mrpt::rtti::CObject* clone() const override; \ 230 static std::shared_ptr<CObject> CreateObject(); \ 231 template <typename... Args> \ 232 static Ptr Create(Args&&... args) \ 234 return std::make_shared<class_name>(std::forward<Args>(args)...); \ 236 template <typename Alloc, typename... Args> \ 237 static Ptr CreateAlloc(const Alloc& alloc, Args&&... args) \ 239 return std::allocate_shared<class_name>( \ 240 alloc, std::forward<Args>(args)...); \ 242 template <typename... Args> \ 243 static UniquePtr CreateUnique(Args&&... args) \ 245 return std::make_unique<class_name>(std::forward<Args>(args)...); \ 250 #define INTERNAL_IMPLEMENTS_MRPT_OBJECT( \ 251 class_name, base, NameSpace, class_registry_name) \ 252 mrpt::rtti::CObject::Ptr NameSpace::class_name::CreateObject() \ 254 return std::static_pointer_cast<CObject>( \ 255 std::make_shared<NameSpace::class_name>()); \ 257 const mrpt::rtti::TRuntimeClassId* NameSpace::class_name::_GetBaseClass() \ 259 return CLASS_ID(base); \ 261 const mrpt::rtti::TRuntimeClassId& \ 262 NameSpace::class_name::GetRuntimeClassIdStatic() \ 264 return NameSpace::class_name::runtimeClassId; \ 266 const mrpt::rtti::TRuntimeClassId NameSpace::class_name::runtimeClassId = \ 267 {class_registry_name, NameSpace::class_name::CreateObject, \ 268 &class_name::_GetBaseClass}; \ 269 const mrpt::rtti::TRuntimeClassId* \ 270 NameSpace::class_name::GetRuntimeClass() const \ 272 return CLASS_ID_NAMESPACE(class_name, NameSpace); \ 274 mrpt::rtti::CLASSINIT NameSpace::class_name::_init_##class_name( \ 276 mrpt::rtti::CObject* NameSpace::class_name::clone() const \ 278 return mrpt::rtti::internal::CopyCtor<std::is_copy_constructible< \ 279 NameSpace::class_name>::value>::clone(*this); \ 286 #define IMPLEMENTS_MRPT_OBJECT_NS_PREFIX(class_name, base, NameSpace) \ 287 INTERNAL_IMPLEMENTS_MRPT_OBJECT( \ 288 class_name, base, NameSpace, #NameSpace "::" #class_name) 294 #define IMPLEMENTS_MRPT_OBJECT(class_name, base, NameSpace) \ 295 INTERNAL_IMPLEMENTS_MRPT_OBJECT(class_name, base, NameSpace, #class_name) 300 #define DEFINE_VIRTUAL_MRPT_OBJECT(class_name) \ 304 static const mrpt::rtti::TRuntimeClassId* _GetBaseClass(); \ 305 static const mrpt::rtti::TRuntimeClassId runtimeClassId; \ 308 using Ptr = std::shared_ptr<class_name>; \ 309 using ConstPtr = std::shared_ptr<const class_name>; \ 310 virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() \ 312 static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic(); \ 318 #define INTERNAL_IMPLEMENTS_VIRTUAL_MRPT_OBJECT( \ 319 class_name, base_name, NS, registered_name) \ 320 const mrpt::rtti::TRuntimeClassId* NS::class_name::_GetBaseClass() \ 322 return CLASS_ID(base_name); \ 324 const mrpt::rtti::TRuntimeClassId NS::class_name::runtimeClassId = { \ 325 registered_name, nullptr, &NS::class_name::_GetBaseClass}; \ 326 const mrpt::rtti::TRuntimeClassId* NS::class_name::GetRuntimeClass() const \ 328 return CLASS_ID(class_name); \ 330 const mrpt::rtti::TRuntimeClassId& \ 331 NS::class_name::GetRuntimeClassIdStatic() \ 333 return NS::class_name::runtimeClassId; \ 336 #define IMPLEMENTS_VIRTUAL_MRPT_OBJECT_NS_PREFIX(class_name, base, NS) \ 337 INTERNAL_IMPLEMENTS_VIRTUAL_MRPT_OBJECT( \ 338 class_name, base, NS, #NS "::" #class_name) 340 #define IMPLEMENTS_VIRTUAL_MRPT_OBJECT(class_name, base, NS) \ 341 INTERNAL_IMPLEMENTS_VIRTUAL_MRPT_OBJECT(class_name, base, NS, #class_name) 362 template <
typename CAST_TO>
365 template <
typename CAST_FROM_PTR>
366 static typename CAST_TO::Ptr
from(
const CAST_FROM_PTR& ptr)
368 return std::dynamic_pointer_cast<CAST_TO>(ptr);
virtual ~CObject()=default
std::shared_ptr< CObject > createObject() const
void registerAllPendingClasses()
Register all pending classes - to be called just before de-serializing an object, for example...
std::unique_ptr< CObject > UniquePtr
Auxiliary structure used for CObject-based RTTI.
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...
Virtual base to provide a compiler-independent RTTI system.
CLASSINIT(const mrpt::rtti::TRuntimeClassId *pNewClass)
std::unique_ptr< const CObject > ConstUniquePtr
static constexpr const mrpt::rtti::TRuntimeClassId * get()
#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 REF &p)
static T * clone(const T &o)
virtual const mrpt::rtti::TRuntimeClassId * GetRuntimeClass() const
Returns information about the class of an object in runtime.
std::function< std::shared_ptr< CObject >void)> ptrCreateObject
Create an object of the related class, or nullptr if it is virtual.
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.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
static const mrpt::rtti::TRuntimeClassId & GetRuntimeClassIdStatic()
static mrpt::rtti::TRuntimeClassId * _GetBaseClass()
static T * clone(const T &o)
mrpt::rtti::CObject::Ptr classFactory(const std::string &className)
Creates an object given by its registered name.
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.
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
static const mrpt::rtti::TRuntimeClassId runtimeClassId
std::vector< const mrpt::rtti::TRuntimeClassId * > getAllRegisteredClasses()
Returns a list with all the classes registered in the system through mrpt::rtti::registerClass.
std::shared_ptr< CObject > Ptr
mrpt::rtti::CObject::Ptr duplicateGetSmartPtr() const
Makes a deep copy of the object and returns a smart pointer to it.