1 #ifndef STATIC_MEMORY_GREMLIN_CLASS
2 #define STATIC_MEMORY_GREMLIN_CLASS
25 class gremlin_object_record;
69 bool put(
const char *unique_name, basis::root_object *ptr);
75 basis::root_object *
get(
const char *unique_name);
81 const char *
find(
const basis::root_object *ptr);
93 gremlin_object_record **c_pointers;
94 bool c_show_debugging;
96 int locate(
const char *unique_name);
129 #define SAFE_STATIC(type, func_name, parms) \
130 type &func_name() { SAFE_STATIC_IMPLEMENTATION(type, parms, __LINE__); }
133 #define SAFE_STATIC_CONST(type, func_name, parms) \
134 const type &func_name() \
135 { SAFE_STATIC_IMPLEMENTATION(type, parms, __LINE__); }
143 #define STATIC_STRING(str) \
144 SAFE_STATIC_IMPLEMENTATION(astring, (str), __LINE__)
149 #define UNIQUE_NAME_BASED_ON_SOURCE(name, linenum) \
150 static const char *name = "file:" __FILE__ ":line:" #linenum
158 #define SAFE_STATIC_IMPLEMENTATION(type, parms, linenum) \
163 UNIQUE_NAME_BASED_ON_SOURCE(__uid_name, linenum); \
165 static basis::root_object *_hidden = NULL_POINTER; \
167 if (structures::static_memory_gremlin::__program_is_dying() || !_hidden) { \
168 basis::auto_synchronizer l(structures::static_memory_gremlin::__memory_gremlin_synchronizer()); \
169 if (structures::static_memory_gremlin::__program_is_dying()) { \
171 _hidden = structures::static_memory_gremlin::__hoople_globals().get(__uid_name); \
175 _hidden = structures::static_memory_gremlin::__hoople_globals().get(__uid_name); \
177 _hidden = new type parms ; \
179 if (!structures::static_memory_gremlin::__hoople_globals().put(__uid_name, _hidden)) { \
189 _hidden = structures::static_memory_gremlin::__hoople_globals().get(__uid_name); \
191 return *dynamic_cast<type *>(_hidden)
Root object for any class that knows its own name.
Holds onto memory chunks that are allocated globally within the program.
bool put(const char *unique_name, basis::root_object *ptr)
adds a "ptr" to the set of static objects under the "unique_name".
DEFINE_CLASS_NAME("static_memory_gremlin")
void enable_debugging(bool verbose)
if "verbose" is true, then the object will produce a noisy log.
basis::root_object * get(const char *unique_name)
locates the pointer held for the "unique_name", if any.
static bool __program_is_dying()
Reports whether the program is shutting down currently.
static static_memory_gremlin & __hoople_globals()
Holds onto objects that have been allocated in a program-wide scope.
void ensure_space_exists()
static basis::mutex & __memory_gremlin_synchronizer()
private object for static_memory_gremlin's use only.
const char * find(const basis::root_object *ptr)
locates the name for "ptr" in our objects.
A dynamic container class that holds any kind of object via pointers.