template<typename T, typename FactoryT = DefaultConstructorFactory<T>>
class BLOCXX_NAMESPACE::GlobalPtr< T, FactoryT >
This class can be used to store a global pointer.
The pointer is lazily constructed. The pointer is never deleted. The intended use is for objects which must always exist for the lifetime of a program, but which may need to be polymorphic and replaced to enable plugging in a mock object for testing.
GlobalPtr is a POD type, and thus must be initialized using POD initialization syntax: GlobalPtr<myType> myGlobalPtr = BLOCXX_GLOBAL_PTR_INIT;
The pointer will be lazily constructed. The first time get() is called, a new T (or derived) will be instantiated by a call to FactoryT::create(). The default type for FactoryT allocates a new instance of T using the default constructor. The initialization is done in a thread safe manner. The double checked locking pattern is used, which doesn't have a large overhead.
The object will never be deleted, so if the destructor needs to do meaningful work, this class shouldn't be used.
All calls to get() are thread safe. Calls to set() are not thread safe.
- Parameters
-
| T | The type of the pointer. |
| FactoryT | To create the T*, FactoryT::create() will be called with no parameters. The return type must be convertible to a T*. The default will return a new T using the default constructor. |
Definition at line 83 of file GlobalPtr.hpp.