X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSingleton.hh;fp=src%2Fsingleton.hh;h=3d60ff29bc92b05535d56d1a8cd195d9153f24be;hp=ec0d01e9997fbce426c4f41a460e00540f81c66f;hb=c2321281bf12a7efaedde930422c7ddbc92080d4;hpb=87bc17e55b0c1dc73ecc66df856d3f08fd7a7724 diff --git a/src/singleton.hh b/src/Moof/Singleton.hh similarity index 80% rename from src/singleton.hh rename to src/Moof/Singleton.hh index ec0d01e..3d60ff2 100644 --- a/src/singleton.hh +++ b/src/Moof/Singleton.hh @@ -26,39 +26,39 @@ *******************************************************************************/ -#ifndef _SINGLETON_HH_ -#define _SINGLETON_HH_ +#ifndef _MOOF_SINGLETON_HH_ +#define _MOOF_SINGLETON_HH_ #include -namespace dc { +namespace Mf { template -class singleton +class Singleton { static T* ptr_; public: - struct exception : public std::runtime_error + struct Exception : public std::runtime_error { - explicit exception(const std::string& what_arg) : + explicit Exception(const std::string& what_arg) : std::runtime_error(what_arg) {} }; - singleton() + Singleton() { if (!ptr_) { // This hack is from Game Programming Gems. - long long offset = (long long)(T*)1 - (long long)(singleton*)(T*)1; + long long offset = (long long)(T*)1 - (long long)(Singleton*)(T*)1; ptr_ = (T*)((long long)this + offset); } } - ~singleton() + ~Singleton() { - long long offset = (long long)(T*)1 - (long long)(singleton*)(T*)1; + long long offset = (long long)(T*)1 - (long long)(Singleton*)(T*)1; if (ptr_ == (T*)((long long)this + offset)) { ptr_ = 0; @@ -69,7 +69,7 @@ public: { if (!ptr_) { - throw exception("accessing uninstantiated singleton"); + throw Exception("accessing uninstantiated singleton"); } return *ptr_; } @@ -80,12 +80,12 @@ public: } }; -template T* singleton::ptr_ = 0; +template T* Singleton::ptr_ = 0; -} // namespace dc +} // namespace Mf -#endif // _SINGLETON_HH_ +#endif // _MOOF_SINGLETON_HH_ /** vim: set ts=4 sw=4 tw=80: *************************************************/