AkBytesCount.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*******************************************************************************
  2. The content of this file includes portions of the AUDIOKINETIC Wwise Technology
  3. released in source code form as part of the SDK installer package.
  4. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Apache License Usage
  10. Alternatively, this file may be used under the Apache License, Version 2.0 (the
  11. "Apache License"); you may not use this file except in compliance with the
  12. Apache License. You may obtain a copy of the Apache License at
  13. http://www.apache.org/licenses/LICENSE-2.0.
  14. Unless required by applicable law or agreed to in writing, software distributed
  15. under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  16. OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
  17. the specific language governing permissions and limitations under the License.
  18. Copyright (c) 2023 Audiokinetic Inc.
  19. *******************************************************************************/
  20. // AkBytesCount.h
  21. /// \file
  22. /// IReadBytes / IWriteBytes implementation on a growing memory buffer. This
  23. /// version uses the AK::MemoryMgr memory pools.
  24. #pragma once
  25. #include <AK/IBytes.h>
  26. #include <AK/SoundEngine/Common/AkSoundEngineExport.h>
  27. #include <AK/Tools/Common/AkBankReadHelpers.h>
  28. namespace AK
  29. {
  30. class ReadBytesSkip
  31. : public AK::IReadBytes
  32. {
  33. public:
  34. AKSOUNDENGINE_API ReadBytesSkip();
  35. AKSOUNDENGINE_API ReadBytesSkip(
  36. const void * in_pBytes,
  37. AkInt32 in_cBytes
  38. );
  39. AKSOUNDENGINE_API virtual ~ReadBytesSkip();
  40. // IReadBytes implementation
  41. AKSOUNDENGINE_API virtual bool ReadBytes(
  42. void * in_pData,
  43. AkInt32 in_cBytes,
  44. AkInt32 & out_cRead
  45. );
  46. // Public methods
  47. AKSOUNDENGINE_API void Attach(
  48. const void * in_pBytes,
  49. AkInt32 in_cBytes
  50. );
  51. AKSOUNDENGINE_API AkInt32 Count();
  52. private:
  53. AkInt32 m_cBytes;
  54. const AkUInt8 * m_pBytes;
  55. AkInt32 m_cPos;
  56. };
  57. class WriteBytesCount
  58. : public AK::IWriteBuffer
  59. {
  60. public:
  61. AKSOUNDENGINE_API WriteBytesCount();
  62. AKSOUNDENGINE_API virtual ~WriteBytesCount();
  63. // IWriteBytes implementation
  64. AKSOUNDENGINE_API virtual bool WriteBytes(
  65. const void * in_pData,
  66. AkInt32 in_cBytes,
  67. AkInt32& out_cWritten);
  68. // IWriteBuffer implementation
  69. AKSOUNDENGINE_API virtual bool Reserve(
  70. AkInt32 in_cBytes
  71. );
  72. AKSOUNDENGINE_API virtual AkInt32 Count() const;
  73. AKSOUNDENGINE_API virtual void SetCount(
  74. AkInt32 in_cBytes
  75. );
  76. AKSOUNDENGINE_API virtual AkUInt8 * Bytes() const;
  77. AKSOUNDENGINE_API virtual AkUInt8 * Detach();
  78. AKSOUNDENGINE_API virtual void Clear();
  79. template<class T>
  80. bool Write(const T & in_data)
  81. {
  82. m_cPos += sizeof(T);
  83. return true;
  84. }
  85. private:
  86. bool Grow(
  87. AkInt32 in_cBytes
  88. );
  89. AkInt32 m_cPos;
  90. };
  91. }