CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csutil/databuf.h

00001 /*
00002     Crystal Space Data Buffer class
00003     Copyright (C) 2000 by Andrew Zabolotny
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 #ifndef __CS_DATABUF_H__
00021 #define __CS_DATABUF_H__
00022 
00023 #include "iutil/databuff.h"
00024 
00031 class csDataBuffer : public iDataBuffer
00032 {
00034   char *Data;
00036   size_t Size;
00038   bool do_delete;
00039 
00040 public:
00041   SCF_DECLARE_IBASE;
00042 
00044   csDataBuffer (size_t iSize)
00045   {
00046     SCF_CONSTRUCT_IBASE (0); 
00047     Size = iSize;
00048     Data = new char [Size]; 
00049     do_delete = true;
00050   }
00051 
00053   csDataBuffer (char *iData, size_t iSize, bool should_delete = true)
00054   {
00055     SCF_CONSTRUCT_IBASE (0); 
00056     Data = iData; 
00057     Size = iSize; 
00058     do_delete = should_delete;
00059   }
00060 
00062   csDataBuffer (iDataBuffer *source)
00063   {
00064     SCF_CONSTRUCT_IBASE (0); 
00065     Size = source->GetSize();
00066     Data = new char [Size + 1];
00067     memcpy (Data, source->GetData(), Size);
00068     Data[Size] = 0;
00069     do_delete = true;
00070   }
00071 
00073   virtual ~csDataBuffer ()
00074   {
00075     if (do_delete)
00076       delete [] Data;
00077     SCF_DESTRUCT_IBASE();
00078   }
00079 
00081   virtual size_t GetSize () const
00082   { return Size; }
00083 
00085   virtual char* GetData () const
00086   { return Data; }
00087 };
00088 
00089 #endif // __CS_DATABUF_H__

Generated for Crystal Space by doxygen 1.2.18