byteBuffer.h

Engine/source/core/util/byteBuffer.h

More...

Classes:

Namespaces:

namespace

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _BYTEBUFFER_H_
25#define _BYTEBUFFER_H_
26
27#ifndef _PLATFORM_H_
28#include "platform/platform.h"
29#endif
30
31namespace Torque
32{
33
34class PrivateBBData;
35
36class ByteBuffer
37{
38public:
39   ByteBuffer();
40
41   /// Create a ByteBuffer from a chunk of memory.
42   ByteBuffer(U8 *dataPtr, U32 bufferSize);
43
44   /// Create a ByteBuffer of the specified size.
45   ByteBuffer(U32 bufferSize);
46
47   /// Copy constructor
48   ByteBuffer(const ByteBuffer &theBuffer);
49   
50   ByteBuffer  &operator=(const ByteBuffer &theBuffer);
51
52   ~ByteBuffer();
53
54   /// Set the ByteBuffer to point to a new chunk of memory.
55   void setBuffer(U8 *dataPtr, U32 bufferSize, bool copyData);
56
57   /// Resize the buffer.
58   void resize(U32 newBufferSize);
59
60   /// Appends the specified buffer to the end of the byte buffer.
61   void appendBuffer(const U8 *dataBuffer, U32 bufferSize);
62
63   /// Appends the specified ByteBuffer to the end of this byte buffer.
64   void appendBuffer(const ByteBuffer &theBuffer)
65   {
66      appendBuffer(theBuffer.getBuffer(), theBuffer.getBufferSize());
67   }
68
69   U32 getBufferSize() const;
70
71   U8 *getBuffer();
72   const U8 *getBuffer() const;
73
74   /// Copy the data in the buffer.
75   ByteBuffer  getCopy() const;
76
77   /// Clear the buffer.
78   void clear();
79
80private:
81   PrivateBBData  *_data;
82};
83
84}
85
86#endif
87