TF++, Miscellaneous classes and modules in C++:
|
template #tfxx::THandle<class TObj>#: More...
#include <handle.h>
Public Types | |
typedef X | Tmutableobject |
typedef const X | Tobject |
typedef ConstHandle< Tobject > | Tcontainer |
typedef Tcontainer | Tcoc |
typedef Tcoc | Tcontainer_of_const |
typedef const Tobject * | Tpointer |
typedef const Tobject & | Treference |
Public Member Functions | |
ConstHandle (Treference p) | |
constructor #tfxx::THandle<class X>::THandle#: More... | |
ConstHandle (Tmutableobject *p) | |
ConstHandle (const ConstHandle &h) | |
constructor #tfxx::THandle<class X>::THandle#: More... | |
~ConstHandle () | |
desctructor #tfxx::THandle<class X>::~THandle# book-keeping destructor More... | |
Tpointer | operator-> () const |
operator #tfxx::THandle<class X>::operator->()# More... | |
Treference | operator* () const |
operator #tfxx::THandle<class X>::operator*()# More... | |
ConstHandle & | operator= (const ConstHandle &h) |
operator #tfxx::THandle<class X>::operator=()# book-keeping asignment operator More... | |
Protected Member Functions | |
Tmutableobject * | pointer () const |
expose the pointer to derived classes More... | |
Tmutableobject & | reference () const |
expose the object to derived classes More... | |
Private Attributes | |
Tmutableobject * | Mrep |
internal pointer to the handled object More... | |
int * | Mpcount |
usage counter More... | |
template #tfxx::THandle<class TObj>#:
THandle is a class template published by B. Stroustrup in Chapter 25.7 of "The C++ programming Language" (3rd edition). This is a slightly modified version.
Example: To create a handle #hs# to a string #s# and then output the string value you would code:
#THandle<string> hs(new string(s)); cout << *hs << endl;#
Thus the handle always represents a kind of pointer to your string. You may copy and pass this pointer as you like. And all these copies will allocated just memory for that pointer and any modification applied to the string will be accessible through every of these handles. However if the last handle is removed during program execution it will also remove the string representation from the memory. This is an convenient way to pass large objects without worrying about memory usage and management.
It is not possible to create an empty handle - that wouldn't make any sense. You always have to provide another handle to copy from or an element to be handled.
#) template providing a handle to an object of any type