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...
struct  mrpt::utils::TTypeName< T >
 A template to obtain the type of its argument as a string at compile time. More...
struct  mrpt::utils::TTypeName< std::pair< T1, T2 > >

Namespaces

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

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:.
Conversion of type to string at compile time
#define MRPT_DECLARE_TTYPENAME(_TYPE)
#define MRPT_DECLARE_TTYPENAME_PTR(_TYPE)
#define MRPT_DECLARE_TTYPENAME_CONTAINER(_CONTAINER)
#define MRPT_DECLARE_TTYPENAME_CONTAINER_ASSOC(_CONTAINER)

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.
const TRuntimeClassId
MRPTDLLIMPEXP * 
mrpt::utils::findRegisteredClass (const std::string &className)
 Return info about a given class by its name, or NULL if the class is not registered.
template<typename T , typename C >
bool std::operator== (const stlplus::smart_ptr_base< T, C > &a, const stlplus::smart_ptr_base< T, C > &b)
 This operator enables comparing two smart pointers with "==" to test whether they point to the same object.
template<typename T , typename C >
bool std::operator!= (const stlplus::smart_ptr_base< T, C > &a, const stlplus::smart_ptr_base< T, C > &b)
 This operator enables comparing two smart pointers with "!=" to test whether they don't point to the same object.
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 98 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 102 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(); \
                        static class_name##Ptr Create(); \
                        virtual CSerializable *duplicate() const;
This declaration must be inserted in all CSerializable classes definition, within the class declaration.

Definition at line 294 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 334 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 359 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) { ASSERTMSG_( p->GetRuntimeClass()->derivedFrom(#class_name),format("Wrong typecasting of smart pointers: %s -> %s",p->GetRuntimeClass()->className, #class_name) )  } \
                                explicit class_name##Ptr(const mrpt::utils::CSerializablePtr & p) : base_name##Ptr(p) { ASSERTMSG_( p->GetRuntimeClass()->derivedFrom(#class_name),format("Wrong typecasting of smart pointers: %s -> %s",p->GetRuntimeClass()->className, #class_name) )  } \
                                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 339 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)  \
                                {  ASSERTMSG_( p->GetRuntimeClass()->derivedFrom(#class_name),format("Wrong typecasting of smart pointers: %s -> %s",p->GetRuntimeClass()->className, #class_name) )  } \
                                void setFromPointerDoNotFreeAtDtor(const class_name* p) { \
                                        this->set(const_cast<mrpt::utils::CSerializable*>(reinterpret_cast<const mrpt::utils::CSerializable*>(p))); m_holder->increment(); \
                                } \
                                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 311 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 386 of file CSerializable.h.

#define IMPLEMENTS_SERIALIZABLE ( class_name,
base,
NameSpace   ) 

Value:

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

Definition at line 364 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 397 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 106 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 110 of file CSerializable.h.

#define MRPT_DECLARE_TTYPENAME ( _TYPE   ) 

Value:

template<> struct TTypeName <_TYPE > { \
                                static std::string get() { return std::string(#_TYPE); } };

Definition at line 235 of file CSerializable.h.

#define MRPT_DECLARE_TTYPENAME_CONTAINER ( _CONTAINER   ) 

Value:

template< typename V > \
                        struct TTypeName <_CONTAINER<V> > { \
                                static std::string get() { \
                                        return std::string( #_CONTAINER )+std::string("<")+std::string( TTypeName<V>::get() ) + std::string(">"); \
                                } \
                        };

Definition at line 257 of file CSerializable.h.

#define MRPT_DECLARE_TTYPENAME_CONTAINER_ASSOC ( _CONTAINER   ) 

Value:

template< typename K, typename V > \
                        struct TTypeName <_CONTAINER<K,V> > { \
                                static std::string get() { \
                                        return std::string( #_CONTAINER )+std::string("<")+std::string( TTypeName<K>::get() )+ std::string(",")+std::string( TTypeName<V>::get() )+std::string(">"); \
                                } \
                        };

Definition at line 270 of file CSerializable.h.

#define MRPT_DECLARE_TTYPENAME_PTR ( _TYPE   ) 

Value:

template<> struct TTypeName <_TYPE##Ptr> { \
                        static std::string get() { return TTypeName<_TYPE>::get(); }    };

Definition at line 239 of file CSerializable.h.




Page generated by Doxygen 1.5.7.1 for MRPT 0.7.1 SVN: at Mon Aug 17 23:02:22 EDT 2009