Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions
icl::utils::UncopiedInstance< T > Class Template Reference

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

#include <UncopiedInstance.h>

List of all members.

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()
UncopiedInstanceoperator= (const UncopiedInstance &other)
 assignment operator (does NOT call T::operator=(other))

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

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

copy from parent constructor

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

default constructor calls T()

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

default copy constructor calls T()


Member Function Documentation

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines