14 #ifndef WPIUTIL_WPI_MANAGEDSTATIC_H
15 #define WPIUTIL_WPI_MANAGEDSTATIC_H
24 static void *call() {
return new C(); }
30 static void call(
void *Ptr) {
delete (T *)Ptr; }
33 static void call(
void *Ptr) {
delete[](T *)Ptr; }
41 mutable std::atomic<void *> Ptr;
42 mutable void (*DeleterFn)(
void*);
45 void RegisterManagedStatic(
void *(*creator)(),
void (*deleter)(
void*))
const;
46 void RegisterManagedStatic(
void *created,
void (*deleter)(
void*))
const;
60 template <
class C,
class Creator =
object_creator<C>,
61 class Deleter =
object_deleter<C>>
67 RegisterManagedStatic(created, deleter);
72 void *Tmp = Ptr.load(std::memory_order_acquire);
74 RegisterManagedStatic(Creator::call, Deleter::call);
76 return *static_cast<C *>(Ptr.load(std::memory_order_relaxed));
79 C *operator->() {
return &**
this; }
81 const C &operator*()
const {
82 void *Tmp = Ptr.load(std::memory_order_acquire);
84 RegisterManagedStatic(Creator::call, Deleter::call);
86 return *static_cast<C *>(Ptr.load(std::memory_order_relaxed));
89 const C *operator->()
const {
return &**
this; }
104 #endif // WPIUTIL_WPI_MANAGEDSTATIC_H
bool isConstructed() const
isConstructed - Return true if this object has not been created yet.
Definition: ManagedStatic.h:50
wpi_shutdown_obj - This is a simple helper class that calls wpi_shutdown() when it is destroyed.
Definition: ManagedStatic.h:97
void wpi_shutdown()
wpi_shutdown - Deallocate and destroy all ManagedStatic variables.
WPILib C++ utilities (wpiutil) namespace.
Definition: EventLoopRunner.h:17
ManagedStaticBase - Common base class for ManagedStatic instances.
Definition: ManagedStatic.h:37
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:62
object_creator - Helper method for ManagedStatic.
Definition: ManagedStatic.h:23
object_deleter - Helper method for ManagedStatic.
Definition: ManagedStatic.h:29