ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
SH::SamplePtr Class Reference

A smart pointer class that holds a single Sample object. More...

#include <SamplePtr.h>

Collaboration diagram for SH::SamplePtr:

Public Member Functions

void testInvariant () const
 test the invariant of this object More...
 
 SamplePtr ()
 standard constructor More...
 
 SamplePtr (Sample *val_sample)
 initializing constructor More...
 
 SamplePtr (std::unique_ptr< Sample > val_sample)
 initializing constructor More...
 
 SamplePtr (const SamplePtr &that)
 standard copy constructor More...
 
 SamplePtr (SamplePtr &&that)
 standard move constructor More...
 
 ~SamplePtr ()
 standard destructor More...
 
SamplePtroperator= (const SamplePtr &that)
 standard assignment operator More...
 
SamplePtroperator= (SamplePtr &&that)
 standard move operator More...
 
bool empty () const
 get() == 0 More...
 
Sampleget ()
 the sample itself More...
 
const Sampleget () const
 the sample itself More...
 
Sampleoperator-> ()
 the sample itself More...
 
const Sampleoperator-> () const
 the sample itself More...
 
Sampleoperator* ()
 the sample itself More...
 
const Sampleoperator* () const
 the sample itself More...
 

Private Attributes

Samplem_sample
 the sample contained More...
 

Detailed Description

A smart pointer class that holds a single Sample object.

To avoid various memory management issues, samples are usually held via such a smart pointer. Since the reference count is internal to the Sample object it is safe to assign the same Sample to multiple smart pointers.

Rationale
This class is mostly to make SampleHandler independent of boost, otherwise I could have used boost::intrusive_ptr.

Definition at line 34 of file SamplePtr.h.

Constructor & Destructor Documentation

◆ SamplePtr() [1/5]

SH::SamplePtr::SamplePtr ( )

standard constructor

Guarantee
no-fail

Definition at line 36 of file SamplePtr.cxx.

38  : m_sample (0)
39  {
40  RCU_NEW_INVARIANT (this);
41  }

◆ SamplePtr() [2/5]

SH::SamplePtr::SamplePtr ( Sample val_sample)

initializing constructor

Guarantee
no-fail

Definition at line 45 of file SamplePtr.cxx.

47  : m_sample (val_sample)
48  {
49  if (m_sample)
50  m_sample->alloc ();
51 
52  RCU_NEW_INVARIANT (this);
53  }

◆ SamplePtr() [3/5]

SH::SamplePtr::SamplePtr ( std::unique_ptr< Sample val_sample)
explicit

initializing constructor

Guarantee
no-fail

Definition at line 57 of file SamplePtr.cxx.

59  : SamplePtr (val_sample.release())
60  {
61  // no invariant used
62  }

◆ SamplePtr() [4/5]

SH::SamplePtr::SamplePtr ( const SamplePtr that)

standard copy constructor

Guarantee
no-fail

Definition at line 66 of file SamplePtr.cxx.

68  : m_sample (that.m_sample)
69  {
70  if (m_sample)
71  m_sample->alloc ();
72 
73  RCU_NEW_INVARIANT (this);
74  }

◆ SamplePtr() [5/5]

SH::SamplePtr::SamplePtr ( SamplePtr &&  that)

standard move constructor

Guarantee
no-fail

Definition at line 78 of file SamplePtr.cxx.

80  : m_sample (that.m_sample)
81  {
82  that.m_sample = nullptr;
83 
84  RCU_NEW_INVARIANT (this);
85  }

◆ ~SamplePtr()

SH::SamplePtr::~SamplePtr ( )

standard destructor

Guarantee
no-fail

Definition at line 89 of file SamplePtr.cxx.

91  {
92  RCU_DESTROY_INVARIANT (this);
93 
94  if (m_sample)
95  m_sample->release ();
96  }

Member Function Documentation

◆ empty()

bool SH::SamplePtr::empty ( ) const

get() == 0

Returns
get() == 0
Guarantee
no-fail

Definition at line 131 of file SamplePtr.cxx.

133  {
134  RCU_READ_INVARIANT (this);
135  return m_sample == 0;
136  }

