28 #ifndef CASA_COUNTEDPTR_H
29 #define CASA_COUNTEDPTR_H
35 #define SHARED_PTR std::shared_ptr
36 #define DYNAMIC_POINTER_CAST std::dynamic_pointer_cast
37 #define CONST_POINTER_CAST std::const_pointer_cast
38 #define STATIC_POINTER_CAST std::static_pointer_cast
51 void throw_Null_CountedPtr_dereference_error();
123 template<
typename TP>
140 template<
typename TP>
166 throw_Null_CountedPtr_dereference_error();
190 return (
get() == other.
get());
194 return (ptr == 0 &&
get() == 0);
204 return (ptr != 0 ||
get() != 0);
238 {
return get() == 0; }
241 operator bool()
const
242 {
return get() != 0; }
258 template<
typename T,
typename U>
260 {
return that.template static_ptr_cast<T>(); }
261 template<
typename T,
typename U>
263 {
return that.template const_ptr_cast<T>(); }
264 template<
typename T,
typename U>
266 {
return that.template dynamic_ptr_cast<T>(); }
272 #ifndef CASACORE_NO_AUTO_TEMPLATES
273 #include <casacore/casa/Utilities/CountedPtr.tcc>
274 #endif //# CASACORE_NO_AUTO_TEMPLATES
CountedPtr< t > & operator=(const CountedPtr< TP > &that)
This assignment operator allows CountedPtrs to be copied from other CountedPtrs for which the pointer...
Bool operator==(const CountedPtr< t > &other) const
Equality operator which checks to see if two CountedPtrs are pointing at the same thing...
CountedPtr(t *val, Bool delit=True)
This constructor sets up a reference count for the val pointer.
CountedPtr< U > static_ptr_cast() const
Cast functions.
uInt nrefs() const
Sometimes it is useful to know if there is more than one reference made.
~CountedPtr()
This destructor only deletes the really stored data when it was initialized as deletable and the refe...
Helper class to make deletion of object optional.
CountedPtr(const CountedPtr< TP > &that)
This copy constructor allows CountedPtrs to be initialized from other CountedPtrs for which the point...
CountedPtr< t > & operator=(t *v)
This assignment operator allows the object to which the current CountedPtr points to be changed...
Bool operator==(int ptr) const
Bool operator!=(const CountedPtr< t > &other) const
Non-equality operator which checks to see if two CountedPtrs are not pointing at the same thing...
void reset(t *val, Bool delit=True)
Reset the pointer.
Referenced counted pointer for constant data.
CountedPtr< U > const_ptr_cast() const
t * get() const
Get the underlying pointer.
t & operator*() const
The CountedPtr indirection operator simply returns a reference to the value being protected...
bool Bool
Define the standard types used by Casacore.
CountedPtr< T > static_pointer_cast(const CountedPtr< U > &that)
Cast the CountedPtr from one pointer type to another.
t * operator->() const
This dereferencing operator behaves as expected; it returns the pointer to the value being protected...
CountedPtr< T > const_pointer_cast(const CountedPtr< U > &that)
std::shared_ptr< t > PointerRep
void operator()(T *data) const
CountedPtr()
This constructor allows for the creation of a null CountedPtr.
Bool operator!=(int ptr) const
CountedPtr(const std::shared_ptr< t > &rep)
Create from a shared_ptr.
CountedPtr< U > dynamic_ptr_cast() const
Bool null() const
Check to see if this CountedPtr is un-initialized, null.
CountedPtr< T > dynamic_pointer_cast(const CountedPtr< U > &that)
Bool countedPtrShared()
A shared_ptr is used as implementation.