Image Component Library (ICL)
|
Utility class for class instances that are created brand new on copy. More...
#include <UncopiedInstance.h>
Public Member Functions | |
UncopiedInstance (const T &t) | |
copy from parent constructor | |
UncopiedInstance () | |
default constructor calls T() | |
UncopiedInstance (const UncopiedInstance &other) | |
default copy constructor calls T() | |
UncopiedInstance & | operator= (const UncopiedInstance &other) |
assignment operator (does NOT call T::operator=(other)) |
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(); } ... };
icl::utils::UncopiedInstance< T >::UncopiedInstance | ( | const T & | t | ) | [inline] |
copy from parent constructor
icl::utils::UncopiedInstance< T >::UncopiedInstance | ( | ) | [inline] |
default constructor calls T()
icl::utils::UncopiedInstance< T >::UncopiedInstance | ( | const UncopiedInstance< T > & | other | ) | [inline] |
default copy constructor calls T()
UncopiedInstance& icl::utils::UncopiedInstance< T >::operator= | ( | const UncopiedInstance< T > & | other | ) | [inline] |
assignment operator (does NOT call T::operator=(other))