#ifndef __JLANG__JOBJECT__ #define __JLANG__JOBJECT__ /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Auxiliary base class for inline creation of a static value or clone from a temporary object. */ template struct JObject { typedef T data_type; /** * Get static instance from temporary object. * * \return reference to static object */ data_type& getInstance() { static char buffer[sizeof(T)]; new (buffer) T(static_cast(*this)); T* p = reinterpret_cast(buffer); return *p; } /** * Get clone from temporary object. * * \return pointer to newly created object */ data_type* clone() const { return new T(static_cast(*this)); } protected: /** * Default constructor. */ JObject() {} /** * Copy constructor. */ JObject(const JObject&) {} private: JObject& operator=(const JObject&); }; /** * Get static instance from temporary object. * * \param object object * \return reference to static object */ template inline T& getInstance(const T& object) { static char buffer[sizeof(T)]; new (buffer) T(object); T* p = reinterpret_cast(buffer); return *p; } } #endif