StreamBuffer.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright (c) 2006-2016 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "StreamBuffer.h"
  21. #include "common/Exception.h"
  22. namespace love
  23. {
  24. namespace graphics
  25. {
  26. StreamBuffer::StreamBuffer(Mode mode, size_t size)
  27. : data(nullptr)
  28. , offset(0)
  29. , totalSize(size)
  30. , mode(mode)
  31. {
  32. setSize(size);
  33. }
  34. StreamBuffer::~StreamBuffer()
  35. {
  36. delete[] data;
  37. }
  38. void *StreamBuffer::getData() const
  39. {
  40. return data;
  41. }
  42. void *StreamBuffer::getOffsetData() const
  43. {
  44. return data + offset;
  45. }
  46. void StreamBuffer::incrementOffset(size_t amount)
  47. {
  48. offset += amount;
  49. }
  50. void StreamBuffer::resetOffset()
  51. {
  52. offset = 0;
  53. }
  54. void StreamBuffer::setSize(size_t size)
  55. {
  56. delete[] data;
  57. try
  58. {
  59. data = new uint8[size];
  60. }
  61. catch (std::exception &)
  62. {
  63. throw love::Exception("Out of memory.");
  64. }
  65. this->totalSize = size;
  66. }
  67. } // graphics
  68. } // love