Main MRPT website > C++ reference for MRPT 1.9.9
Classes | Namespaces | Functions
CObject.h File Reference
#include <mrpt/system/memory.h>
#include <mrpt/utils/safe_pointers.h>
#include <mrpt/utils/aligned_allocator.h>
#include <vector>
#include <memory>

Go to the source code of this file.

Classes

struct  mrpt::utils::TRuntimeClassId
 A structure that holds runtime class type information. More...
 
struct  mrpt::utils::IS_CLASS_impl< T >
 
struct  mrpt::utils::CLASSINIT
 Auxiliary structure used for CObject-based RTTI. More...
 
struct  mrpt::utils::is_shared_ptr< T >
 This is useful for checking ::Ptr types. More...
 
struct  mrpt::utils::is_shared_ptr< std::shared_ptr< T > >
 
class  mrpt::utils::CObject
 The virtual base class of all MRPT classes with a unified RTTI system. More...
 
struct  mrpt::ptr_cast< CAST_TO >
 Converts a smart pointer Base::Ptr to Derived::Ptr, in a way compatible with MRPT >=1.5.4 and MRPT 2.x series. More...
 

Namespaces

 mrpt
 This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
 
 mrpt::utils
 Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
 

Functions

void mrpt::utils::registerAllPendingClasses ()
 Register all pending classes - to be called just before de-serializing an object, for example. More...
 

RTTI classes and functions

#define CLASS_ID(T)   mrpt::utils::CLASS_ID_impl<T>()
 Access to runtime class ID for a defined class name. More...
 
#define CLASS_ID_TEMPLATE(class_name, T)   mrpt::utils::CLASS_ID_impl<T>()
 
#define CLASS_ID_NAMESPACE(class_name, namespaceName)    mrpt::utils::CLASS_ID_impl<namespaceName::class_name>()
 
#define IS_CLASS(ptrObj, class_name)    mrpt::utils::IS_CLASS_impl<class_name>::check(ptrObj)
 Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of the given class. More...
 
#define IS_DERIVED(ptrObj, class_name)    ((ptrObj)->GetRuntimeClass()->derivedFrom(CLASS_ID(class_name)))
 Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is an instance of the given class or any of its derived classes. More...
 
#define DEFINE_MRPT_OBJECT(class_name)
 This declaration must be inserted in all CObject classes definition, within the class declaration. More...
 
#define IMPLEMENTS_MRPT_OBJECT(class_name, base, NameSpace)
 This must be inserted in all CObject classes implementation files. More...
 
#define DEFINE_VIRTUAL_MRPT_OBJECT(class_name)
 This declaration must be inserted in virtual CSerializable classes definition: More...
 
#define IMPLEMENTS_VIRTUAL_MRPT_OBJECT(class_name, base_class_name, NameSpace)
 This must be inserted as implementation of some required members for virtual CSerializable classes: More...
 
void mrpt::utils::registerClass (const mrpt::utils::TRuntimeClassId *pNewClass)
 Register a class into the MRPT internal list of "CSerializable" descendents. More...
 
void mrpt::utils::registerClassCustomName (const char *customName, const TRuntimeClassId *pNewClass)
 Mostly for internal use within mrpt sources, to handle exceptional cases with multiple serialization names for backward compatibility (CMultiMetricMaps, CImage,...) More...
 
std::vector< const mrpt::utils::TRuntimeClassId * > mrpt::utils::getAllRegisteredClasses ()
 Returns a list with all the classes registered in the system through mrpt::utils::registerClass. More...
 
std::vector< const TRuntimeClassId * > mrpt::utils::getAllRegisteredClassesChildrenOf (const TRuntimeClassId *parent_id)
 Like getAllRegisteredClasses(), but filters the list to only include children clases of a given base one. More...
 
const TRuntimeClassIdmrpt::utils::findRegisteredClass (const std::string &className)
 Return info about a given class by its name, or nullptr if the class is not registered. More...
 
template<typename T >
constexpr const mrpt::utils::TRuntimeClassIdmrpt::utils::CLASS_ID_impl ()
 

Macro Definition Documentation

◆ CLASS_ID

#define CLASS_ID (   T)    mrpt::utils::CLASS_ID_impl<T>()

Access to runtime class ID for a defined class name.

Definition at line 85 of file CObject.h.

◆ CLASS_ID_NAMESPACE

#define CLASS_ID_NAMESPACE (   class_name,
  namespaceName 
)     mrpt::utils::CLASS_ID_impl<namespaceName::class_name>()

Definition at line 88 of file CObject.h.

◆ CLASS_ID_TEMPLATE

#define CLASS_ID_TEMPLATE (   class_name,
 
)    mrpt::utils::CLASS_ID_impl<T>()

Definition at line 87 of file CObject.h.

◆ DEFINE_MRPT_OBJECT

