MRPT logo

CSerializable.h File Reference

#include <mrpt/utils/utils_defs.h>
#include <mrpt/utils/CStream.h>
#include <mrpt/utils/safe_pointers.h>

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::CLASSINIT
 Auxiliary structure used for CSerializable runtime class ID support. More...
class  mrpt::utils::CSerializable
 The virtual base class which provides a unified interface for all persistent objects in MRPT. More...

Namespaces

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

Defines

#define CLASS_ID(class_name)   static_cast<const mrpt::utils::TRuntimeClassId*>(&class_name::class##class_name)
 Access to runtime class ID for a defined class name.
#define CLASS_ID_NAMESPACE(class_name, namespaceName)   static_cast<const mrpt::utils::TRuntimeClassId*>(&namespaceName::class_name::class##class_name)
 Access to runtime class ID for a defined class name.
#define CLASS_ID_TEMPLATE(class_name, T)   static_cast<const mrpt::utils::TRuntimeClassId*>(& template <class T> class_name<T>::class##class_name)
 Access to runtime class ID for a defined template class name.
#define IS_CLASS(ptrObj, class_name)   ((ptrObj)->GetRuntimeClass()==CLASS_ID(class_name))
 Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of the given class.
#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.
#define DEFINE_SERIALIZABLE(class_name)
 This declaration must be inserted in all CSerializable classes definition, within the class declaration.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_LINKAGE(class_name, _LINKAGE_)
 This declaration must be inserted in all CSerializable classes definition, before the class declaration.
#define DEFINE_SERIALIZABLE_PRE(class_name)   DEFINE_SERIALIZABLE_PRE_CUSTOM_LINKAGE(class_name, MRPTDLLIMPEXP )
 This declaration must be inserted in all CSerializable classes definition, before the class declaration.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
 This declaration must be inserted in all CSerializable classes definition, before the class declaration.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE(class_name, base_name)   DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, MRPTDLLIMPEXP )
 This declaration must be inserted in all CSerializable classes definition, before the class declaration.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
 This must be inserted in all CSerializable classes implementation files:.
#define DEFINE_VIRTUAL_SERIALIZABLE(class_name)
 This declaration must be inserted in virtual CSerializable classes definition:.
#define IMPLEMENTS_VIRTUAL_SERIALIZABLE(class_name, base_class_name, NameSpace)
 This must be inserted as implementation of some required members for virtual CSerializable classes:.

Typedefs

typedef
stlplus::smart_ptr_clone
< CSerializable > 
mrpt::utils::CSerializablePtr
 A smart pointer to a CRenderizable object.
typedef safe_ptr< TRuntimeClassId > mrpt::utils::TRuntimeClassIdPtr
 A wrapper class for a "TRuntimeClassId *", well-defined with respect to copy operators and constructors.

Functions

void MRPTDLLIMPEXP mrpt::utils::registerClass (const mrpt::utils::TRuntimeClassId *pNewClass)
 Register a class into the MRPT internal list of "CSerializable" descendents.
std::vector< const
mrpt::utils::TRuntimeClassId * >
MRPTDLLIMPEXP 
mrpt::utils::getAllRegisteredClasses ()
 Returns a list with all the classes registered in the system through mrpt::utils::registerClass.
Non-streaming serialization functions
std::string MRPTDLLIMPEXP mrpt::utils::ObjectToString (const CSerializable *o)
 Used to pass MRPT objects into a CORBA-like object (strings).
void MRPTDLLIMPEXP mrpt::utils::StringToObject (std::string &str, CSerializablePtr &obj)
 Used to pass CORBA-like objects (strings) into a MRPT object.
void MRPTDLLIMPEXP mrpt::utils::ObjectToOctetVector (const CSerializable *o, vector_byte &out_vector)
 Converts (serializes) a MRPT object into an array of bytes.
void MRPTDLLIMPEXP mrpt::utils::OctetVectorToObject (const vector_byte &in_data, CSerializablePtr &obj)
 Converts back (de-serializes) a sequence of binary data into a MRPT object, without prior information about the object's class.

Variables

class MRPTDLLIMPEXP mrpt::utils::CSerializable


Define Documentation

#define CLASS_ID ( class_name   )     static_cast<const mrpt::utils::TRuntimeClassId*>(&class_name::class##class_name)

