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>
class QuadrupleImpl;
class QuadrupleImplDelOp {
static void delete_func( QuadrupleImpl*
impl);
};
class Quadruple :
public ShallowCopyable<QuadrupleImpl,QuadrupleImplDelOp>{
public:
Quadruple(int a,int b, int c, int d);
int &a();
int &b();
int &c();
int &d();
};
struct QuadrupleImpl{
};
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(){
Quadruple q1(1,2,3,4);
Quadruple q2 = q1;
q1.a() = 5;
printf("q2.a = %d \n",q2.a());
return 0;
}