00001 // ///////////////////////////////////////////////////////////////////////////// 00002 // 00003 // Name: ReferenceCounted.cpp 00004 // Author: Michael Bartsch (ZCCdark203) 00005 // 00006 // Desc : This class provides reference counting through the methods 00007 // grab() and drop(). Most objects with the framework are 00008 // derived from ReferenceCounted, and so they are reference 00009 // counted. 00010 // 00011 // License: Copyright (C) 2009 Michael Bartsch and Contributors 00012 // 00013 // This program is free software: you can redistribute it 00014 // and/or modify it under the terms of the zlib/libpng License. 00015 // See main.cpp for conditions of distribution and use. 00016 // 00017 // ///////////////////////////////////////////////////////////////////////////// 00018 00019 // Include files 00020 #include "ReferenceCounted.h" 00021 00022 00023 // ReferenceCounted class 00024 // ReferenceCounted constructor. 00025 ReferenceCounted::ReferenceCounted() 00026 : mRefCount(1) 00027 { 00028 } 00029 00030 // ReferenceCounted deconstructor. 00031 ReferenceCounted::~ReferenceCounted() 00032 { 00033 } 00034 00035 // Gets the reference count. 00036 s32 ReferenceCounted::getReferenceCount() 00037 { 00038 return mRefCount; 00039 } 00040 00041 // Increases the reference counter. 00042 void ReferenceCounted::grab() 00043 { 00044 ++mRefCount; 00045 } 00046 00047 // Decreases the reference counter. 00048 void ReferenceCounted::drop() 00049 { 00050 if(--mRefCount == 0) 00051 delete this; 00052 } 00053 00054 // End of File