#define CLASS_ID_NAMESPACE ( class_name,
namespaceName   )     static_cast<const mrpt::utils::TRuntimeClassId*>(&namespaceName::class_name::class##class_name)

Access to runtime class ID for a defined class name.

Definition at line 91 of file CSerializable.h.

Referenced by mrpt::opengl::CSetOfObjects::getByClass(), and mrpt::opengl::COpenGLViewport::getByClass().

#define CLASS_ID_TEMPLATE ( class_name,
 )     static_cast<const mrpt::utils::TRuntimeClassId*>(& template <class T> class_name<T>::class##class_name)

Access to runtime class ID for a defined template class name.

Definition at line 95 of file CSerializable.h.

#define DEFINE_SERIALIZABLE ( class_name   ) 

Value:

protected: \
                        static  const mrpt::utils::TRuntimeClassId* _GetBaseClass(); \
                        static mrpt::utils::CLASSINIT _init_##class_name;\
                        void  writeToStream(mrpt::utils::CStream &out, int *getVersion) const;\
                        void  readFromStream(mrpt::utils::CStream &in, int version);\
                public: \
                        typedef class_name##Ptr SmartPtr; \
                        static  mrpt::utils::TRuntimeClassId  class##class_name; \
                        static  const mrpt::utils::TRuntimeClassId *classinfo; \
                        virtual const mrpt::utils::TRuntimeClassId* GetRuntimeClass() const; \
                        static  CSerializable* CreateObject(); \
                        virtual CSerializable *duplicate() const;
This declaration must be inserted in all CSerializable classes definition, within the class declaration.

Definition at line 117 of file CSerializable.h.

#define DEFINE_SERIALIZABLE_PRE ( class_name   )     DEFINE_SERIALIZABLE_PRE_CUSTOM_LINKAGE(class_name, MRPTDLLIMPEXP )

This declaration must be inserted in all CSerializable classes definition, before the class declaration.

Definition at line 151 of file CSerializable.h.

#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE ( class_name,
base_name   )     DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, MRPTDLLIMPEXP )

This declaration must be inserted in all CSerializable classes definition, before the class declaration.

Definition at line 176 of file CSerializable.h.

#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE ( class_name,
base_name,
_LINKAGE_   ) 

Value:

