lsnes/include/core/globalwrap.hpp

28 lines
455 B
C++
Raw Normal View History

#ifndef _globalwrap__hpp__included__
#define _globalwrap__hpp__included__
2011-09-26 19:02:43 +03:00
/**
* Wrapper for glboal/module-local objects accessable in global ctor context.
*/
template<class T>
class globalwrap
{
public:
2011-09-26 19:02:43 +03:00
/**
* Get the wrapped object.
*
* returns: The wrapped object.
* throws std::bad_alloc: Not enough memory.
*/
T& operator()() throw(std::bad_alloc)
{
if(!storage)
storage = new T();
return *storage;
}
private:
T* storage;
};
#endif