00001 /***************************************************************************** 00002 * SGL: A Scene Graph Library 00003 * 00004 * Copyright (C) 1997-2001 Scott McMillan All Rights Reserved. 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public 00017 * License along with this library; if not, write to the Free 00018 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 ***************************************************************************** 00020 * File: sglDataPtr.hpp 00021 * Author: Tom Stimson 00022 * Created: 6 April 2002 00023 * Summary: Reference counted container for data pointers. 00024 *****************************************************************************/ 00025 00026 #ifndef __SGL_DATA_PTR_HPP 00027 #define __SGL_DATA_PTR_HPP 00028 00029 #include <sglObject.hpp> 00030 00033 class SGL_DLL_API sglDataPtr : public sglObject 00034 { 00035 public: 00037 enum DataTypeEnum 00038 { 00039 eBYTE, 00040 eUNSIGNED_BYTE, 00041 eSHORT, 00042 eUNSIGNED_SHORT, 00043 eINT, 00044 eUNSIGNED_INT, 00045 eFLOAT, 00046 eDOUBLE 00047 }; 00048 00049 public: 00051 sglDataPtr() {} 00052 00054 virtual ~sglDataPtr() {} 00055 00059 virtual void *getData() const = 0; 00060 00065 static int getSizeOfType(DataTypeEnum type) 00066 { return s_size[type]; } 00067 00072 static GLenum getGLType(DataTypeEnum type) 00073 { return s_gltype[type]; } 00074 00075 private: 00076 // Not Implemented. 00077 sglDataPtr(const sglDataPtr &); 00078 sglDataPtr &operator=(const sglDataPtr &); 00079 00080 private: 00081 static int s_size[8]; 00082 static GLenum s_gltype[8]; 00083 }; 00084 00085 00089 template <class T> 00090 class SGL_DLL_API sglDeleteableDataPtr : public sglDataPtr 00091 { 00092 public: 00094 sglDeleteableDataPtr(T *ptr) : m_data(ptr) {} 00095 00097 virtual ~sglDeleteableDataPtr() { delete[] m_data; } 00098 00099 // See sglDataPtr::getData() for details. 00100 virtual void *getData() const { return m_data; } 00101 00102 private: 00103 // Not Implemented. 00104 sglDeleteableDataPtr(const sglDeleteableDataPtr &); 00105 sglDeleteableDataPtr &operator=(const sglDeleteableDataPtr &); 00106 00107 private: 00108 T *m_data; 00109 }; 00110 00111 00115 class SGL_DLL_API sglFreeableDataPtr : public sglDataPtr 00116 { 00117 public: 00119 sglFreeableDataPtr(void *ptr) : m_data(ptr) {} 00120 00122 virtual ~sglFreeableDataPtr() { if (m_data) free(m_data); } 00123 00124 // See sglDataPtr::getData() for details. 00125 virtual void *getData() const { return m_data; } 00126 00127 private: 00128 // Not Implemented. 00129 sglFreeableDataPtr(const sglFreeableDataPtr &); 00130 sglFreeableDataPtr &operator=(const sglFreeableDataPtr &); 00131 00132 private: 00133 void *m_data; 00134 }; 00135 00136 00141 class SGL_DLL_API sglNoRefDataPtr : public sglDataPtr 00142 { 00143 public: 00145 sglNoRefDataPtr(void *ptr) : m_data(ptr) {} 00146 00148 virtual ~sglNoRefDataPtr() {} 00149 00150 // See sglDataPtr::getData() for details. 00151 virtual void *getData() const { return m_data; } 00152 00153 private: 00154 // Not Implemented. 00155 sglNoRefDataPtr(const sglNoRefDataPtr &); 00156 sglNoRefDataPtr &operator=(const sglNoRefDataPtr &); 00157 00158 private: 00159 void *m_data; 00160 }; 00161 00162 00163 #endif