MyGUI 3.0.1
MyGUI_Instance.h
Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #ifndef __MYGUI_INSTANCE_H__
00024 #define __MYGUI_INSTANCE_H__
00025 
00026 #define MYGUI_INSTANCE_HEADER(type) \
00027     private: \
00028         static type* msInstance; \
00029         bool mIsInitialise; \
00030     public: \
00031         type();\
00032         ~type();\
00033         static type& getInstance(); \
00034         static type* getInstancePtr();
00035 
00036 
00037 #define MYGUI_INSTANCE_IMPLEMENT(type) \
00038     const std::string INSTANCE_TYPE_NAME(#type); \
00039     type* type::msInstance = nullptr; \
00040     type* type::getInstancePtr() { return msInstance; } \
00041     type& type::getInstance() { MYGUI_ASSERT(0 != msInstance, "instance " << INSTANCE_TYPE_NAME << " was not created"); return (*msInstance); } \
00042     type::type() : mIsInitialise(false) { MYGUI_ASSERT(0 == msInstance, "instance " << INSTANCE_TYPE_NAME << " is exsist"); msInstance = this; } \
00043     type::~type() { msInstance = nullptr; }
00044 
00045 #endif // __MYGUI_INSTANCE_H__