#define DEFINE_MRPT_OBJECT (   class_name)
Value:
/*! @name RTTI stuff */ \
/*! @{ */ \
protected: \
static const mrpt::utils::TRuntimeClassId* _GetBaseClass(); \
static mrpt::utils::CLASSINIT _init_##class_name; \
static const mrpt::utils::TRuntimeClassId runtimeClassId; \
\
public: \
/*! A typedef for the associated smart pointer */ \
using Ptr = std::shared_ptr<class_name>; \
using ConstPtr = std::shared_ptr<const class_name>; \
static constexpr const char* className = #class_name; \
static const mrpt::utils::TRuntimeClassId& GetRuntimeClassIdStatic(); \
virtual const mrpt::utils::TRuntimeClassId* GetRuntimeClass() \
const override; \
static mrpt::utils::CObject* CreateObject(); \
virtual mrpt::utils::CObject* clone() const override; \
template <typename... Args> \
static Ptr Create(Args&&... args) \
{ \
return mrpt::make_aligned_shared<class_name>( \
std::forward<Args>(args)...); \
} \
/*! @} */ \
public: \
MRPT_MAKE_ALIGNED_OPERATOR_NEW
The virtual base class of all MRPT classes with a unified RTTI system.
Definition: CObject.h:148
Auxiliary structure used for CObject-based RTTI.
Definition: CObject.h:114
A structure that holds runtime class type information.
Definition: CObject.h:32

This declaration must be inserted in all CObject classes definition, within the class declaration.

Definition at line 186 of file CObject.h.

◆ DEFINE_VIRTUAL_MRPT_OBJECT

#define DEFINE_VIRTUAL_MRPT_OBJECT (   class_name)
Value:
/*! @name RTTI stuff */ \
/*! @{ */ \
protected: \
static const mrpt::utils::TRuntimeClassId* _GetBaseClass(); \
static const mrpt::utils::TRuntimeClassId runtimeClassId; \
\
public: \
using Ptr = std::shared_ptr<class_name>; \
using ConstPtr = std::shared_ptr<const class_name>; \
virtual const mrpt::utils::TRuntimeClassId* GetRuntimeClass() \
const override; \
static const mrpt::utils::TRuntimeClassId& GetRuntimeClassIdStatic(); \
friend class mrpt::utils::CStream; \
/*! @} */
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:42

This declaration must be inserted in virtual CSerializable classes definition:

Definition at line 249 of file CObject.h.

◆ IMPLEMENTS_MRPT_OBJECT

#define IMPLEMENTS_MRPT_OBJECT (   class_name,
  base,
  NameSpace 
)
Value:
mrpt::utils::CObject* NameSpace::class_name::CreateObject() \
{ \
return static_cast<mrpt::utils::CObject*>(new NameSpace::class_name); \
} \
const mrpt::utils::TRuntimeClassId* NameSpace::class_name::_GetBaseClass() \
{ \
return CLASS_ID(base); \
} \
NameSpace::class_name::GetRuntimeClassIdStatic() \
{ \
return NameSpace::class_name::runtimeClassId; \
} \
const mrpt::utils::TRuntimeClassId NameSpace::class_name::runtimeClassId = \
{#class_name, NameSpace::class_name::CreateObject, \
&class_name::_GetBaseClass}; \
NameSpace::class_name::GetRuntimeClass() const \
{ \
return CLASS_ID_NAMESPACE(class_name, NameSpace); \
} \
mrpt::utils::CLASSINIT NameSpace::class_name::_init_##class_name( \
CLASS_ID(base)); \
mrpt::utils::CObject* NameSpace::class_name::clone() const \
{ \
return static_cast<mrpt::utils::CObject*>( \
new NameSpace::class_name(*this)); \
}
#define CLASS_ID_NAMESPACE(class_name, namespaceName)
Definition: CObject.h:88
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
Definition: CObject.h:85

This must be inserted in all CObject classes implementation files.

Definition at line 216 of file CObject.h.

◆ IMPLEMENTS_VIRTUAL_MRPT_OBJECT

#define IMPLEMENTS_VIRTUAL_MRPT_OBJECT (   class_name,
  base_class_name,
  NameSpace 
)
Value:
const mrpt::utils::TRuntimeClassId* class_name::_GetBaseClass() \
{ \
return CLASS_ID(base_class_name); \
} \
const mrpt::utils::TRuntimeClassId class_name::runtimeClassId = { \
#class_name, nullptr, &class_name::_GetBaseClass}; \
const mrpt::utils::TRuntimeClassId* class_name::GetRuntimeClass() const \
{ \
return CLASS_ID(class_name); \
} \
const mrpt::utils::TRuntimeClassId& \
NameSpace::class_name::GetRuntimeClassIdStatic() \
{ \
return NameSpace::class_name::runtimeClassId; \
}

This must be inserted as implementation of some required members for virtual CSerializable classes:

Definition at line 268 of file CObject.h.

◆ IS_CLASS

#define IS_CLASS (   ptrObj,
  class_name 
)     mrpt::utils::IS_CLASS_impl<class_name>::check(ptrObj)

Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of the given class.

Definition at line 103 of file CObject.h.

◆ IS_DERIVED

#define IS_DERIVED (   ptrObj,
  class_name 
)     ((ptrObj)->GetRuntimeClass()->derivedFrom(CLASS_ID(class_name)))

Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is an instance of the given class or any of its derived classes.

Definition at line 109 of file CObject.h.




Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST