byteBuffer.h 2.5 KB

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