[692] | 1 | /************************************************************************
|
---|
| 2 | filename: CEGUIDataContainer.h
|
---|
| 3 | created: 10/8/2004
|
---|
| 4 | author: James '_mental_' O'Sullivan
|
---|
| 5 |
|
---|
| 6 | purpose: Defines abstract base class for Window objects
|
---|
| 7 | *************************************************************************/
|
---|
| 8 | /*************************************************************************
|
---|
| 9 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
| 10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
| 11 |
|
---|
| 12 | This library is free software; you can redistribute it and/or
|
---|
| 13 | modify it under the terms of the GNU Lesser General Public
|
---|
| 14 | License as published by the Free Software Foundation; either
|
---|
| 15 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 16 |
|
---|
| 17 | This library is distributed in the hope that it will be useful,
|
---|
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | Lesser General Public License for more details.
|
---|
| 21 |
|
---|
| 22 | You should have received a copy of the GNU Lesser General Public
|
---|
| 23 | License along with this library; if not, write to the Free Software
|
---|
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 25 | *************************************************************************/
|
---|
| 26 | #ifndef _CEGUIDataContainer_h_
|
---|
| 27 | #define _CEGUIDataContainer_h_
|
---|
| 28 |
|
---|
| 29 | #include "CEGUIBase.h"
|
---|
| 30 |
|
---|
| 31 | #include <malloc.h>
|
---|
| 32 | //#include <xercesc/sax/InputSource.hpp>
|
---|
| 33 |
|
---|
| 34 | // Start of CEGUI namespace section
|
---|
| 35 | namespace CEGUI
|
---|
| 36 | {
|
---|
| 37 |
|
---|
| 38 | template <class T>
|
---|
| 39 | class CEGUIEXPORT DataContainer
|
---|
| 40 | {
|
---|
| 41 | public:
|
---|
| 42 | /*************************************************************************
|
---|
| 43 | Construction and Destruction
|
---|
| 44 | *************************************************************************/
|
---|
| 45 | /*!
|
---|
| 46 | \brief
|
---|
| 47 | Constructor for DataContainer class
|
---|
| 48 | */
|
---|
| 49 | DataContainer()
|
---|
| 50 | : mData(0),
|
---|
| 51 | mSize(0)
|
---|
| 52 | {
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /*!
|
---|
| 56 | \brief
|
---|
| 57 | Destructor for DataContainer class
|
---|
| 58 | */
|
---|
| 59 | virtual ~DataContainer(void)
|
---|
| 60 | {
|
---|
| 61 | release();
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | /*************************************************************************
|
---|
| 65 | Accessor functions
|
---|
| 66 | *************************************************************************/
|
---|
| 67 | /*!
|
---|
| 68 | \brief
|
---|
| 69 | Set a pointer to the external data.
|
---|
| 70 |
|
---|
| 71 | \param data
|
---|
| 72 | Pointer to a object of type T, where T defined when the template is specialized.
|
---|
| 73 | */
|
---|
| 74 | void setData(T* data) { mData = data; }
|
---|
| 75 |
|
---|
| 76 | /*!
|
---|
| 77 | \brief
|
---|
| 78 | Return a pointer to the external data
|
---|
| 79 |
|
---|
| 80 | \return
|
---|
| 81 | Pointer to an object of type T, where T defined when the template is specialized.
|
---|
| 82 | */
|
---|
| 83 | T* getDataPtr(void) { return mData; }
|
---|
| 84 |
|
---|
| 85 | /*!
|
---|
| 86 | \brief
|
---|
| 87 | Set the size of the external data. This maybe zero depending on the type of T.
|
---|
| 88 |
|
---|
| 89 | \param size
|
---|
| 90 | size_t containing the size of the external data
|
---|
| 91 | */
|
---|
| 92 | void setSize(size_t size) { mSize = size; }
|
---|
| 93 |
|
---|
| 94 | /*!
|
---|
| 95 | \brief
|
---|
| 96 | Get the size of the external data. This maybe zero depending on the type of T.
|
---|
| 97 |
|
---|
| 98 | \return
|
---|
| 99 | size_t containing the size of the external data
|
---|
| 100 | */
|
---|
| 101 | size_t getSize(void) const { return mSize; }
|
---|
| 102 |
|
---|
| 103 | /*!
|
---|
| 104 | \brief
|
---|
| 105 | Release supplied data.
|
---|
| 106 |
|
---|
| 107 | */
|
---|
| 108 | virtual void release(void)
|
---|
| 109 | {
|
---|
| 110 | if(mData)
|
---|
| 111 | {
|
---|
| 112 | delete mData;
|
---|
| 113 | mData = 0;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | /*************************************************************************
|
---|
| 117 | Implementation Data
|
---|
| 118 | *************************************************************************/
|
---|
| 119 | protected:
|
---|
| 120 | T* mData;
|
---|
| 121 | size_t mSize;
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 | // Specialized templates
|
---|
| 125 | class RawDataContainer : public DataContainer<unsigned char>
|
---|
| 126 | {
|
---|
| 127 | public:
|
---|
| 128 | RawDataContainer() : DataContainer<unsigned char>()
|
---|
| 129 | {
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | ~RawDataContainer()
|
---|
| 133 | {
|
---|
| 134 | release();
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | void release(void)
|
---|
| 138 | {
|
---|
| 139 | if(mData)
|
---|
| 140 | {
|
---|
| 141 | delete [] mData;
|
---|
| 142 | mData = 0;
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | };
|
---|
| 146 |
|
---|
| 147 | //typedef DataContainer<unsigned char> RawDataContainer;
|
---|
| 148 | //typedef DataContainer<XERCES_CPP_NAMESPACE::InputSource> InputSourceContainer;
|
---|
| 149 |
|
---|
| 150 | } // End of CEGUI namespace section
|
---|
| 151 |
|
---|
| 152 | #endif // end of guard _CEGUIDataContainer_h_
|
---|
| 153 |
|
---|
| 154 |
|
---|