MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / Initialize

Class Initialize

runtime/Initialize.h:45–82  ·  view source on GitHub ↗

* This class is used to manage once-only initialization that should occur * before main() is invoked, such as the creation of static variables. It * also provides a mechanism for handling dependencies (where one class * needs to perform its once-only initialization before another). * * The simplest way to use an Initialize object is to define a static * initialization method for a class, s

Source from the content-addressed store, hash-verified

43 * destruction).
44 */
45class Initialize {
46 public:
47 /**
48 * This form of constructor causes its function argument to be invoked
49 * when the object is constructed. When used with a static Initialize
50 * object, this will cause #func to run before main() runs, so that
51 * #func can perform once-only initialization.
52 *
53 * \param func
54 * This function is invoked with no arguments when the object is
55 * constructed. Typically the function will create static
56 * objects and/or invoke other initialization functions. The
57 * function should normally contain an internal guard so that it
58 * only performs its initialization the first time it is invoked.
59 */
60 Initialize(void (*func)()) {
61 (*func)();
62 }
63
64 /**
65 * This form of constructor causes a new object of a particular class
66 * to be constructed with a no-argument constructor and assigned to a
67 * given pointer. This form is typically used with a static Initialize
68 * object: the result is that the object will be created and assigned
69 * to the pointer before main() runs.
70 *
71 * \param p
72 * Pointer to an object of any type. If the pointer is NULL then
73 * it is replaced with a pointer to a newly allocated object of
74 * the given type.
75 */
76 template<typename T>
77 explicit Initialize(T*& p) {
78 if (p == NULL) {
79 p = new T;
80 }
81 }
82};
83
84} // end RAMCloud
85

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected