Geant4-11
Public Member Functions | Private Types | Static Private Member Functions
G4CacheReference< VALTYPE > Class Template Reference

#include <G4CacheDetails.hh>

Public Member Functions

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

Private Types

using cache_container = std::vector< VALTYPE * >
 

Static Private Member Functions

static cache_container *& cache ()
 

Detailed Description

template<class VALTYPE>
class G4CacheReference< VALTYPE >

Definition at line 70 of file G4CacheDetails.hh.

Member Typedef Documentation

◆ cache_container

template<class VALTYPE >
using G4CacheReference< VALTYPE >::cache_container = std::vector<VALTYPE*>
private

Definition at line 84 of file G4CacheDetails.hh.

Member Function Documentation

◆ cache()

template<class V >
G4CacheReference< V * >::cache_container *& G4CacheReference< V >::cache
staticprivate

Definition at line 201 of file G4CacheDetails.hh.

202{
203 G4ThreadLocalStatic cache_container* _instance = nullptr;
204 return _instance;
205}
std::vector< VALTYPE * > cache_container
#define G4ThreadLocalStatic
Definition: tls.hh:76

References G4ThreadLocalStatic.

Referenced by G4CacheReference< G4double >::Destroy(), G4CacheReference< G4double >::GetCache(), and G4CacheReference< G4double >::Initialize().

◆ 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:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
static cache_container *& cache()

References FatalException, and G4Exception().

◆ 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}

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

◆ 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}

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


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