Image Component Library (ICL)
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
icl::utils::ShallowCopyable< Impl, DelOp > Class Template Reference

Interface class for cheap copyable classes using a smart ptr. More...

#include <ShallowCopyable.h>

Public Types

typedef ShallowCopyable< Impl, DelOp > ParentSC
 

Public Member Functions

bool isNull () const
 returns wheter the objects implementation holds a null pointer More...
 

Protected Member Functions

 ShallowCopyable (Impl *t=0)
 create a the implementation with a given T* value More...
 

Protected Attributes

SmartPtrBase< Impl, DelOp > impl
 shared pointer for the classes implementation More...
 

Detailed Description

template<class Impl, class DelOp = PointerDelOp>
class icl::utils::ShallowCopyable< Impl, DelOp >

Interface class for cheap copyable classes using a smart ptr.

To provide a class interface for cheap-copy enabled objects, the ShallowCopyable class template can be used. Each inherited class of ShallowCopyable<T> can use a T* for storing its data. This pointer is then shared by shallow copied intances of that class using an instance of the ICL's SmartPtr class.
See the following example for more details

#include <stdio.h>
using namespace icl::utils;
// forward declaration of the implementation class
// this class can be implemented in the ".cpp"-file
class QuadrupleImpl;
// Because the underlying Implementation class QuadrupleImpl is
// defined as a forward declaration, we need a special delete-op
// class. The concrete implementation of the delete func may
// at first be implemented, when the class is defined (in the cpp
// file
class QuadrupleImplDelOp {
static void delete_func( QuadrupleImpl* impl);
};
// A demo class holding 4 shared integers by inheriting the
// ShallowCopyable template class interface
class Quadruple : public ShallowCopyable<QuadrupleImpl,QuadrupleImplDelOp>{
public:
Quadruple(int a,int b, int c, int d);
int &a();
int &b();
int &c();
int &d();
};
// *******************************************************************
// ******* The following code could be put into the ".cpp"-file ******
// *******************************************************************
// the implementation of the demo class (just the data in this case)
struct QuadrupleImpl{
int data[4];
};
// now, where the QuadrupleImpl class is defined, we can define the
// delete op classes delete_func
void QuadrupleImplDelOp::delete_func( QuadrupleImpl* impl){
}
Quadruple::Quadruple(int a, int b, int c, int d) : ShallowCopyable<QuadrupleImpl,QuadrupleImplDelOp>(new QuadrupleImpl){
impl->data[0] = a;
impl->data[1] = b;
impl->data[2] = c;
impl->data[3] = d;
};
int &Quadruple::a(){
return impl->data[0];
}
int &Quadruple::b(){
return impl->data[1];
}
int &Quadruple::c(){
return impl->data[2];
}
int &Quadruple::d(){
return impl->data[3];
}
int main(){
// create an instance with given values
Quadruple q1(1,2,3,4);
// create a shared instance
Quadruple q2 = q1;
// assign a value to qt
q1.a() = 5;
// see that also q2 has also been changed
printf("q2.a = %d \n",q2.a());
return 0;
}

Member Typedef Documentation

◆ ParentSC

template<class Impl, class DelOp = PointerDelOp>
typedef ShallowCopyable<Impl,DelOp> icl::utils::ShallowCopyable< Impl, DelOp >::ParentSC

Constructor & Destructor Documentation

◆ ShallowCopyable()

template<class Impl, class DelOp = PointerDelOp>
icl::utils::ShallowCopyable< Impl, DelOp >::ShallowCopyable ( Impl *  t = 0)
inlineprotected

create a the implementation with a given T* value

Member Function Documentation

◆ isNull()

template<class Impl, class DelOp = PointerDelOp>
bool icl::utils::ShallowCopyable< Impl, DelOp >::isNull ( ) const
inline

returns wheter the objects implementation holds a null pointer

Member Data Documentation

◆ impl

template<class Impl, class DelOp = PointerDelOp>
SmartPtrBase<Impl,DelOp> icl::utils::ShallowCopyable< Impl, DelOp >::impl
protected

shared pointer for the classes implementation


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