Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CacheReference< VALTYPE > Class Template Reference

#include <G4CacheDetails.hh>

Public Member Functions

void Initialize (unsigned int id)
 
void Destroy (unsigned int id, G4bool last)
 
VALTYPE & GetCache (unsigned int id) const
 

Detailed Description

template<class VALTYPE>
class G4CacheReference< VALTYPE >

Definition at line 70 of file G4CacheDetails.hh.

Member Function Documentation

◆ Destroy()

template<class V >
void G4CacheReference< V >::Destroy ( unsigned int  id,
G4bool  last 
)
inline

Definition at line 155 of file G4CacheDetails.hh.

156{
157 if(cache() != nullptr)
158 {
159#ifdef g4cdebug
160 std::cout << "V: Destroying element " << id << " is last? " << last
161 << std::endl;
162#endif
163 if(cache()->size() < id)
164 {
166 msg << "Internal fatal error. Invalid G4Cache size (requested id: " << id
167 << " but cache has size: " << cache()->size();
168 msg << " Possibly client created G4Cache object in a thread and"
169 << " tried to delete it from another thread!";
170 G4Exception("G4CacheReference<V>::Destroy", "Cache001", FatalException,
171 msg);
172 return;
173 }
174 if(cache()->size() > id && (*cache())[id] != nullptr)
175 {
176#ifdef g4cdebug
177 std::cout << "V: Destroying element " << id
178 << " size: " << cache()->size() << std::endl;
179#endif
180 delete(*cache())[id];
181 (*cache())[id] = nullptr;
182 }
183 if(last)
184 {
185#ifdef g4cdebug
186 std::cout << "V: Destroying LAST element!" << std::endl;
187#endif
188 delete cache();
189 cache() = nullptr;
190 }
191 }
192}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40

Referenced by G4Cache< VALTYPE >::~G4Cache().

◆ GetCache()

template<class V >
V *& G4CacheReference< V >::GetCache ( unsigned int  id) const
inline

Definition at line 195 of file G4CacheDetails.hh.

196{
197 return *(cache()->operator[](id));
198}

◆ Initialize()

template<class V >
void G4CacheReference< V >::Initialize ( unsigned int  id)
inline

Definition at line 134 of file G4CacheDetails.hh.

135{
136 // Create cache container
137 if(cache() == nullptr)
138 {
139#ifdef g4cdebug
140 std::cout << "Generic template container..." << std::endl;
141#endif
142 cache() = new cache_container;
143 }
144 if(cache()->size() <= id)
145 {
146 cache()->resize(id + 1, static_cast<V*>(0));
147 }
148 if((*cache())[id] == 0)
149 {
150 (*cache())[id] = new V;
151 }
152}

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