00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "CeylanSingleton.h"
00028
00029
00030 #include "CeylanLogPlug.h"
00031 #include "CeylanOperators.h"
00032
00033
00034
00035 using std::string ;
00036
00037 using namespace Ceylan ;
00038 using namespace Ceylan::Log ;
00039
00040
00041 Singleton * Singleton::_InternalSingleton = 0 ;
00042
00043
00044
00045 SingletonException::SingletonException( const string & reason ) :
00046 Ceylan::Exception( reason )
00047 {
00048
00049 }
00050
00051
00052
00053 SingletonException::~SingletonException() throw()
00054 {
00055
00056 }
00057
00058
00059
00060 Singleton & Singleton::GetSingleton()
00061 {
00062
00063 if ( Singleton::_InternalSingleton == 0 )
00064 {
00065
00066 LogPlug::debug(
00067 "No Singleton available for getSingleton, creating new one" ) ;
00068 Singleton::_InternalSingleton = new Singleton() ;
00069
00070 }
00071 else
00072 {
00073
00074 LogPlug::debug( "Returning already constructed instance "
00075 "of Singleton, no creation" ) ;
00076
00077 }
00078
00079 LogPlug::debug( "Returning Singleton instance "
00080 + Ceylan::toString( Singleton::_InternalSingleton ) ) ;
00081
00082 return * Singleton::_InternalSingleton ;
00083
00084 }
00085
00086
00087
00088 void Singleton::DeleteSingleton()
00089 {
00090
00091 if ( Singleton::_InternalSingleton != 0 )
00092 {
00093 LogPlug::debug( "deleteSingleton: effective deleting." ) ;
00094 delete Singleton::_InternalSingleton ;
00095 Singleton::_InternalSingleton = 0 ;
00096 }
00097 else
00098 {
00099 LogPlug::debug( "deleteSingleton: no deleting needed." ) ;
00100 }
00101
00102 }
00103
00104
00105
00106
00107
00108
00109 Singleton::Singleton()
00110 {
00111
00112 LogPlug::debug( "Creation of a Singleton instance: "
00113 + Ceylan::toString( this ) ) ;
00114
00115 }
00116
00117
00118
00119 Singleton::~Singleton() throw()
00120 {
00121
00122 LogPlug::debug( "Warning: destruction of a Singleton instance: "
00123 + Ceylan::toString( this ) ) ;
00124
00125 }
00126