class class_name; \
                        struct _LINKAGE_ class_name##Ptr : public base_name##Ptr \
                        { \
                                class_name##Ptr() : base_name##Ptr(static_cast<base_name*>(NULL)) { } \
                                explicit class_name##Ptr(class_name* p) : base_name##Ptr( reinterpret_cast<base_name*>(p) ) { } \
                                explicit class_name##Ptr(const base_name##Ptr & p) : base_name##Ptr(p) { } \
                                explicit class_name##Ptr(const mrpt::utils::CSerializablePtr & p) : base_name##Ptr(p) { } \
                                class_name * pointer() { return reinterpret_cast<class_name*>(base_name##Ptr::pointer()); } \
                                const class_name * pointer() const { return reinterpret_cast<const class_name*>(base_name##Ptr::pointer()); } \
                                class_name* operator ->(void) { return reinterpret_cast<class_name*>( base_name##Ptr::operator ->() ); } \
                                const class_name* operator ->(void) const { return reinterpret_cast<const class_name*>( base_name##Ptr::operator ->() ); } \
                                class_name& operator *(void) { return *reinterpret_cast<class_name*>( base_name##Ptr::operator ->() ); } \
                                const class_name& operator *(void) const { return *reinterpret_cast<const class_name*>( base_name##Ptr::operator ->() ); } \
                        }; \
                        _LINKAGE_ ::mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj);
This declaration must be inserted in all CSerializable classes definition, before the class declaration.

Definition at line 156 of file CSerializable.h.

#define DEFINE_SERIALIZABLE_PRE_CUSTOM_LINKAGE ( class_name,
_LINKAGE_   ) 

Value:

class class_name; \
                        struct _LINKAGE_ class_name##Ptr : public mrpt::utils::CSerializablePtr \
                        { \
                                class_name##Ptr() : mrpt::utils::CSerializablePtr(static_cast<mrpt::utils::CSerializable*>(NULL)) { } \
                                explicit class_name##Ptr(class_name* p) : mrpt::utils::CSerializablePtr( reinterpret_cast<mrpt::utils::CSerializable*>(p) ) { } \
                                explicit class_name##Ptr(const mrpt::utils::CSerializablePtr & p) : mrpt::utils::CSerializablePtr(p) { } \
                                class_name * pointer() { return reinterpret_cast<class_name*>(mrpt::utils::CSerializablePtr::pointer()); } \
                                const class_name * pointer() const { return reinterpret_cast<const class_name*>(mrpt::utils::CSerializablePtr::pointer()); } \
                                class_name* operator ->(void) { return reinterpret_cast<class_name*>( mrpt::utils::CSerializablePtr::operator ->() ); } \
                                const class_name* operator ->(void) const { return reinterpret_cast<const class_name*>( mrpt::utils::CSerializablePtr::operator ->() ); } \
                                class_name& operator *(void) { return *reinterpret_cast<class_name*>( mrpt::utils::CSerializablePtr::operator ->() ); } \
                                const class_name& operator *(void) const { return *reinterpret_cast<const class_name*>( mrpt::utils::CSerializablePtr::operator ->() ); } \
                        };\
                        _LINKAGE_ ::mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj);
This declaration must be inserted in all CSerializable classes definition, before the class declaration.

Definition at line 133 of file CSerializable.h.

#define DEFINE_VIRTUAL_SERIALIZABLE ( class_name   ) 

Value:

protected: \
                        static const mrpt::utils::TRuntimeClassId* _GetBaseClass(); \
                public: \
                        static const mrpt::utils::TRuntimeClassId class##class_name; \
                        virtual const mrpt::utils::TRuntimeClassId* GetRuntimeClass() const; \
                        friend class mrpt::utils::CStream; \
This declaration must be inserted in virtual CSerializable classes definition:.

Definition at line 218 of file CSerializable.h.

#define IMPLEMENTS_SERIALIZABLE ( class_name,
base,
NameSpace   ) 

Value:

mrpt::utils::CSerializable* class_name::CreateObject() \
                                { return static_cast<mrpt::utils::CSerializable*>( new class_name ); } \
                        const mrpt::utils::TRuntimeClassId* class_name::_GetBaseClass() \
                                { return CLASS_ID(base); } \
                        mrpt::utils::TRuntimeClassId class_name::class##class_name = { \
                                #class_name, sizeof(class class_name), class_name::CreateObject, \
                                        &class_name::_GetBaseClass }; \
                        const mrpt::utils::TRuntimeClassId *class_name::classinfo = & class_name::class##class_name; \
                        const mrpt::utils::TRuntimeClassId* class_name::GetRuntimeClass() const \
                                { return CLASS_ID(class_name); } \
                        mrpt::utils::CLASSINIT class_name::_init_##class_name(CLASS_ID(class_name)); \
                        mrpt::utils::CStream& NameSpace::operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj) \
                        { pObj = class_name##Ptr( in.ReadObject() ); return in; } \
                        mrpt::utils::CSerializable * class_name::duplicate() const \
                        { return static_cast<mrpt::utils::CSerializable*>( new class_name(*this) ); }
This must be inserted in all CSerializable classes implementation files:.

Definition at line 181 of file CSerializable.h.

#define IMPLEMENTS_VIRTUAL_SERIALIZABLE ( 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::class##class_name = { \
                                #class_name, sizeof(class class_name), NULL, \
                                        &class_name::_GetBaseClass }; \
                        const mrpt::utils::TRuntimeClassId* class_name::GetRuntimeClass() const \
                                { return CLASS_ID(class_name); } \
                        mrpt::utils::CStream& NameSpace::operator>>(mrpt::utils::CStream& in, class_name##Ptr &pObj) \
                        { pObj = class_name##Ptr( in.ReadObject() ); return in; }
This must be inserted as implementation of some required members for virtual CSerializable classes:.

Definition at line 229 of file CSerializable.h.

#define IS_CLASS ( ptrObj,
class_name   )     ((ptrObj)->GetRuntimeClass()==CLASS_ID(class_name))

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

Definition at line 99 of file CSerializable.h.

#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 103 of file CSerializable.h.




Page generated by Doxygen 1.5.9 for MRPT 0.6.5 SVN:exported at Thu May 21 04:14:55 UTC 2009