Cortex  10.0.0-a4
Public Types | Public Member Functions | Protected Types | Protected Attributes | List of all members
IECore::ClassData< ClassTypeT, DataTypeT, DataDeletePolicyT > Class Template Reference

#include <ClassData.h>

Public Types

typedef ClassTypeT ClassType
 
typedef DataTypeT DataType
 
typedef DataDeletePolicyT DataDeletePolicy
 

Public Member Functions

virtual ~ClassData ()
 Exercises DataDeletePolicy on all held data.
 
DataType & create (const ClassType *classOwner)
 Create some uninitialized data for the given class.
 
DataType & create (const ClassType *classOwner, const DataType &d)
 Create some data with initial value as specified for the given class.
 
const DataType & operator[] (const ClassType *classOwner) const
 
DataType & operator[] (const ClassType *classOwner)
 
void erase (const ClassType *classOwner)
 

Protected Types

typedef std::map< const ClassType *, DataType > ClassDataMap
 

Protected Attributes

ClassDataMap m_classDataMap
 

Detailed Description

template<typename ClassTypeT, typename DataTypeT, typename DataDeletePolicyT = NullDeleter<DataTypeT>>
class IECore::ClassData< ClassTypeT, DataTypeT, DataDeletePolicyT >

A simple class to allow, for example, extra data to be added to a class for use in cases where simply adding member data would break the library's binary compatibility. Template with the type of the class that data is being added to, the type of the data being added, and policy for deleting that data when the class is destructed. The latter allows use of dynamically-allocated data and arrays.

It the responsibility of the client of this class to implement all creation, deletion, and copy semantics.

Example, which effectively adds an extra member of type "int" to class "A" :

// In file A.h :
class A
{
int &extraMember();
};
// In file A.cpp:
#include "A.h"
#include "IECore/ClassData.h"
static IECore::ClassData< A, int > g_classData;
A::A()
{
g_classData.create( this, 4 );
}
A::~A()
{
g_classData.erase( this );
}
int &A::extraMember()
{
return g_classData[ this ];
}

Member Function Documentation

template<typename ClassTypeT, typename DataTypeT, typename DataDeletePolicyT = NullDeleter<DataTypeT>>
void IECore::ClassData< ClassTypeT, DataTypeT, DataDeletePolicyT >::erase ( const ClassType *  classOwner)

Exercise DataDeletePolicy on the classOwner's data, and remove it. If the data has not yet been created the behaviour is undefined.

template<typename ClassTypeT, typename DataTypeT, typename DataDeletePolicyT = NullDeleter<DataTypeT>>
const DataType& IECore::ClassData< ClassTypeT, DataTypeT, DataDeletePolicyT >::operator[] ( const ClassType *  classOwner) const

Const access to the data associated with the class. If the data has not yet been created the behaviour is undefined.

template<typename ClassTypeT, typename DataTypeT, typename DataDeletePolicyT = NullDeleter<DataTypeT>>
DataType& IECore::ClassData< ClassTypeT, DataTypeT, DataDeletePolicyT >::operator[] ( const ClassType *  classOwner)

Read/write access to the data associated with the class. If the data has not yet been created the behaviour is undefined.


The documentation for this class was generated from the following file: