60#ifndef G4CacheDetails_hh
61#define G4CacheDetails_hh
69template <
class VALTYPE>
80 inline VALTYPE&
GetCache(
unsigned int id)
const;
84 using cache_container = std::vector<VALTYPE*>;
90 static cache_container*& cache();
97template <
class VALTYPE>
108 using cache_container = std::vector<VALTYPE*>;
109 static cache_container*& cache();
126 using cache_container = std::vector<G4double>;
137 if(cache() ==
nullptr)
140 std::cout <<
"Generic template container..." << std::endl;
142 cache() =
new cache_container;
144 if(cache()->size() <=
id)
146 cache()->resize(
id + 1,
static_cast<V*
>(0));
148 if((*cache())[
id] == 0)
150 (*cache())[
id] =
new V;
157 if(cache() !=
nullptr)
160 std::cout <<
"V: Destroying element " <<
id <<
" is last? " << last
163 if(cache()->size() <
id)
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!";
174 if(cache()->size() >
id && (*cache())[
id] !=
nullptr)
177 std::cout <<
"V: Destroying element " <<
id
178 <<
" size: " << cache()->size() << std::endl;
180 delete(*cache())[
id];
181 (*cache())[
id] =
nullptr;
186 std::cout <<
"V: Destroying LAST element!" << std::endl;
197 return *(cache()->operator[](id));
213 if(cache() ==
nullptr)
216 std::cout <<
"Pointer template container..." << std::endl;
218 cache() =
new cache_container;
220 if(cache()->size() <=
id)
222 cache()->resize(
id + 1,
static_cast<V*
>(0));
229 if(cache() !=
nullptr)
232 std::cout <<
"V*: Destroying element " <<
id <<
" is last? " << last
235 if(cache()->size() <
id)
238 msg <<
"Internal fatal error. Invalid G4Cache size (requested id: " <<
id
239 <<
" but cache has size: " << cache()->size();
240 msg <<
" Possibly client created G4Cache object in a thread and"
241 <<
" tried to delete it from another thread!";
246 if(cache()->size() >
id && (*cache())[
id] !=
nullptr)
251 std::cout <<
"V*: Resetting element " <<
id
252 <<
" size: " << cache()->size() << std::endl;
254 (*cache())[
id] =
nullptr;
259 std::cout <<
"V*: Deleting LAST element!" << std::endl;
270 return (cache()->
operator[](
id));
285 if(cache() ==
nullptr)
288 std::cout <<
"Specialized template for G4double container..." << std::endl;
290 cache() =
new cache_container;
292 if(cache()->size() <=
id)
294 cache()->resize(
id + 1,
static_cast<G4double>(0));
300 if(cache() !=
nullptr && last)
303 std::cout <<
"DB: Destroying LAST element! Is it last? " << last
313 return cache()->operator[](id);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
void Destroy(unsigned int id, G4bool last)
VALTYPE *& GetCache(unsigned int id) const
void Initialize(unsigned int id)
VALTYPE & GetCache(unsigned int id) const
void Initialize(unsigned int id)
void Destroy(unsigned int id, G4bool last)
#define G4ThreadLocalStatic