- Your Widget Set For OpenGL
Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

ucollectable.hpp

00001 /*************************************************************************** 00002 LibUFO - UI For OpenGL 00003 copyright : (C) 2001-2005 by Johannes Schmidt 00004 email : schmidtjf at users.sourceforge.net 00005 ------------------- 00006 00007 file : include/ufo/ucollectable.hpp 00008 begin : Sat Jan 26 2002 00009 $Id: ucollectable.hpp,v 1.12 2005/09/30 14:30:08 schmidtjf Exp $ 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * This library is free software; you can redistribute it and/or * 00014 * modify it under the terms of the GNU Lesser General Public * 00015 * License as published by the Free Software Foundation; either * 00016 * version 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00021 * Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 00026 ***************************************************************************/ 00027 00028 #ifndef UCOLLECTABLE_HPP 00029 #define UCOLLECTABLE_HPP 00030 00031 #include <cstddef> 00032 00033 #include "ufo_global.hpp" 00034 00035 namespace ufo { 00036 00053 //class UFO_EXPORT UCollectable : public gc_cleanup { 00054 //}; 00055 class UFO_EXPORT UCollectable { 00056 public: 00057 UCollectable(); 00058 virtual ~UCollectable(); 00059 00060 void setDynamic(bool b); 00061 bool isDynamic(); 00062 00063 void reference() const; 00064 void unreference() const; 00065 00066 unsigned int getReferenceCount() const; 00067 00068 // FIXME 00069 // hm, evil 00070 void * operator new(std::size_t size); 00071 inline void operator delete(void * p, std::size_t /* size */); 00072 private: 00073 mutable unsigned int m_refCount : 31; 00074 unsigned int m_isDynamic : 1; 00075 static bool m_dynamicAlloc; 00076 }; 00077 00078 // 00079 // inline implementation 00080 // 00081 00082 00083 inline void 00084 UCollectable::setDynamic(bool b) { m_isDynamic = b; } 00085 00086 inline bool 00087 UCollectable::isDynamic() { return m_isDynamic; } 00088 00089 inline void 00090 UCollectable::reference() const { m_refCount++; } 00091 00092 inline void 00093 UCollectable::unreference() const { 00094 if (m_refCount) { // do nothing if ref() has never been called 00095 m_refCount--; 00096 if (m_refCount == 0 && m_isDynamic) { delete this; } 00097 } 00098 } 00099 00100 inline unsigned int 00101 UCollectable::getReferenceCount() const { 00102 return m_refCount; 00103 } 00104 00105 inline void 00106 UCollectable::operator delete(void * p, std::size_t /* size */) { 00107 ::operator delete(p); 00108 } 00109 00110 } // namespace ufo 00111 00112 #endif // UCOLLECTABLE_HPP

The libUFO Project - written by Johannes Schmidt