1 #ifndef _library__stateobject__hpp__included__
2 #define _library__stateobject__hpp__included__
9 void* _get(void* obj
, void* (*create
)());
10 void* _get_soft(void* obj
);
11 void _clear(void* obj
, void (*destroy
)(void* obj
));
13 template<typename T
, typename U
> class type
17 * Get state object, creating it if needed.
19 * Parameter obj: The object to get the state for.
20 * Returns: The object state.
24 return *reinterpret_cast<U
*>(_get(obj
, []() -> void* { return new U
; }));
27 * Get state object, but don't create if it does not already exist.
29 * Parameter obj: The object to get the state for.
30 * Returns: The object state, or NULL if no existing state.
32 static U
* get_soft(T
* obj
) throw() { return reinterpret_cast<U
*>(_get_soft(obj
)); }
36 static void clear(T
* obj
) throw()
38 return _clear(obj
, [](void* obj
) -> void { delete reinterpret_cast<U
*>(obj
); });