ATLAS Offline Software
Loading...
Searching...
No Matches
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
 SamplePtr ()
 standard constructor
 SamplePtr (Sample *val_sample)
 initializing constructor
 SamplePtr (std::unique_ptr< Sample > val_sample)
 initializing constructor
 SamplePtr (const SamplePtr &that)
 standard copy constructor
 SamplePtr (SamplePtr &&that)
 standard move constructor
 ~SamplePtr ()
 standard destructor
SamplePtroperator= (const SamplePtr &that)
 standard assignment operator
SamplePtroperator= (SamplePtr &&that)
 standard move operator
bool empty () const
 get() == 0
Sampleget ()
 the sample itself
const Sampleget () const
 the sample itself
Sampleoperator-> ()
 the sample itself
const Sampleoperator-> () const
 the sample itself
Sampleoperator* ()
 the sample itself
const Sampleoperator* () const
 the sample itself

Private Attributes

Samplem_sample
 the sample contained

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 }
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
Sample * m_sample
the sample contained
Definition SamplePtr.h:186

◆ 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()
standard constructor
Definition SamplePtr.cxx:37

◆ 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 {
93
94 if (m_sample)
95 m_sample->release ();
96 }
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235

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 }
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229

◆ 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);
182 return *m_sample;
183 }
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:153
bool empty() const
get() == 0

◆ 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);
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);
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);
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 {
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 }
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231

◆ operator=() [2/2]

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

standard move operator

Guarantee
no-fail

Definition at line 116 of file SamplePtr.cxx.

118 {
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: