1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/Exception.hpp" 9 namespace hmbdc {
namespace pattern {
19 template <
typename Singleton>
21 template <
typename...Args>
34 template<
typename Singleton>
37 static Singleton& instance() {
return *pInstance_s;}
38 static bool initialized() {
return pInstance_s;}
44 static Singleton* pInstance_s;
47 template <
typename Singleton> Singleton*
50 template <
typename Singleton>
51 template <
typename...Args>
54 if (GuardedSingleton<Singleton>::pInstance_s) {
55 HMBDC_THROW(std::runtime_error
56 ,
"Cannot reinitialize typeid=" <<
typeid(Singleton).name());
58 GuardedSingleton<Singleton>::pInstance_s
59 =
new Singleton(std::forward<Args>(args)...);
62 template <
typename Singleton>
65 delete GuardedSingleton<Singleton>::pInstance_s;
66 GuardedSingleton<Singleton>::pInstance_s = 0;
base for the Singleton that works with SingletonGuardian
Definition: GuardedSingleton.hpp:35
RAII representing the lifespan of the underlying Singleton which also ganrantees the singularity of u...
Definition: GuardedSingleton.hpp:20