Class CObject

Class Documentation

class CObject

Virtual base to provide a compiler-independent RTTI system.

Each class named Foo will have associated smart pointer types:

  • Foo::Ptr => std::shared_ptr<Foo> (the most commonly-used one)

  • Foo::ConstPtr => std::shared_ptr<const Foo>

  • Foo::UniquePtr => std::unique_ptr<Foo>

  • Foo::ConstUniquePtr => std::unique_ptr<const Foo>

It is recommended to use MRPT-defined std::make_shared<> instead of std::make_shared<> to create objects, to avoid memory alignment problems caused by classes containing Eigen vectors or matrices. Example:

Foo::Ptr o = std::make_shared<Foo>();
Or using the shorter auxiliary static method ::Create() for conciseness or to keep compatibility with MRPT 1.5.* code bases:
Foo::Ptr o = Foo::Create();
If a special memory allocator is needed, use Foo::CreateAlloc(alloc,...);.

RTTI classes and functions for polymorphic hierarchies

inline mrpt::rtti::CObject::Ptr duplicateGetSmartPtr() const

Makes a deep copy of the object and returns a smart pointer to it

Public Types

using Ptr = std::shared_ptr<CObject>
using ConstPtr = std::shared_ptr<const CObject>
using UniquePtr = std::unique_ptr<CObject>
using ConstUniquePtr = std::unique_ptr<const CObject>

Public Functions

inline virtual const mrpt::rtti::TRuntimeClassId *GetRuntimeClass() const

Returns information about the class of an object in runtime.

virtual CObject *clone() const = 0

Returns a deep copy (clone) of the object, indepently of its class.

virtual ~CObject() = default

Public Static Functions

static const mrpt::rtti::TRuntimeClassId &GetRuntimeClassIdStatic()

Protected Static Functions

static mrpt::rtti::TRuntimeClassId *_GetBaseClass()

Protected Static Attributes

static constexpr mrpt::rtti::TRuntimeClassId runtimeClassId = {"CObject", nullptr, nullptr}