Geant4  10.02.p03
G4CacheReference< VALTYPE > Class Template Reference

#include <G4CacheDetails.hh>

Collaboration diagram for G4CacheReference< VALTYPE >:

Public Member Functions

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

Private Types

typedef std::vector< VALTYPE * > cache_container
 

Static Private Attributes

static G4ThreadLocal cache_containercache = 0
 

Detailed Description

template<class VALTYPE>
class G4CacheReference< VALTYPE >

Definition at line 77 of file G4CacheDetails.hh.

Member Typedef Documentation

◆ cache_container

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

Definition at line 89 of file G4CacheDetails.hh.

Member Function Documentation

◆ Destroy()

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

Definition at line 157 of file G4CacheDetails.hh.

158 {
159  if ( cache ) {
160 #ifdef g4cdebug
161  cout<<"Destroying element"<<id<<" is last?"<<last<<endl;
162 #endif
163  if ( cache->size() < id ) {
165  msg<<"Internal fatal error. Invalid G4Cache size (requested id: "<<id<<" but cache has size: "<<cache->size();
166  msg<<" Possibly client created G4Cache object in a thread and tried to delete it from another thread!";
167  G4Exception("G4CacheReference<V>::Destroy","Cache001",FatalException,msg);
168  return;
169  }
170  if ( cache->size() > id && (*cache)[id] ) {
171  delete (*cache)[id];
172  (*cache)[id]=0;
173  }
174  if (last ) {
175  delete cache;
176  cache = 0;
177  }
178  }
179 }
static G4ThreadLocal cache_container * cache
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
Here is the caller graph for this function:

◆ GetCache()

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

Definition at line 182 of file G4CacheDetails.hh.

183 {
184  return *(cache->operator[](id));
185 }
static G4ThreadLocal cache_container * cache
Here is the caller graph for this function:

◆ Initialize()

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

Definition at line 141 of file G4CacheDetails.hh.

142 {
143 #ifdef g4cdebug
144  if ( cache == 0 )
145  cout<<"Generic template"<<endl;
146 #endif
147  //Create cache container
148  if ( cache == 0 )
149  cache = new cache_container;
150  if ( cache->size() <= id )
151  cache->resize(id+1,static_cast<V*>(0));
152  if ( (*cache)[id] == 0 ) (*cache)[id]=new V;
153 
154 }
std::vector< VALTYPE * > cache_container
static G4ThreadLocal cache_container * cache
Here is the caller graph for this function:

Member Data Documentation

◆ cache

template<class VALTYPE>
G4ThreadLocal G4CacheReference< V * >::cache_container * G4CacheReference< V >::cache = 0
staticprivate

Definition at line 92 of file G4CacheDetails.hh.


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