This class provides ref-counting and copy-on-write for ArrayData's. More...
#include <Image/ArrayData.H>
Public Member Functions | |
ArrayHandle () | |
Default construct with an empty array (i.e. 0-by-0). | |
ArrayHandle (const ArrayData< T > *p) throw () | |
Construct with a new ArrayData, which the ArrayHandle now owns. | |
ArrayHandle (const ArrayData< T > *p, const MemoryPolicy mp, const int dev) throw () | |
Construct with a new ArrayData, which the ArrayHandle now owns. | |
ArrayHandle (const ArrayHandle &r) throw () | |
Copy construct; no deep-copy is incurred, just bumps the ref-count. | |
~ArrayHandle () throw () | |
Destruct; delete's the ArrayData<T> if its ref count goes to zero. | |
void | swap (ArrayHandle< T > &other) throw () |
Swap contents with another ArrayHandle. | |
ArrayHandle & | operator= (const ArrayHandle &r) throw () |
Assignment; no deep-copy is incurred, just bumps the ref-count. | |
const ArrayData< T > & | get () const throw () |
Get a read-only reference to the ArrayData object. | |
ArrayData< T > & | uniq (const MemoryPolicy mp, const int dev) |
Get a unique read-write reference to the ArrayData object. | |
ArrayData< T > & | uniq () |
Get a unique read-write reference to the ArrayData object. | |
bool | isShared () const throw () |
See if the ArrayData object is shared (i.e. ref-count > 1). | |
bool | hasSameData (const ArrayHandle< T > &b) const throw () |
For testing/debugging only. | |
int | refCount () const throw () |
For testing/debugging only. |
This class provides ref-counting and copy-on-write for ArrayData's.
NOTE: Most clients will not need to use ArrayHandle<T> directly, but can rather use Image<T>, which wraps and expands the ArrayHandle interface. Nevertheless, these notes may be of interest because the ref-counting and copy-on-write semantics that ArrayHandle<T> offers are transferred through to Image<T>.
As long as clients access ArrayData<T> through an ArrayHandle<T>, the proper copy-on-write semantics are guaranteed. This is by virtue of the fact that the only way to extract a non-const ArrayData<T>& from an ArrayHandle<T> is to call uniq(), which in turn checks to see if the ArrayData is shared (i.e. ref count > 1). If it is shared, then that ArrayData is clone()'d before returning a reference to it.
The only caveat: you should not store non-const references to an ArrayData or to the elements of an ArrayData object for "long" periods of time. In this case, "long" means "longer than you are sure you have a unique reference", which in practice means "you can keep such references up until a new copy of the ArrayHandle<T> is made". This goes along with sensible coding practices anyway; a typical usage pattern would be:
Definition at line 326 of file ArrayData.H.
ArrayHandle< T >::ArrayHandle | ( | ) | [inline] |
Default construct with an empty array (i.e. 0-by-0).
Definition at line 907 of file ArrayData.H.
ArrayHandle< T >::ArrayHandle | ( | const ArrayData< T > * | p | ) | throw () [inline, explicit] |
Construct with a new ArrayData, which the ArrayHandle now owns.
Definition at line 915 of file ArrayData.H.
ArrayHandle< T >::ArrayHandle | ( | const ArrayData< T > * | p, | |
const MemoryPolicy | mp, | |||
const int | dev | |||
) | throw () [inline, explicit] |
Construct with a new ArrayData, which the ArrayHandle now owns.
Definition at line 925 of file ArrayData.H.
ArrayHandle< T >::ArrayHandle | ( | const ArrayHandle< T > & | r | ) | throw () [inline] |
Copy construct; no deep-copy is incurred, just bumps the ref-count.
Definition at line 936 of file ArrayData.H.
ArrayHandle< T >::~ArrayHandle | ( | ) | throw () [inline] |
Destruct; delete's the ArrayData<T> if its ref count goes to zero.
Definition at line 944 of file ArrayData.H.
const ArrayData< T > & ArrayHandle< T >::get | ( | ) | const throw () [inline] |
Get a read-only reference to the ArrayData object.
This is a "cheap" operation, since the ArrayData will never be copied in this operation.
Definition at line 967 of file ArrayData.H.
bool ArrayHandle< T >::hasSameData | ( | const ArrayHandle< T > & | b | ) | const throw () [inline] |
For testing/debugging only.
See if we are pointing to the same ArrayData<T> as is the other ArrayHandle<T>.
Definition at line 1003 of file ArrayData.H.
bool ArrayHandle< T >::isShared | ( | ) | const throw () [inline] |
See if the ArrayData object is shared (i.e. ref-count > 1).
Definition at line 998 of file ArrayData.H.
ArrayHandle< T > & ArrayHandle< T >::operator= | ( | const ArrayHandle< T > & | r | ) | throw () [inline] |
Assignment; no deep-copy is incurred, just bumps the ref-count.
Definition at line 960 of file ArrayData.H.
int ArrayHandle< T >::refCount | ( | ) | const throw () [inline] |
For testing/debugging only.
Returns the current reference count of the our ArrayData<T>.
Definition at line 1008 of file ArrayData.H.
void ArrayHandle< T >::swap | ( | ArrayHandle< T > & | other | ) | throw () [inline] |
Swap contents with another ArrayHandle.
Definition at line 951 of file ArrayData.H.
Referenced by TCPmessage::freeMem(), TCPmessage::operator=(), and ArrayHandle< T >::uniq().
ArrayData< T > & ArrayHandle< T >::uniq | ( | ) | [inline] |
Get a unique read-write reference to the ArrayData object.
This is a potentially "expensive" operation, since in order to get a unique ArrayData object, the current one may have to be clone()'d if it is shared (i.e. ref-count > 1).
Definition at line 985 of file ArrayData.H.
References ArrayHandle< T >::swap().
ArrayData< T > & ArrayHandle< T >::uniq | ( | const MemoryPolicy | mp, | |
const int | dev | |||
) | [inline] |
Get a unique read-write reference to the ArrayData object.
This is a potentially "expensive" operation, since in order to get a unique ArrayData object, the current one may have to be clone()'d if it is shared (i.e. ref-count > 1).
Definition at line 972 of file ArrayData.H.
References ArrayHandle< T >::swap().
Referenced by VideoFrame::fromStream(), VideoFrame::getFlippedHoriz(), VideoFrame::makeBobDeinterlaced(), MgzDecoder::readFrame(), and MgzJDecoder::readFrame().