Buffer.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. #pragma once
  17. /**
  18. * @file Buffer.h
  19. * @ingroup util
  20. * The Buffer class.
  21. */
  22. #include "Audaspace.h"
  23. AUD_NAMESPACE_BEGIN
  24. /**
  25. * This class is a simple buffer in RAM which is 32 Byte aligned and provides
  26. * resize functionality.
  27. */
  28. class AUD_API Buffer
  29. {
  30. private:
  31. /// The size of the buffer in bytes.
  32. int m_size;
  33. /// The pointer to the buffer memory.
  34. data_t* m_buffer;
  35. // delete copy constructor and operator=
  36. Buffer(const Buffer&) = delete;
  37. Buffer& operator=(const Buffer&) = delete;
  38. public:
  39. /**
  40. * Creates a new buffer.
  41. * \param size The size of the buffer in bytes.
  42. */
  43. Buffer(int size = 0);
  44. /**
  45. * Destroys the buffer.
  46. */
  47. ~Buffer();
  48. /**
  49. * Returns the pointer to the buffer in memory.
  50. */
  51. sample_t* getBuffer() const;
  52. /**
  53. * Returns the size of the buffer in bytes.
  54. */
  55. int getSize() const;
  56. /**
  57. * Resizes the buffer.
  58. * \param size The new size of the buffer, measured in bytes.
  59. * \param keep Whether to keep the old data. If the new buffer is smaller,
  60. * the data at the end will be lost.
  61. */
  62. void resize(int size, bool keep = false);
  63. /**
  64. * Makes sure the buffer has a minimum size.
  65. * If size is >= current size, nothing will happen.
  66. * Otherwise the buffer is resized with keep as parameter.
  67. * \param size The new minimum size of the buffer, measured in bytes.
  68. * \param keep Whether to keep the old data. If the new buffer is smaller,
  69. * the data at the end will be lost.
  70. */
  71. void assureSize(int size, bool keep = false);
  72. };
  73. AUD_NAMESPACE_END