Geant4  10.02.p03
G4Cache< VALTYPE > Class Template Reference

#include <G4Cache.hh>

Collaboration diagram for G4Cache< VALTYPE >:

Public Types

typedef VALTYPE value_type
 

Public Member Functions

 G4Cache ()
 
 G4Cache (const value_type &v)
 
virtual ~G4Cache ()
 
value_typeGet () const
 
void Put (const value_type &val) const
 
value_type Pop ()
 
 G4Cache (const G4Cache &rhs)
 
G4Cacheoperator= (const G4Cache &rhs)
 

Protected Member Functions

const int & GetId () const
 

Private Member Functions

value_typeGetCache () const
 

Private Attributes

int id
 
G4CacheReference< value_typetheCache
 

Static Private Attributes

static G4Mutex gMutex = G4MUTEX_INITIALIZER
 
static unsigned int instancesctr = 0
 
static unsigned int dstrctr = 0
 

Detailed Description

template<class VALTYPE>
class G4Cache< VALTYPE >

Definition at line 85 of file G4Cache.hh.

Member Typedef Documentation

◆ value_type

template<class VALTYPE>
typedef VALTYPE G4Cache< VALTYPE >::value_type

Definition at line 87 of file G4Cache.hh.

Constructor & Destructor Documentation

◆ G4Cache() [1/3]

template<class V >
G4Cache< V >::G4Cache ( )

Definition at line 216 of file G4Cache.hh.

217 {
218  G4AutoLock l(&gMutex);
219  id = instancesctr++;
220 #ifdef g4cdebug
221  cout<<"G4Cache id: "<<id<<endl;
222 #endif
223 }
static unsigned int instancesctr
Definition: G4Cache.hh:117
static G4Mutex gMutex
Definition: G4Cache.hh:116
Here is the caller graph for this function:

◆ G4Cache() [2/3]

template<class VALTYPE>
G4Cache< VALTYPE >::G4Cache ( const value_type v)

◆ ~G4Cache()

template<class V >
G4Cache< V >::~G4Cache ( )
virtual

Definition at line 266 of file G4Cache.hh.

267 { //Move base calss
268 #ifdef g4cdebug
269  cout<<"~G4Cache id: "<<id<<" "<<endl;
270 #endif
271  G4AutoLock l(&gMutex);
272  ++dstrctr;
273  G4bool last = ( dstrctr == instancesctr );
274  theCache.Destroy(id,last);
275  if (last) {
276  instancesctr = 0;
277  dstrctr = 0;
278  }
279 }
G4CacheReference< value_type > theCache
Definition: G4Cache.hh:115
static unsigned int instancesctr
Definition: G4Cache.hh:117
bool G4bool
Definition: G4Types.hh:79
void Destroy(unsigned int id, G4bool last)
static unsigned int dstrctr
Definition: G4Cache.hh:118
static G4Mutex gMutex
Definition: G4Cache.hh:116

◆ G4Cache() [3/3]

template<class VALTYPE>
G4Cache< VALTYPE >::G4Cache ( const G4Cache< VALTYPE > &  rhs)

Member Function Documentation

◆ Get()

template<class V >
V & G4Cache< V >::Get ( ) const
inline

Definition at line 282 of file G4Cache.hh.

283 { return GetCache(); }
value_type & GetCache() const
Definition: G4Cache.hh:120

◆ GetCache()

template<class VALTYPE>
value_type& G4Cache< VALTYPE >::GetCache ( ) const
inlineprivate

Definition at line 120 of file G4Cache.hh.

120  {
121  theCache.Initialize(id);
122  return theCache.GetCache(id);
123  }
G4CacheReference< value_type > theCache
Definition: G4Cache.hh:115
void Initialize(unsigned int id)
VALTYPE & GetCache(unsigned int id) const
Here is the caller graph for this function:

◆ GetId()

template<class VALTYPE>
const int& G4Cache< VALTYPE >::GetId ( ) const
inlineprotected

Definition at line 112 of file G4Cache.hh.

112 { return id; }
int id
Definition: G4Cache.hh:114
Here is the caller graph for this function:

◆ operator=()

template<class VALTYPE>
G4Cache< V > & G4Cache< V >::operator= ( const G4Cache< VALTYPE > &  rhs)

Definition at line 242 of file G4Cache.hh.

243 {
244  if (this == &rhs) return *this;
245  //Force copy of cached data
246  V aCopy = rhs.GetCache();
247  Put(aCopy);
248 #ifdef g4cdebug
249  cout<<"Assignement operator with id: "<<id<<endl;
250 #endif
251  return *this;
252 }
void Put(const value_type &val) const
Definition: G4Cache.hh:286
value_type & GetCache() const
Definition: G4Cache.hh:120

◆ Pop()

template<class V >
V G4Cache< V >::Pop ( )
inline

Definition at line 291 of file G4Cache.hh.

292 { return GetCache(); }
value_type & GetCache() const
Definition: G4Cache.hh:120

◆ Put()

template<class VALTYPE>
void G4Cache< V >::Put ( const value_type val) const
inline

Definition at line 286 of file G4Cache.hh.

287 { GetCache() = val; }
value_type & GetCache() const
Definition: G4Cache.hh:120
Here is the caller graph for this function:

Member Data Documentation

◆ dstrctr

template<class VALTYPE>
unsigned int G4Cache< V >::dstrctr = 0
staticprivate

Definition at line 118 of file G4Cache.hh.

◆ gMutex

template<class VALTYPE>
G4Mutex G4Cache< V >::gMutex = G4MUTEX_INITIALIZER
staticprivate

Definition at line 116 of file G4Cache.hh.

◆ id

template<class VALTYPE>
int G4Cache< VALTYPE >::id
private

Definition at line 114 of file G4Cache.hh.

◆ instancesctr

template<class VALTYPE>
unsigned int G4Cache< V >::instancesctr = 0
staticprivate

Definition at line 117 of file G4Cache.hh.

◆ theCache

template<class VALTYPE>
G4CacheReference<value_type> G4Cache< VALTYPE >::theCache
mutableprivate

Definition at line 115 of file G4Cache.hh.


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