ATLAS Offline Software
SamplePtr.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 
14 //
15 // includes
16 //
17 
19 
20 #include <RootCoreUtils/Assert.h>
21 #include <SampleHandler/Sample.h>
22 
23 //
24 // method implementations
25 //
26 
27 namespace SH
28 {
30  testInvariant () const
31  {
32  }
33 
34 
35 
37  SamplePtr ()
38  : m_sample (0)
39  {
40  RCU_NEW_INVARIANT (this);
41  }
42 
43 
44 
46  SamplePtr (Sample *val_sample)
47  : m_sample (val_sample)
48  {
49  if (m_sample)
50  m_sample->alloc ();
51 
52  RCU_NEW_INVARIANT (this);
53  }
54 
55 
56 
58  SamplePtr (std::unique_ptr<Sample> val_sample)
59  : SamplePtr (val_sample.release())
60  {
61  // no invariant used
62  }
63 
64 
65 
67  SamplePtr (const SamplePtr& that)
68  : m_sample (that.m_sample)
69  {
70  if (m_sample)
71  m_sample->alloc ();
72 
73  RCU_NEW_INVARIANT (this);
74  }
75 
76 
77 
79  SamplePtr (SamplePtr&& that)
80  : m_sample (that.m_sample)
81  {
82  that.m_sample = nullptr;
83 
84  RCU_NEW_INVARIANT (this);
85  }
86 
87 
88 
90  ~SamplePtr ()
91  {
92  RCU_DESTROY_INVARIANT (this);
93 
94  if (m_sample)
95  m_sample->release ();
96  }
97 
98 
99 
101  operator = (const SamplePtr& that)
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  }
113 
114 
115 
117  operator = (SamplePtr&& that)
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  }
128 
129 
130 
132  empty () const
133  {
134  RCU_READ_INVARIANT (this);
135  return m_sample == 0;
136  }
137 
138 
139 
141  get ()
142  {
143  RCU_READ_INVARIANT (this);
144  return m_sample;
145  }
146 
147 
149  get () const
150  {
151  RCU_READ_INVARIANT (this);
152  return m_sample;
153  }
154 
155 
156 
159  {
160  RCU_READ_INVARIANT (this);
161  RCU_REQUIRE_SOFT (!empty());
162  return m_sample;
163  }
164 
165 
166 
168  operator -> () const
169  {
170  RCU_READ_INVARIANT (this);
171  RCU_REQUIRE_SOFT (!empty());
172  return m_sample;
173  }
174 
175 
176 
178  operator * ()
179  {
180  RCU_READ_INVARIANT (this);
181  RCU_REQUIRE_SOFT (!empty());
182  return *m_sample;
183  }
184 
185 
186 
188  operator * () const
189  {
190  RCU_READ_INVARIANT (this);
191  RCU_REQUIRE_SOFT (!empty());
192  return *m_sample;
193  }
194 }
SH::SamplePtr::~SamplePtr
~SamplePtr()
standard destructor
Definition: SamplePtr.cxx:90
SH::SamplePtr::SamplePtr
SamplePtr()
standard constructor
Definition: SamplePtr.cxx:37
SH::SamplePtr::empty
bool empty() const
get() == 0
Definition: SamplePtr.cxx:132
SH::SamplePtr::testInvariant
void testInvariant() const
test the invariant of this object
Definition: SamplePtr.cxx:30
Assert.h
SH::SamplePtr::m_sample
Sample * m_sample
the sample contained
Definition: SamplePtr.h:186
SH::SamplePtr::operator*
Sample & operator*()
the sample itself
Definition: SamplePtr.cxx:178
SH::SamplePtr::operator=
SamplePtr & operator=(const SamplePtr &that)
standard assignment operator
Definition: SamplePtr.cxx:101
SamplePtr.h
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition: Assert.h:153
SH::Sample::release
void release() const
decrease the reference count by one
SH::Sample
a base class that manages a set of files belonging to a particular data set and the associated meta-d...
Definition: Sample.h:54
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:24
SH::SamplePtr
A smart pointer class that holds a single Sample object.
Definition: SamplePtr.h:35
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
SH
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: PrunDriver.h:15
SH::SamplePtr::operator->
Sample * operator->()
the sample itself
Definition: SamplePtr.cxx:158
SH::SamplePtr::get
Sample * get()
the sample itself
Definition: SamplePtr.cxx:141
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
Sample.h
SH::Sample::alloc
void alloc() const
increase the reference count by one
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233