40template <
typename Type,
41 typename PointerT = std::unique_ptr<Type, std::default_delete<Type>>>
54 template <
bool B,
typename T =
int>
89 void*
operator new(size_t)
92 return static_cast<void*
>(ptr);
97 void operator delete(
void* ptr)
133 void*
operator new[](std::size_t)
noexcept {
return nullptr; }
134 void operator delete[](
void*)
noexcept {}
136 template <
typename Tp =
Type,
typename PtrT = PointerT,
137 enable_if_t<(std::is_same<PtrT, std::shared_ptr<Tp>>::value)> = 0>
140 static deleter_t _instance = [](PointerT&) {};
144 template <
typename Tp =
Type,
typename PtrT = PointerT,
145 enable_if_t<!(std::is_same<PtrT, std::shared_ptr<Tp>>::value)> = 0>
148 static deleter_t _instance = [](PointerT& _master) {
149 auto& del = _master.get_deleter();
151 _master.reset(
nullptr);
173 : m_master_thread(_tid)
174 , m_master_instance(_master)
179 m_master_instance =
nullptr;
199template <
typename Type,
typename Po
interT>
203 return f_persistent_data().m_master_thread;
208template <
typename Type,
typename Po
interT>
212 return f_persistent_data().m_master_instance;
217template <
typename Type,
typename Po
interT>
221 return f_persistent_data().m_mutex;
226template <
typename Type,
typename Po
interT>
230 return f_persistent_data().m_children;
235template <
typename Type,
typename Po
interT>
243template <
typename Type,
typename Po
interT>
251template <
typename Type,
typename Po
interT>
254 auto& del = GetDeleter();
255 del(_master_instance());
260template <
typename Type,
typename Po
interT>
264 if(!f_master_instance())
266 f_master_thread() = std::this_thread::get_id();
267 f_master_instance() =
new Type();
273template <
typename Type,
typename Po
interT>
277 if(!f_master_instance())
279 f_master_thread() = std::this_thread::get_id();
280 f_master_instance() = ptr;
286template <
typename Type,
typename Po
interT>
290 if(std::this_thread::get_id() == f_master_thread() && f_master_instance())
292 delete f_master_instance();
293 f_master_instance() =
nullptr;
297 remove(_local_instance().
get());
303template <
typename Type,
typename Po
interT>
307 if(std::this_thread::get_id() == f_master_thread())
308 return GetMasterInstance();
309 else if(!_local_instance().
get())
311 _local_instance().reset(
new Type());
312 Insert(_local_instance().
get());
314 return _local_instance().get();
319template <
typename Type,
typename Po
interT>
323 if(!f_master_instance())
325 f_master_thread() = std::this_thread::get_id();
326 f_master_instance() =
new Type();
328 return f_master_instance();
333template <
typename Type,
typename Po
interT>
339 if(_master_instance().
get())
340 _master_instance().reset();
341 else if(f_master_instance())
343 auto& del = GetDeleter();
344 del(_master_instance());
345 f_master_instance() =
nullptr;
347 f_persistent_data().reset();
351 _local_instance().reset();
357template <
typename Type,
typename Po
interT>
362 _master_instance().reset();
363 _local_instance().reset();
364 f_persistent_data().reset();
369template <
typename Type,
typename Po
interT>
373 return std::this_thread::get_id() == f_master_thread();
378template <
typename Type,
typename Po
interT>
383 f_children().insert(itr);
388template <
typename Type,
typename Po
interT>
393 for(
auto litr = f_children().begin(); litr != f_children().end(); ++litr)
397 f_children().erase(litr);
G4double(* function)(G4double)
Singleton object that allows a deleter class to be specified.
std::unique_lock< mutex_t > auto_lock_t
static smart_pointer & _master_instance()
std::set< pointer > list_t
std::function< void(PointerT &)> deleter_t
static pointer GetMasterInstance()
std::thread::id thread_id_t
Singleton(const Singleton &)=delete
Singleton & operator=(const Singleton &)=delete
static list_t & f_children()
static pointer & f_master_instance()
static bool IsMasterThread()
smart_pointer & GetSmartInstance()
static thread_id_t & f_master_thread()
static pointer GetRawMasterInstance()
Singleton & operator=(Singleton &&)=delete
static pointer GetInstance()
static smart_pointer & _local_instance()
static void Remove(pointer)
static persistent_data & f_persistent_data()
static thread_id_t GetMasterThreadID()
static mutex_t & GetMutex()
static bool IsMaster(pointer ptr)
static smart_pointer & GetSmartMasterInstance()
typename std::enable_if< B, T >::type enable_if_t
Singleton(Singleton &&)=delete
std::recursive_mutex mutex_t
static mutex_t & f_mutex()
Singleton< Type, PointerT > this_type
static void Insert(pointer)
auto get(Tuple< Elements... > &t) -> decltype(get_height< sizeof...(Elements) - I - 1 >(t))
typename std::enable_if< B, T >::type enable_if_t
~persistent_data()=default
persistent_data(persistent_data &&)=delete
persistent_data(const persistent_data &)=delete
persistent_data & operator=(persistent_data &&)=delete
persistent_data(pointer _master, std::thread::id _tid)
persistent_data()=default
persistent_data & operator=(const persistent_data &)=delete