MINT2
Public Types | Public Member Functions | Public Attributes | List of all members
MINT::counted_ptr< X > Class Template Reference

#include <counted_ptr.h>

Inheritance diagram for MINT::counted_ptr< X >:
MINT::const_counted_ptr< X > MINT::const_counted_ptr< X >

Public Types

typedef X element_type
 

Public Member Functions

bool ok () const
 
void acquire (const counted_ptr< X > &other) throw ()
 
template<typename Y >
void acquire (const counted_ptr< Y > &other) throw ()
 
void release ()
 
 counted_ptr (X *p=0)
 
 ~counted_ptr ()
 
 counted_ptr (const counted_ptr &r) throw ()
 
counted_ptroperator= (const counted_ptr &r)
 
template<typename Y >
 counted_ptr (const counted_ptr< Y > &r) throw ()
 
template<typename Y >
counted_ptroperator= (const counted_ptr< Y > &r)
 
X * get () const throw ()
 
X & operator * () const throw ()
 
X * operator-> () const throw ()
 
bool unique () const throw ()
 
 operator const void * () const
 
void acquire (counted_ptr_counter *c) throw ()
 
void release ()
 
 counted_ptr (X *p=0)
 
 ~counted_ptr ()
 
 counted_ptr (const counted_ptr &r) throw ()
 
counted_ptroperator= (const counted_ptr &r)
 
template<class Y >
 counted_ptr (const counted_ptr< Y > &r) throw ()
 
template<class Y >
counted_ptroperator= (const counted_ptr< Y > &r)
 
X & operator * () const throw ()
 
X * operator-> () const throw ()
 
X * get () const throw ()
 
bool unique () const throw ()
 
 operator void * () const
 

Public Attributes

X * ptr
 
counted_ptr_counteritsCounter
 

Detailed Description

template<typename X>
class MINT::counted_ptr< X >

Definition at line 39 of file counted_ptr.h.

Member Typedef Documentation

◆ element_type

template<typename X>
typedef X MINT::counted_ptr< X >::element_type

Definition at line 67 of file old_counted_ptr.h.

Constructor & Destructor Documentation

◆ counted_ptr() [1/6]

template<typename X>
MINT::counted_ptr< X >::counted_ptr ( X *  p = 0)
inline

Definition at line 80 of file counted_ptr.h.

81  : ptr(p)
82  , itsCounter(0){
83  if (0 != p){
84  itsCounter = new counted_ptr_counter(1);
85  ptr = p;
86  }
87  }
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ ~counted_ptr() [1/2]

template<typename X>
MINT::counted_ptr< X >::~counted_ptr ( )
inline

Definition at line 88 of file counted_ptr.h.

89  {release();}

◆ counted_ptr() [2/6]

template<typename X>
MINT::counted_ptr< X >::counted_ptr ( const counted_ptr< X > &  r)
throw (
)
inline

Definition at line 90 of file counted_ptr.h.

91  {
92  // std::cout << "copy-constructing" << std::endl;
93  acquire(r);
94  }
void acquire(const counted_ptr< X > &other)
Definition: counted_ptr.h:50

◆ counted_ptr() [3/6]

template<typename X>
template<typename Y >
MINT::counted_ptr< X >::counted_ptr ( const counted_ptr< Y > &  r)
throw (
)
inline

Definition at line 107 of file counted_ptr.h.

108  {
109  // std::cout << "copy-constructing other" << std::endl;
110  acquire(r);
111  }
void acquire(const counted_ptr< X > &other)
Definition: counted_ptr.h:50

◆ counted_ptr() [4/6]

template<typename X>
MINT::counted_ptr< X >::counted_ptr ( X *  p = 0)
inlineexplicit

Definition at line 69 of file old_counted_ptr.h.

70  : itsCounter(0) {if (p) itsCounter = new counted_ptr_counter(p);}
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ ~counted_ptr() [2/2]

template<typename X>
MINT::counted_ptr< X >::~counted_ptr ( )
inline

Definition at line 71 of file old_counted_ptr.h.

72  {release();}

◆ counted_ptr() [5/6]

