PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: RefCount.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLCORE_REFCOUNT_H__ 00024 #define __PLCORE_REFCOUNT_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/PLCore.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Classes ] 00042 //[-------------------------------------------------------] 00043 /** 00044 * @brief 00045 * Reference counter template 00046 * 00047 * @note 00048 * - Initially the reference counter is 0 00049 */ 00050 template <class AType> 00051 class RefCount { 00052 00053 00054 //[-------------------------------------------------------] 00055 //[ Public functions ] 00056 //[-------------------------------------------------------] 00057 public: 00058 /** 00059 * @brief 00060 * Constructor 00061 */ 00062 RefCount(); 00063 00064 /** 00065 * @brief 00066 * Destructor 00067 */ 00068 virtual ~RefCount(); 00069 00070 /** 00071 * @brief 00072 * Get a pointer to the object 00073 * 00074 * @return 00075 * Pointer to the reference counter's object, NEVER a null pointer! 00076 */ 00077 virtual const AType *GetPointer() const; 00078 virtual AType *GetPointer(); 00079 00080 /** 00081 * @brief 00082 * Increases the reference count 00083 * 00084 * @return 00085 * Current reference count 00086 */ 00087 uint32 AddReference(); 00088 00089 /** 00090 * @brief 00091 * Decreases the reference count 00092 * 00093 * @return 00094 * Current reference count 00095 * 00096 * @note 00097 * - When the last reference was released, the instance is destroyed automatically 00098 */ 00099 uint32 Release(); 00100 00101 /** 00102 * @brief 00103 * Gets the current reference count 00104 * 00105 * @return 00106 * Current reference count 00107 */ 00108 uint32 GetRefCount() const; 00109 00110 00111 //[-------------------------------------------------------] 00112 //[ Private data ] 00113 //[-------------------------------------------------------] 00114 private: 00115 uint32 m_nRefCount; /**< Reference count */ 00116 00117 00118 }; 00119 00120 00121 //[-------------------------------------------------------] 00122 //[ Namespace ] 00123 //[-------------------------------------------------------] 00124 } // PLCore 00125 00126 00127 //[-------------------------------------------------------] 00128 //[ Implementation ] 00129 //[-------------------------------------------------------] 00130 #include "PLCore/Core/RefCount.inl" 00131 00132 00133 #endif // __PLCORE_REFCOUNT_H__
|