#include <CTBgrab.hxx>
Public Methods | |
void | Construct (T *p_dst, T &src) const |
void | Destruct (T &dst, T *p_src) const |
void | Move (T *p_dst, T *p_src) const |
void | Swap (T &v1, T &v2) const |
void | operator() (T &dst, T &src) const |
In some cases an object is copied just before it becomes obsolete or is destroyed. For heavy objects it is in these cases often substantially faster to use the grab paradigm rather than a simple copy.
In templatized classes one faces the problem to use depending on the type of the object either the grab or the copy approach.
The classes CTBgrab
and a helper class CTBgrabable
provide a function object interface for such a `grab or copy' functionality:
CTBgrab
provides the interface: Construct()
does a placement `grab or copy' construct Destruct()
saves the old value and does a placement destruct Move()
is the combination of Construct()
and Destruct()
Swap()
exchanges the contents of its arguments using `grab or copy'. operator()()
does a `grab or copy' Construct()
, Destruct()
and Move()
methods use placement contructors and destructors for `raw memory' manipulations. This is usually only used in the implemenation of container classes or the allocators used by container classes.
CTBgrab
uses copy semantics and provides the default for all simple classes. CTBgrabable
has the same interface as CTBgrab
, its implementation uses grab semantics and expects a grab constructor and a Grab()
method to exists. T
one has to overwrite the definition of CTBgrab<T>
by providing a specialization of CTBgrab
. If T
has a grab constructor and a Grab()
method this can simply be done by deriving a specialization of CTBgrab
from CTBgrabable
like class foo { public: foo(foo& rhs, bool b_grab); foo* Grab(); ... }; class CTBgrab<foo> : public CTBgrabable<foo> {};
Definition at line 17 of file CTBgrab.hxx.
|
Placement copy construct an object at p_dst with src.
Definition at line 76 of file CTBgrab.icc. Referenced by CTBrawBuffer::GrabConstruct(), and CTBrawBuffer::GrabConstructRange().
|
|
Copy object at p_src to dst, placement destruct object at p_src.
Definition at line 86 of file CTBgrab.icc. Referenced by CTBrawBuffer::GrabDestruct().
|
|
Move an object from p_src to p_dst. Placement copy construct an object at p_dst with p_src, than do a placement destruct at p_src. Definition at line 101 of file CTBgrab.icc. |
|
Exchange contents of v1 and v2.
Definition at line 112 of file CTBgrab.icc. Referenced by CTBswap(), and CTBsortQ::operator()().
|
|
Copy src to dst.
Definition at line 124 of file CTBgrab.icc. |