Image Component Library (ICL)
Public Member Functions | List of all members
icl::utils::UncopiedInstance< T > Class Template Reference

Utility class for class instances that are created brand new on copy. More...

#include <UncopiedInstance.h>

Inheritance diagram for icl::utils::UncopiedInstance< T >:

Public Member Functions

 UncopiedInstance (const T &t)
 copy from parent constructor More...
 
 UncopiedInstance ()
 default constructor calls T() More...
 
 UncopiedInstance (const UncopiedInstance &other)
 default copy constructor calls T() More...
 
UncopiedInstanceoperator= (const UncopiedInstance &other)
 assignment operator (does NOT call T::operator=(other)) More...
 

Detailed Description

template<class T>
class icl::utils::UncopiedInstance< T >

Utility class for class instances that are created brand new on copy.

Consider the following problem: You have a class with some mutex'ed interface

class Camera{
float *data;
Mutex mutex;
public:
void lock(){ mutex.lock(); }
void unlock() { mutex.unlock(); }
...
};

As the mutex class is an instance of the Uncopyable interfaces, it cannot be copied. Furthermore, all classes X that have a member of type Mutex are Uncopyable too, unless, A special copy constructor and assignment operator for X is defined. This can be bypassed using the UncopiedInstance interface.
Due to template based inheritance, Uncopied instances can be used as their (templated) child instances. One major drawback is, that the wrapped T instance (wrapped by inheritance) is always constructed using the ()-empty constructor.
The Camera class from above can simply use the default copy constructor and assignment operator if we use an UncopiedInstance<Mutex> instead of the Mutex class itself.

class Camera{
float *data;
UncopiedInstance<Mutex> mutex;
public:
void lock(){ mutex.lock(); }
void unlock() { mutex.unlock(); }
...
};

Constructor & Destructor Documentation

◆ UncopiedInstance() [1/3]

template<class T>
icl::utils::UncopiedInstance< T >::UncopiedInstance ( const T &  t)
inline

copy from parent constructor

◆ UncopiedInstance() [2/3]

template<class T>
icl::utils::UncopiedInstance< T >::UncopiedInstance ( )
inline

default constructor calls T()

◆ UncopiedInstance() [3/3]

template<class T>
icl::utils::UncopiedInstance< T >::UncopiedInstance ( const UncopiedInstance< T > &  other)
inline

default copy constructor calls T()

Member Function Documentation

◆ operator=()

template<class T>
UncopiedInstance& icl::utils::UncopiedInstance< T >::operator= ( const UncopiedInstance< T > &  other)
inline

assignment operator (does NOT call T::operator=(other))


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