template<typename X>
MINT::counted_ptr< X >::counted_ptr ( const counted_ptr< X > &  r)
throw (
)
inline

Definition at line 73 of file old_counted_ptr.h.

74  {acquire(r.itsCounter);}
void acquire(const counted_ptr< X > &other)
Definition: counted_ptr.h:50

◆ counted_ptr() [6/6]

template<typename X>
template<class Y >
MINT::counted_ptr< X >::counted_ptr ( const counted_ptr< Y > &  r)
throw (
)
inline

Definition at line 86 of file old_counted_ptr.h.

87  {
88  // with this trick we check (I hope) if the conversion
89  // is legal (jr):
90  static_cast<X*>(r.get());
91  acquire(r.itsCounter);
92  }
void acquire(const counted_ptr< X > &other)
Definition: counted_ptr.h:50

Member Function Documentation

◆ acquire() [1/3]

template<typename X>
void MINT::counted_ptr< X >::acquire ( counted_ptr_counter c)
throw (
)
inline

Definition at line 49 of file old_counted_ptr.h.

50  { // increment the count
51  itsCounter = c;
52  if (c) ++(c->count);
53  }
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ acquire() [2/3]

template<typename X>
void MINT::counted_ptr< X >::acquire ( const counted_ptr< X > &  other)
throw (
)
inline

Definition at line 50 of file counted_ptr.h.

51  { // increment the count
52  // std::cout << "acquiring" << std::endl;
53  itsCounter = other.itsCounter;
54  ptr = other.ptr;
55  if (ok()) ++(itsCounter->count);
56  }
bool ok() const
Definition: counted_ptr.h:46
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ acquire() [3/3]

template<typename X>
template<typename Y >
void MINT::counted_ptr< X >::acquire ( const counted_ptr< Y > &  other)
throw (
)
inline

Definition at line 59 of file counted_ptr.h.

60  { // increment the count
61  // std::cout << "acquiring different type" << std::endl;
62  itsCounter = other.itsCounter;
63  ptr = (X*) (other.ptr);
64  if (ok()) ++(itsCounter->count);
65  }
bool ok() const
Definition: counted_ptr.h:46
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ get() [1/2]

template<typename X>
X* MINT::counted_ptr< X >::get ( ) const
throw (
)
inline

Definition at line 108 of file old_counted_ptr.h.

108 {return ((itsCounter) ? static_cast<X*>(itsCounter->ptr) : 0);}
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ get() [2/2]

template<typename X>
X* MINT::counted_ptr< X >::get ( ) const
throw (
)
inline

Definition at line 123 of file counted_ptr.h.

123 {return (this->ok() ? ptr : 0);}
bool ok() const
Definition: counted_ptr.h:46

◆ ok()

template<typename X>
bool MINT::counted_ptr< X >::ok ( ) const
inline

Definition at line 46 of file counted_ptr.h.

46  {
47  return (0 != itsCounter) && (0 != ptr);
48  }
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ operator *() [1/2]

template<typename X>
X& MINT::counted_ptr< X >::operator * ( ) const
throw (
)
inline

Definition at line 106 of file old_counted_ptr.h.

106 {return *(static_cast<X*>(itsCounter->ptr));}
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ operator *() [2/2]

template<typename X>
X& MINT::counted_ptr< X >::operator * ( ) const
throw (
)
inline

Definition at line 124 of file counted_ptr.h.

124 {return *(get());}
X * get() const
Definition: counted_ptr.h:123

◆ operator const void *()

template<typename X>
MINT::counted_ptr< X >::operator const void * ( ) const
inline

Definition at line 130 of file counted_ptr.h.

130  { // jr
131  return (const void*) get();
132  }
X * get() const
Definition: counted_ptr.h:123

◆ operator void *()

template<typename X>
MINT::counted_ptr< X >::operator void * ( ) const
inline

Definition at line 113 of file old_counted_ptr.h.

113  { // jr
114  return (void*) get();
115  }
X * get() const
Definition: counted_ptr.h:123

◆ operator->() [1/2]

template<typename X>
X* MINT::counted_ptr< X >::operator-> ( ) const
throw (
)
inline

Definition at line 107 of file old_counted_ptr.h.

