- static T* get_ptr(detail::TypeDescriptor type_descriptor = {typeid(T), ""},
- SingletonVault* vault = nullptr /* for testing */) {
- return static_cast<T*>(
- (vault ?: SingletonVault::singleton())->get_ptr(type_descriptor));
- }
-
- // Don't use this function, it's private for a reason! Using it
- // would defeat the *entire purpose* of the vault in that we lose
- // the ability to guarantee that, after a destroyInstances is
- // called, all instances are, in fact, destroyed. You should use
- // weak_ptr if you need to hold a reference to the singleton and
- // guarantee briefly that it exists.
- //
- // Yes, you can just get the weak pointer and lock it, but hopefully
- // if you have taken the time to read this far, you see why that
- // would be bad.
- static std::shared_ptr<T> get_shared(
- detail::TypeDescriptor type_descriptor = {typeid(T), ""},
- SingletonVault* vault = nullptr /* for testing */) {
- return std::static_pointer_cast<T>(
- (vault ?: SingletonVault::singleton())->get_weak(type_descriptor).lock());
- }
-
- detail::TypeDescriptor type_descriptor_;