Home
Install
Use
Develop
Support
News
Credits
hosted by
|
11#ifndef __psrchive_util_units_ReferenceTo_h
12#define __psrchive_util_units_ReferenceTo_h
16#include "ReferenceAble.h"
25 template< class Type, bool active = true> class To {
30 constexpr To () = default;
64 operator Type* () const { return get(); }
70 operator bool () const;
82 const Type* ptr () const;
93 void hook ( const Able*);
96 void unhook ( bool auto_delete = true);
104template< class Type, bool active>
107 DEBUG( "Reference::To<"+ name()+ ">::operator ==");
111template< class Type, bool active>
114 DEBUG( "Reference::To<"+ name()+ ">::operator !=");
118template< class Type, bool active>
122 return !the_handle || the_handle->pointer == nullptr;
124 return the_handle && the_handle->pointer == ptr;
127template< class Type, bool active>
128void Reference::To<Type,active>::unhook ( bool auto_delete)
130 DEBUG( "Reference::To<"+name()+ ">::unhook handle=" << the_handle << " auto_delete=" << auto_delete);
143template< class Type, bool active>
144void Reference::To<Type,active>::hook ( const Able* pointer)
146 DEBUG( "Reference::To<"+name()+ ">::handle Able*="<< pointer);
151 the_handle = pointer->__reference (active);
154template< class Type, bool active>
160 return typeid(Type). name();
164template< class Type, bool active>
167 DEBUG( "Reference::To<"+ name()+ ">::To (Type*="<< ( void*)ref_pointer << ")");
173template< class Type, bool active>
176 DEBUG( "Reference::To<"+ name()+ ">::~To");
181template< class Type, bool active>
184 DEBUG( "Reference::To<"+ name()+ ">::operator !");
186 return !the_handle || the_handle->pointer == 0;
189template< class Type, bool active>
192 DEBUG( "Reference::To<"+ name()+ ">::operator bool");
194 return the_handle && the_handle->pointer;
198template< class Type, bool active>
201 DEBUG( "Reference::To<"+ name()+ ">::To (To<Type>)");
210template< class Type, bool active>
214 DEBUG( "Reference::To<"+ name()+ ">::operator = (To<Type>)");
216 if (the_handle == oref.the_handle)
228template< class Type, bool active>
232 DEBUG( "Reference::To<"+ name()+ ">::operator = (Type*=" << ( void*)ref_pointer << ")");
238template< class Type, bool active>
241 DEBUG( "Reference::To<"+ name()+ ">::set (Type*=" << ( void*)ref_pointer << ")");
243 if (the_handle && the_handle->pointer == ref_pointer)
250template< class Type, bool active>
253 DEBUG( "Reference::To<"+ name()+ ">::get");
255 if (!the_handle || the_handle->pointer == 0)
256 throw Error (InvalidPointer, "Reference::To<"+ name()+ ">::get");
258 return reinterpret_cast<Type* >( the_handle->pointer );
262template< class Type, bool active>
265 DEBUG( "Reference::To<"+ name()+ ">::release");
267 if (!the_handle || the_handle->pointer == 0)
268 throw Error (InvalidPointer, "Reference::To<"+ name()+ ">::release");
270 Type* copy = reinterpret_cast<Type* >( the_handle->pointer );
278template< class Type, bool active>
282 return reinterpret_cast<const Type* >( the_handle->pointer );
288template< class Type, bool active>
291 if (the_handle && the_handle->pointer)
292 return reinterpret_cast<Type* >( the_handle->pointer );
297template< class Type, bool active>
300 DEBUG( "swap (Reference::To<Type>, ditto)");
302 Type* ref1_ptr = ref1. release();
303 Type* ref2_ptr = ref2. release();
310template< class Type1, bool active1, class Type2, bool active2>
314 DEBUG( "operator == (Reference::To<Type>&, Reference::To<Type2>&)");
322 return ref1. ptr() == ref2. ptr();
326template< class Type1, bool active1, class Type2, bool active2>
330 DEBUG( "operator != (Reference::To<Type>&, Reference::To<Type2>&)");
338 return ref1. ptr() != ref2. ptr();
343template< class Type, bool active, class Type2>
346 DEBUG( "operator == (Reference::To<Type>&, Type*)");
351template< class Type, bool active, class Type2>
354 DEBUG( "operator == (T2*, Reference::To<T1>&)");
358template< typename C, typename P, bool A>
361 return dynamic_cast<C* > (p. ptr());
364template< typename P, bool A>
367 return const_cast<P* > (p. ptr());
A convenient exception handling class. Definition Error.h:54
Definition ReferenceAble.h:81
void decrement(bool active, bool auto_delete) Thread-safe decrement and delete. Definition ReferenceAble.C:249
static void copy(Handle *&to, Handle *const &from, bool active) Thread-safe copy and increment. Definition ReferenceAble.C:305
Manages Reference::To references to the instance. Definition ReferenceAble.h:35
Template class manages Reference::Able objects. Definition ReferenceTo.h:25
Type * get() const Return the pointer. Definition ReferenceTo.h:251
bool operator==(const Type *ptr) const Comparison operator. Definition ReferenceTo.h:105
bool operator!() const Returns true if reference is null. Definition ReferenceTo.h:182
std::string name() const Return the name of the object, as returned by typeid. Definition ReferenceTo.h:155
Type & operator*() const Object dereferencing operator. Definition ReferenceTo.h:48
bool is_equal_to(const Type *ptr) const Work around "warning: ISO C++ says that these are ambiguous. Definition ReferenceTo.h:119
Type * operator->() const Member dereferencing operator. Definition ReferenceTo.h:51
Type * release() Return the pointer and unhook without deleting the object. Definition ReferenceTo.h:263
const typename FFTW3::Plan * ptr() const Definition ReferenceTo.h:279
void set(Type *) Set the pointer. Definition ReferenceTo.h:239
bool operator!=(const Type *ptr) const Comparison operator. Definition ReferenceTo.h:112
To & operator=(const To &) Assignment operator. Definition ReferenceTo.h:212
~To() Destructor. Definition ReferenceTo.h:174
constexpr To()=default Default constructor.
Contains two basic classes that simplify dynamic memory management. Definition HeapTracked.h:17
Generated using doxygen 1.14.0
|