107 {return static_cast<X*>(itsCounter->ptr);}
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ operator->() [2/2]

template<typename X>
X* MINT::counted_ptr< X >::operator-> ( ) const
throw (
)
inline

Definition at line 125 of file counted_ptr.h.

125 {return get();}
X * get() const
Definition: counted_ptr.h:123

◆ operator=() [1/4]

template<typename X>
counted_ptr& MINT::counted_ptr< X >::operator= ( const counted_ptr< X > &  r)
inline

Definition at line 75 of file old_counted_ptr.h.

76  {
77  if (this != &r) {
78  release();
79  acquire(r.itsCounter);
80  }
81  return *this;
82  }
void acquire(const counted_ptr< X > &other)
Definition: counted_ptr.h:50

◆ operator=() [2/4]

template<typename X>
template<class Y >
counted_ptr& MINT::counted_ptr< X >::operator= ( const counted_ptr< Y > &  r)
inline

Definition at line 93 of file old_counted_ptr.h.

94  {
95  if (this != &r) {
96  // with this trick we check (I hope) if the conversion
97  // is legal (jr):
98  static_cast<X*>(r.get());
99  release();
100  acquire(r.itsCounter);
101  }
102  return *this;
103  }
void acquire(const counted_ptr< X > &other)
Definition: counted_ptr.h:50

◆ operator=() [3/4]

template<typename X>
counted_ptr& MINT::counted_ptr< X >::operator= ( const counted_ptr< X > &  r)
inline

Definition at line 95 of file counted_ptr.h.

96  {
97  // std::cout << "copy- = " << std::endl;
98  if (this != &r) {
99  release();
100  acquire(r);
101  }
102  return *this;
103  }
void acquire(const counted_ptr< X > &other)
Definition: counted_ptr.h:50

◆ operator=() [4/4]

template<typename X>
template<typename Y >
counted_ptr& MINT::counted_ptr< X >::operator= ( const counted_ptr< Y > &  r)
inline

Definition at line 112 of file counted_ptr.h.

113  {
114  if ((const void*)this != (const void*) (&r)) {
115  release();
116  // std::cout << "copy = other" << std::endl;
117  acquire(r);
118  }
119  return *this;
120  }
void acquire(const counted_ptr< X > &other)
Definition: counted_ptr.h:50

◆ release() [1/2]

template<typename X>
void MINT::counted_ptr< X >::release ( )
inline

Definition at line 55 of file old_counted_ptr.h.

56  { // decrement the count, delete if it is 0
57  if (itsCounter) {
58  if (--itsCounter->count == 0) {
59  delete (X*)(itsCounter->ptr);
60  delete itsCounter;
61  }
62  itsCounter = 0;
63  }
64  }
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ release() [2/2]

template<typename X>
void MINT::counted_ptr< X >::release ( )
inline

Definition at line 67 of file counted_ptr.h.

68  { // decrement the count, delete if it is 0
69  // std::cout << "releasing" << std::endl;
70  if (ok()) {
71  if (--(itsCounter->count) == 0) {
72  delete ptr;
73  delete itsCounter;
74  }
75  ptr=0;
76  itsCounter = 0;
77  }
78  }
bool ok() const
Definition: counted_ptr.h:46
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ unique() [1/2]

template<typename X>
bool MINT::counted_ptr< X >::unique ( ) const
throw (
)
inline

Definition at line 109 of file old_counted_ptr.h.

110  {return (itsCounter ? itsCounter->count == 1 : true);}
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

◆ unique() [2/2]

template<typename X>
bool MINT::counted_ptr< X >::unique ( ) const
throw (
)
inline

Definition at line 126 of file counted_ptr.h.

127  {return (itsCounter ? itsCounter->count == 1 : true);}
counted_ptr_counter * itsCounter
Definition: counted_ptr.h:44

Member Data Documentation

◆ itsCounter

template<typename X>
counted_ptr_counter * MINT::counted_ptr< X >::itsCounter

Definition at line 44 of file counted_ptr.h.

◆ ptr

template<typename X>
X* MINT::counted_ptr< X >::ptr

Definition at line 43 of file counted_ptr.h.


The documentation for this class was generated from the following files: