FDO API Reference Feature Data Objects

IDisposable.h

Go to the documentation of this file.
00001 #ifndef _IDISPOSABLE_H_
00002 #define _IDISPOSABLE_H_
00003 // 
00004 
00005 //
00006 // Copyright (C) 2004-2006  Autodesk, Inc.
00007 // 
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of version 2.1 of the GNU Lesser
00010 // General Public License as published by the Free Software Foundation.
00011 // 
00012 // This 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 GNU
00015 // Lesser General Public License for more details.
00016 // 
00017 // You should have received a copy of the GNU Lesser General Public
00018 // License along with this library; if not, write to the Free Software
00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 //
00021 
00022 #ifdef _WIN32
00023 #pragma once
00024 #endif
00025 
00026 /// \brief
00027 /// FdoIDisposable is the base interface for all classes that implement this
00028 /// standard interface for reference counting and object destruction.
00029 class FdoIDisposable
00030 {
00031 protected:
00032     /// \brief
00033     /// Create an instance of the IDisposable object
00034     /// 
00035     /// \return
00036     /// Returns nothing
00037     /// 
00038     FDO_API_COMMON FdoIDisposable() : m_refCount(1) {};
00039 
00040     /// \brief
00041     /// Default destructor for this class.
00042     /// 
00043     /// \return
00044     /// Returns nothing
00045     /// 
00046     FDO_API_COMMON virtual ~FdoIDisposable() {};
00047 
00048     /// \brief
00049     /// Dispose this object.
00050     /// 
00051     /// \return
00052     /// Returns nothing
00053     /// 
00054     FDO_API_COMMON virtual void Dispose() = 0;
00055 
00056 public:
00057     /// \brief
00058     /// Increase the reference count.
00059     /// 
00060     /// \return
00061     /// Returns the new reference count (value for debugging use only).
00062     /// 
00063     FDO_API_COMMON FdoInt32 AddRef() { return ++m_refCount; }
00064 
00065     /// \brief
00066     /// Decrease the reference count.
00067     /// 
00068     /// \return
00069     /// Returns the new reference count (value for debugging use only).
00070     /// 
00071     FDO_API_COMMON FdoInt32 Release() { if (0 != --m_refCount ) return m_refCount; Dispose(); return 0; }
00072 
00073     /// \brief
00074     /// Retrieves the reference count.
00075     /// 
00076     /// \return
00077     /// Returns the existing reference count value.
00078     /// 
00079     FDO_API_COMMON FdoInt32 GetRefCount() { return m_refCount; }
00080 
00081 private:
00082     FdoInt32    m_refCount;
00083 };
00084 
00085 #define FDO_SAFE_RELEASE(x) {if (x) (x)->Release(); (x) = NULL;}
00086 #define FDO_SAFE_ADDREF(x)  ((x != NULL) ? (x)->AddRef(), (x) : (NULL))
00087 #endif
00088 
00089 

Comments or suggestions? Send us feedback.