1 | //////////////////////////////////////////////////////////////////////////////// |
---|
2 | // _singleton.h |
---|
3 | // Author : Francesco Giordana |
---|
4 | // Start Date : January 13, 2005 |
---|
5 | // Copyright : (C) 2006 by Francesco Giordana |
---|
6 | // Email : fra.giordana@tiscali.it |
---|
7 | //////////////////////////////////////////////////////////////////////////////// |
---|
8 | |
---|
9 | //////////////////////////////////////////////////////////////////////////////// |
---|
10 | // Modified from the original version by |
---|
11 | // Author : Steve Streeting |
---|
12 | // Email : Doug@IceTecStudios.com |
---|
13 | //////////////////////////////////////////////////////////////////////////////// |
---|
14 | |
---|
15 | /********************************************************************************* |
---|
16 | * * |
---|
17 | * This program is free software; you can redistribute it and/or modify * |
---|
18 | * it under the terms of the GNU Lesser General Public License as published by * |
---|
19 | * the Free Software Foundation; either version 2 of the License, or * |
---|
20 | * (at your option) any later version. * |
---|
21 | * * |
---|
22 | **********************************************************************************/ |
---|
23 | |
---|
24 | #ifndef __SINGLETON_H__ |
---|
25 | #define __SINGLETON_H__ |
---|
26 | |
---|
27 | // Copied frome Ogre::Singleton, created by Steve Streeting for Ogre |
---|
28 | |
---|
29 | namespace OgreMayaExporter |
---|
30 | { |
---|
31 | /** Template class for creating single-instance global classes. |
---|
32 | */ |
---|
33 | template <typename T> class Singleton |
---|
34 | { |
---|
35 | protected: |
---|
36 | static T* ms_Singleton; |
---|
37 | |
---|
38 | public: |
---|
39 | Singleton(){ |
---|
40 | assert( !ms_Singleton ); |
---|
41 | ms_Singleton = static_cast< T* >( this ); |
---|
42 | } |
---|
43 | ~Singleton(){ |
---|
44 | assert( ms_Singleton ); |
---|
45 | ms_Singleton = 0; |
---|
46 | } |
---|
47 | static T& getSingleton(){ |
---|
48 | assert( ms_Singleton ); |
---|
49 | return ( *ms_Singleton ); |
---|
50 | } |
---|
51 | static T* getSingletonPtr(){ |
---|
52 | return ms_Singleton; |
---|
53 | } |
---|
54 | }; |
---|
55 | |
---|
56 | }; // end namespace |
---|
57 | #endif |
---|