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;}
39 using element_type = Singleton;
45 static Singleton* pInstance_s;
48 template <
typename Singleton> Singleton*
51 template <
typename Singleton>
52 template <
typename...Args>
55 if (GuardedSingleton<Singleton>::pInstance_s) {
56 HMBDC_THROW(std::runtime_error
57 ,
"Cannot reinitialize typeid=" <<
typeid(Singleton).name());
59 GuardedSingleton<Singleton>::pInstance_s
60 =
new Singleton(std::forward<Args>(args)...);
63 template <
typename Singleton>
66 delete GuardedSingleton<Singleton>::pInstance_s;
67 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