nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef NMACROS_H 00024 #define NMACROS_H 00025 00026 00027 // Disable object copy constructor and assignment operator 00028 #define NUX_DISABLE_OBJECT_COPY(Class) \ 00029 private: \ 00030 Class(const Class &); \ 00031 const Class& operator = (const Class &); 00032 00034 #define NUX_GLOBAL_OBJECT_VARIABLE(Class) Class m_##Class; 00035 #define NUX_GLOBAL_OBJECT_INSTANCE(Class) Class::Instance() 00036 #define NUX_GLOBAL_OBJECT_REFERENCE(Class) Class::Instance() 00037 00038 #define NUX_IMPLEMENT_GLOBAL_OBJECT(Class) Class* Class::pInstance = 0; 00039 00040 00041 // Note: Methods that are implicitly generated by the compiler if they are not explicitly defined are: 00042 // * Default constructor (C::C()) 00043 // * Copy constructor (C::C (const C& rhs)) 00044 // * Destructor (C::~C()) 00045 // * Assignment operator (C& C::operator= (const C& rhs)) 00046 // * Address-of operator (C* C::operator&()) 00047 // * Address-of operator (const C* C::operator&() const;) 00048 00066 #define NUX_DECLARE_GLOBAL_OBJECT(Class, GlobalInitializer) \ 00067 NUX_DISABLE_OBJECT_COPY(Class); \ 00068 /* Disable address-of operator */ \ 00069 /*Class* operator & (); */ \ 00070 /*const Class* operator & () const; */ \ 00071 friend class GlobalInitializer; \ 00072 private: \ 00073 static Class* pInstance; \ 00074 Class() \ 00075 { \ 00076 pInstance = this; \ 00077 Constructor(); \ 00078 } \ 00079 virtual ~Class() \ 00080 { \ 00081 Destructor(); \ 00082 } \ 00083 \ 00084 void Constructor(); \ 00085 void Destructor(); \ 00086 \ 00087 public: \ 00088 static bool Ready() \ 00089 { \ 00090 return pInstance != 0; \ 00091 } \ 00092 static Class& Instance() \ 00093 { \ 00094 if(pInstance == 0) \ 00095 { \ 00096 PrintOutputDebugString(ANSI_TO_TCHAR(__FILE__), __LINE__, \ 00097 TEXT("Global object %s has not been initialized"), ANSI_TO_TCHAR(TEXT(#Class))); \ 00098 inlDebugBreak(); \ 00099 } \ 00100 return *pInstance; \ 00101 } \ 00102 00103 00105 00106 #define NUX_SINGLETON_CLASS_INTERNAL(ClassImpl) \ 00107 private: \ 00108 ClassImpl(); \ 00109 ~ClassImpl(); \ 00110 ClassImpl(const ClassImpl &); \ 00111 ClassImpl& operator=(const ClassImpl &); \ 00112 ClassImpl* operator &(); \ 00113 friend struct Loki::CreateUsingNew<ClassImpl>; \ 00114 friend struct Loki::CreateUsingMalloc<ClassImpl>; \ 00115 friend struct Loki::CreateStatic<ClassImpl>; 00116 00117 #define NUX_SINGLETON_CLASS_DECLARE(ClassImpl, SingletonClass) typedef ::Loki::SingletonHolder<ClassImpl, ::Loki::CreateUsingNew, ::Loki::DefaultLifetime, ::Loki::ClassLevelLockable> SingletonClass; 00118 #define NUX_SINGLETON_INSTANCE(SingletonClass) SingletonClass::Instance() 00119 // Silence unused parameters: no warning 00120 #define NUX_UNUSED(parameter) (void)parameter; 00121 00122 #endif // NMACROS_H