◆ get() [1/2]

Sample * SH::SamplePtr::get ( )

the sample itself

Returns
the sample itself
Guarantee
no-fail

Definition at line 140 of file SamplePtr.cxx.

142  {
143  RCU_READ_INVARIANT (this);
144  return m_sample;
145  }

◆ get() [2/2]

const Sample * SH::SamplePtr::get ( ) const

the sample itself

Returns
the sample itself
Guarantee
no-fail

Definition at line 148 of file SamplePtr.cxx.

150  {
151  RCU_READ_INVARIANT (this);
152  return m_sample;
153  }

◆ operator*() [1/2]

Sample & SH::SamplePtr::operator* ( )

the sample itself

Returns
the sample itself
Guarantee
no-fail
Precondition
!empty()

Definition at line 177 of file SamplePtr.cxx.

179  {
180  RCU_READ_INVARIANT (this);
181  RCU_REQUIRE_SOFT (!empty());
182  return *m_sample;
183  }

◆ operator*() [2/2]

const Sample & SH::SamplePtr::operator* ( ) const

the sample itself

Returns
the sample itself
Guarantee
no-fail
Precondition
!empty()

Definition at line 187 of file SamplePtr.cxx.

189  {
190  RCU_READ_INVARIANT (this);
191  RCU_REQUIRE_SOFT (!empty());
192  return *m_sample;
193  }

◆ operator->() [1/2]

Sample * SH::SamplePtr::operator-> ( )

the sample itself

Returns
the sample itself
Guarantee
no-fail
Precondition
!empty()

Definition at line 157 of file SamplePtr.cxx.

159  {
160  RCU_READ_INVARIANT (this);
161  RCU_REQUIRE_SOFT (!empty());
162  return m_sample;
163  }

◆ operator->() [2/2]

const Sample * SH::SamplePtr::operator-> ( ) const

the sample itself

Returns
the sample itself
Guarantee
no-fail
Precondition
!empty()

Definition at line 167 of file SamplePtr.cxx.

169  {
170  RCU_READ_INVARIANT (this);
171  RCU_REQUIRE_SOFT (!empty());
172  return m_sample;
173  }

◆ operator=() [1/2]

SamplePtr & SH::SamplePtr::operator= ( const SamplePtr that)

standard assignment operator

Guarantee
no-fail

Definition at line 100 of file SamplePtr.cxx.

102  {
103  RCU_CHANGE_INVARIANT (this);
104  RCU_READ_INVARIANT (&that);
105 
106  if (that.m_sample)
107  that.m_sample->alloc ();
108  if (m_sample)
109  m_sample->release ();
110  m_sample = that.m_sample;
111  return *this;
112  }

◆ operator=() [2/2]

SamplePtr & SH::SamplePtr::operator= ( SamplePtr &&  that)

standard move operator

Guarantee
no-fail

Definition at line 116 of file SamplePtr.cxx.

118  {
119  RCU_CHANGE_INVARIANT (this);
120  RCU_READ_INVARIANT (&that);
121 
122  if (m_sample)
123  m_sample->release ();
124  m_sample = that.m_sample;
125  that.m_sample = nullptr;
126  return *this;
127  }

◆ testInvariant()

void SH::SamplePtr::testInvariant ( ) const

test the invariant of this object

Guarantee
no-fail

Definition at line 29 of file SamplePtr.cxx.

31  {
32  }

Member Data Documentation

◆ m_sample

Sample* SH::SamplePtr::m_sample
private

the sample contained

Definition at line 186 of file SamplePtr.h.


The documentation for this class was generated from the following files:
SH::SamplePtr::SamplePtr
SamplePtr()
standard constructor
Definition: SamplePtr.cxx:37
SH::SamplePtr::empty
bool empty() const
get() == 0
Definition: SamplePtr.cxx:132
SH::SamplePtr::m_sample
Sample * m_sample
the sample contained
Definition: SamplePtr.h:186
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition: Assert.h:153
SH::Sample::release
void release() const
decrease the reference count by one
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
SH::Sample::alloc
void alloc() const
increase the reference count by one
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233