Home
Install
Use
Develop
Support
News
Credits
hosted by
|
11 #ifndef __ReferenceTo_h
12 #define __ReferenceTo_h
16 #include "ReferenceAble.h"
25 template< class Type, bool active = true> class To {
33 operator bool () const;
57 operator Type* () const { return get(); }
66 const Type* ptr () const;
72 std::string name () const;
77 void hook ( const Able*);
80 void unhook ( bool auto_delete = true);
88 template< class Type, bool active>
91 DEBUG( "Reference::To<"+name()+ ">::unhook handle=" << the_handle << " auto_delete=" << auto_delete);
96 Able::Handle* temp = the_handle;
101 temp->decrement (active, auto_delete);
104 template< class Type, bool active>
107 DEBUG( "Reference::To<"+name()+ ">::handle Able*="<< pointer);
112 the_handle = pointer->__reference (active);
115 template< class Type, bool active>
121 return typeid(Type).name();
125 template< class Type, bool active>
128 DEBUG( "Reference::To<"+name()+ ">::To (Type*="<< ( void*)ref_pointer << ")");
134 template< class Type, bool active>
137 DEBUG( "Reference::To<"+name()+ ">::~To");
142 template< class Type, bool active>
145 DEBUG( "Reference::To<"+name()+ ">::operator !");
147 return !the_handle || the_handle->pointer == 0;
150 template< class Type, bool active>
153 DEBUG( "Reference::To<"+name()+ ">::operator bool");
155 return the_handle && the_handle->pointer;
159 template< class Type, bool active>
162 DEBUG( "Reference::To<"+name()+ ">::To (To<Type>)");
166 Able::Handle::copy (the_handle, another_reference.the_handle, active);
171 template< class Type, bool active>
175 DEBUG( "Reference::To<"+name()+ ">::operator = (To<Type>)");
177 if (the_handle == oref.the_handle)
183 Able::Handle::copy (the_handle, oref.the_handle, active);
189 template< class Type, bool active>
193 DEBUG( "Reference::To<"+name()+ ">::operator = (Type*=" << ( void*)ref_pointer << ")");
195 if (the_handle && the_handle->pointer == ref_pointer)
205 template< class Type, bool active>
208 DEBUG( "Reference::To<"+name()+ ">::get");
210 if (!the_handle || the_handle->pointer == 0)
211 throw Error (InvalidPointer, "Reference::To<"+name()+ ">::get");
213 return reinterpret_cast<Type* >( the_handle->pointer );
217 template< class Type, bool active>
220 DEBUG( "Reference::To<"+name()+ ">::release");
222 if (!the_handle || the_handle->pointer == 0)
223 throw Error (InvalidPointer, "Reference::To<"+name()+ ">::release");
225 Type* copy = reinterpret_cast<Type* >( the_handle->pointer );
233 template< class Type, bool active>
237 return reinterpret_cast<const Type* >( the_handle->pointer );
243 template< class Type, bool active>
246 if (the_handle && the_handle->pointer)
247 return reinterpret_cast<Type* >( the_handle->pointer );
252 template< class Type, bool active>
255 DEBUG( "swap (Reference::To<Type>, ditto)");
257 Type* ref1_ptr = ref1. release();
258 Type* ref2_ptr = ref2. release();
265 template< class Type1, bool active1, class Type2, bool active2>
269 DEBUG( "operator == (Reference::To<Type>&, Reference::To<Type2>&)");
271 return ref1. ptr() == ref2. ptr();
275 template< class Type1, bool active1, class Type2, bool active2>
279 DEBUG( "operator != (Reference::To<Type>&, Reference::To<Type2>&)");
281 return ref1. ptr() != ref2. ptr();
286 template< class Type, bool active, class Type2>
289 DEBUG( "operator == (Reference::To<Type>&, Type*)");
291 return ref. ptr() == instance;
295 template< class Type, bool active, class Type2>
298 DEBUG( "operator == (T2*, Reference::To<T1>&)");
300 return ref. ptr() == instance;
303 template< typename C, typename P, bool A>
306 return dynamic_cast<C* > (p. ptr());
309 template< typename P, bool A>
312 return const_cast<P* > (p. ptr());
315 #endif // #ifndef __ReferenceTo_h
bool operator!() const Returns true if reference is null. Definition: ReferenceTo.h:143
Contains two basic classes that simplify dynamic memory management. Definition: HeapTracked.h:17
A convenient exception handling class. Definition: Error.h:54
To(Type *ptr=0) Default constructor. Definition: ReferenceTo.h:126
Type * release() Return the pointer and unhook without deleting the object. Definition: ReferenceTo.h:218
Type * get() const Return the pointer. Definition: ReferenceTo.h:206
Template class manages Reference::Able objects. Definition: Reference.h:74
std::string name() const Return the name of the object, as returned by typeid. Definition: ReferenceTo.h:116
~To() Destructor. Definition: ReferenceTo.h:135
Manages Reference::To references to the instance. Definition: ReferenceAble.h:40
Definition: ReferenceAble.h:86
const Type * ptr() const Return pointer without testing for validity. Definition: ReferenceTo.h:234
Type * operator->() const Member dereferencing operator. Definition: ReferenceTo.h:64
To & operator=(const To &) Assignment operator. Definition: ReferenceTo.h:173
Type & operator*() const Object dereferencing operator. Definition: ReferenceTo.h:61
Generated using doxygen 1.8.17
|