00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #include "CeylanCountable.h" 00028 00029 00030 #include "CeylanUtils.h" // for emergencyShutdown 00031 00032 00033 #include "CeylanOperators.h" 00034 #include "CeylanLogLight.h" 00035 00036 00037 00038 00039 using std::string ; 00040 00041 using namespace Ceylan ; 00042 00043 00044 Countable::InstanceCount Countable::ReferenceCount = 0 ; 00045 Countable::InstanceCount Countable::MaximumReferenceCount = 0 ; 00046 00047 00048 const string Countable::LogPrefix = "[Instance count]" ; 00049 00050 00051 00052 Countable::Countable( bool verbose ) : 00053 _verbose( verbose ) 00054 { 00055 00056 ReferenceCount++ ; 00057 00058 if ( ReferenceCount > MaximumReferenceCount ) 00059 MaximumReferenceCount = ReferenceCount ; 00060 00061 if ( _verbose ) 00062 { 00063 CEYLAN_LOG( LogPrefix + " one more : " 00064 + Ceylan::toString( ReferenceCount ) 00065 + "/" + Ceylan::toString( MaximumReferenceCount ) ) ; 00066 } 00067 00068 } 00069 00070 00071 00072 Countable::~Countable() throw() 00073 { 00074 00075 if ( ReferenceCount == 0 ) 00076 Ceylan::emergencyShutdown( 00077 "Countable destructor : negative reference count detected." ) ; 00078 00079 ReferenceCount-- ; 00080 00081 if ( _verbose ) 00082 { 00083 CEYLAN_LOG( LogPrefix + " one less : " 00084 + Ceylan::toString( ReferenceCount ) 00085 + "/" + Ceylan::toString( MaximumReferenceCount ) ) ; 00086 } 00087 00088 } 00089 00090 00091 00092 const string Countable::ToString( Ceylan::VerbosityLevels level ) 00093 { 00094 00095 return "Current Countable count is " + Ceylan::toString( ReferenceCount ) 00096 + ", maximum was " + Ceylan::toString( MaximumReferenceCount ) ; 00097 00098 } 00099 00100 00101 00102 Countable::InstanceCount Countable::GetInstanceCount() 00103 { 00104 00105 return ReferenceCount ; 00106 00107 } 00108 00109 00110 00111 Countable::InstanceCount Countable::GetMaximumInstanceCount() 00112 { 00113 00114 return MaximumReferenceCount ; 00115 00116 } 00117