11 #ifndef _REFCOUNTEDPTR_H_ 12 #define _REFCOUNTEDPTR_H_ 25 #ifdef CH_USE_MEMORY_TRACKING 26 extern unsigned long long int ch_memcount;
32 #define RCPDBG(x) (void)0; 60 template <
typename T,
typename S>
109 template <
typename T>
171 template <
typename T,
199 template <
typename S>
208 template <
typename OP2>
216 template <
typename OP2>
233 Self& operator=(
const Self& rhs);
243 template <
typename S>
250 template <
typename OP2>
258 template <
typename OP2>
269 pointer operator ->()
const;
277 pointer
const& getRefToThePointer()
const;
283 reference operator [](
const int a_idx)
const;
288 operator T* ()
const;
293 bool isNonUnique()
const;
295 int refCount()
const;
306 template<
typename T2,
typename OP2>
309 static const std::string&
name()
323 {a_in.ptr_=0; a_in.refCount_=0; }
326 { std::swap(
ptr_, a_in.ptr_); std::swap(
refCount_,a_in.refCount_);
341 template<
typename T,
typename OP>
343 std::string(
"RefCountedPtr ")+std::string(
typeid(T).
name()));
347 template<
typename T,
typename OP>
350 template<
typename T,
typename OP>
353 template <
typename T,
typename OP>
357 #ifdef CH_USE_MEMORY_TRACKING 358 #pragma omp critical(s_Arena) 371 template <
typename T,
typename OP>
375 #ifdef CH_USE_MEMORY_TRACKING 376 #pragma omp critical(s_Arena) 389 template <
typename T,
typename OP>
395 RCPDBG(
pout() <<
"POD pointer constructor\n";)
400 MayDay::Error(
"RefCountedPtr::RefCountedPtr(T* ptr) out of memory");
403 RCPDBG(
pout() <<
"====> Creating " << ptr << std::endl;)
407 template<typename T, typename OP>
419 template<
typename T,
typename OP>
427 #pragma omp atomic capture 434 template <
typename T,
typename OP>
444 template <
typename T,
typename OP>
455 template <
typename T,
typename OP>
456 template <
typename S>
459 :
ptr_(dynamic_cast<T*>(other.
ptr_)),
462 RCPDBG(
pout() <<
"related conversion copy " <<
ptr_ << std::endl;)
465 if (other.
ptr_ != NULL)
472 template <
typename T,
typename OP>
479 template <
typename T,
typename OP>
488 #pragma omp critical(RCPAssign) 503 template <
typename T,
typename OP>
508 RCPDBG(
pout() <<
"const conversion assign " << rhs.ptr_ << std::endl;)
509 #pragma omp critical(RCPAssign) 511 if (
ptr_ != rhs.ptr_)
528 template <
typename T,
typename OP>
529 template <
typename S>
533 RCPDBG(
pout() <<
"related conversion assign " << rhs.
ptr_ << std::endl;)
534 #pragma omp critical(RCPAssign) 556 template <
typename T,
typename OP>
561 MayDay::Error(
"RefCountedPtr<T>::operator ->() on null pointer");
565 template <
typename T,
typename OP>
572 template <
typename T,
typename OP>
577 MayDay::Error(
"RefCountedPtr<T>::operator *() on null pointer");
581 template <
typename T,
typename OP>
589 template <
class T,
typename OP>
597 template <
typename T,
typename OP>
604 template <
typename T,
typename OP>
611 template <
typename T,
typename OP>
618 template <
typename T,
typename OP>
637 template <
typename T,
typename OP>
std::ostream & pout()
Use this in place of std::cout for program output.
static int size_
Definition: RefCountedPtr.H:336
int * refCount_
Definition: RefCountedPtr.H:333
void swap(Self &b)
Definition: RefCountedPtr.H:620
A reference-counting handle class.
Definition: RefCountedPtr.H:173
#define CH_assert(cond)
Definition: CHArray.H:37
static void destroy(T *a_array)
Definition: RefCountedPtr.H:100
T value_type
Definition: RefCountedPtr.H:177
General case T is non-const and inverse is const.
Definition: RefCountedPtr.H:43
void neverDelete()
Will never delete ptr_.
Definition: RefCountedPtr.H:639
reference operator[](const int a_idx) const
[] access
Definition: RefCountedPtr.H:583
static std::string name_
Definition: RefCountedPtr.H:334
reference operator*() const
pointer dereference.
Definition: RefCountedPtr.H:574
#define RCPDBG(x)
Definition: RefCountedPtr.H:32
void refUp()
Definition: RefCountedPtr.H:409
T InvertConstType
Definition: RefCountedPtr.H:52
Self & operator=(const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &rhs)
Definition: RefCountedPtr.H:259
T * pointer
Definition: RefCountedPtr.H:178
void refDown()
Definition: RefCountedPtr.H:421
A Concrete Class for Dynamic Memory Management.
Definition: Arena.H:124
Policies for when T is an array.
Definition: RefCountedPtr.H:97
pointer ptr_
Definition: RefCountedPtr.H:332
bool isNull() const
Definition: RefCountedPtr.H:599
T & reference
Definition: RefCountedPtr.H:179
RefCountedPtr(const RefCountedPtr< T, OP2 > &other)
Definition: RefCountedPtr.H:209
pointer const & getRefToThePointer() const
Return a const reference to the pointer and don't ask questions.
Definition: RefCountedPtr.H:567
RefCountedPtr< T, OP > Self
Definition: RefCountedPtr.H:180
static void destroy(T *a_mem)
Definition: RefCountedPtr.H:110
const char * name(const FArrayBox &a_dummySpecializationArg)
Definition: CH_HDF5.H:907
T SamePolicyType
Definition: RefCountedPtr.H:77
~RefCountedPtr()
Destructor.
Definition: RefCountedPtr.H:474
static BArena s_Arena
Definition: RefCountedPtr.H:335
friend class RefCountedPtr
Definition: RefCountedPtr.H:307
RefCountedPtr< T, OP > & operator=(RefCountedPtr< T, OP > &&a_in) noexcept
Definition: RefCountedPtr.H:325
static const std::string & name()
Definition: RefCountedPtr.H:309
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
void freeMem()
Definition: RefCountedPtr.H:373
const T InvertConstType
Definition: RefCountedPtr.H:45
Self & operator=(const RefCountedPtr< T, OP2 > &rhs)
Definition: RefCountedPtr.H:251
static void destroy(T *a_pointer)
Definition: RefCountedPtr.H:90
General case T and S are not the same.
Definition: RefCountedPtr.H:61
pointer operator->() const
dereference access operator used like a pointer derefence access function.
Definition: RefCountedPtr.H:558
Policies for when T is created via malloc (or otherwise requires free)
Definition: RefCountedPtr.H:107
void incrementMem()
Definition: RefCountedPtr.H:355
C::self_type operator*(const C &, const C &)
Definition: GenericArithmeticI.H:128
RefCountedPtr(RefCountedPtr< T, OP > &&a_in) noexcept
move constructor
Definition: RefCountedPtr.H:321
bool isNonUnique() const
true when refcount is one.
Definition: RefCountedPtr.H:606
int refCount() const
Definition: RefCountedPtr.H:613
RefCountedPtr(const RefCountedPtr< typename RCPTypeTr< T >::InvertConstType, OP2 > &other)
Definition: RefCountedPtr.H:217
Policies for when T is a scalar object.
Definition: RefCountedPtr.H:87
Self & operator=(const Self &rhs)
assignment operator copies pointer member
Definition: RefCountedPtr.H:481