2011-09-24 20:53:37 +03:00
|
|
|
#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.
|
|
|
|
*/
|
2011-09-24 20:53:37 +03:00
|
|
|
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.
|
|
|
|
*/
|
2011-09-24 20:53:37 +03:00
|
|
|
T& operator()() throw(std::bad_alloc)
|
|
|
|
{
|
|
|
|
if(!storage)
|
|
|
|
storage = new T();
|
|
|
|
return *storage;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
T* storage;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|