123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #pragma once
- #include <AK/IBytes.h>
- #include <AK/SoundEngine/Common/AkSoundEngineExport.h>
- #include <AK/Tools/Common/AkBankReadHelpers.h>
- namespace AK
- {
- class ReadBytesMem
- : public AK::IReadBytes
- {
- public:
- AKSOUNDENGINE_API ReadBytesMem();
- AKSOUNDENGINE_API ReadBytesMem(
- const void * in_pBytes,
- AkInt32 in_cBytes
- );
- AKSOUNDENGINE_API virtual ~ReadBytesMem();
-
- AKSOUNDENGINE_API virtual bool ReadBytes(
- void * in_pData,
- AkInt32 in_cBytes,
- AkInt32 & out_cRead
- );
-
- AKSOUNDENGINE_API void Attach(
- const void * in_pBytes,
- AkInt32 in_cBytes
- );
- private:
- AkInt32 m_cBytes;
- const AkUInt8 * m_pBytes;
- AkInt32 m_cPos;
- };
- class WriteBytesMem
- : public AK::IWriteBuffer
- {
- public:
-
- AKSOUNDENGINE_API WriteBytesMem();
- AKSOUNDENGINE_API virtual ~WriteBytesMem();
-
-
- AKSOUNDENGINE_API virtual bool WriteBytes(
- const void * in_pData,
- AkInt32 in_cBytes,
- AkInt32& out_cWritten);
-
-
- AKSOUNDENGINE_API virtual bool Reserve(
- AkInt32 in_cBytes
- );
- AKSOUNDENGINE_API virtual AkInt32 Count() const;
- AKSOUNDENGINE_API virtual void SetCount(
- AkInt32 in_cBytes
- );
- AKSOUNDENGINE_API AkInt32 Size() const;
- AKSOUNDENGINE_API virtual AkUInt8 * Bytes() const;
- AKSOUNDENGINE_API virtual AkUInt8 * Detach();
-
- AKSOUNDENGINE_API virtual void Clear();
-
-
- AKSOUNDENGINE_API void SetMemPool( AkMemPoolId in_pool );
- AKSOUNDENGINE_API bool HasValidMemPool();
-
- AkUInt8* GetWritePtr(AkInt32 in_cBytes)
- {
- AkInt32 cPos = m_cPos;
- AkInt32 cNewPos = cPos + in_cBytes;
- if ((m_cBytes >= cNewPos) || Grow(cNewPos))
- {
- m_cPos = cNewPos;
- return m_pBytes + cPos;
- }
- else
- return nullptr;
- }
- template<class T>
- T* GetWritePtr()
- {
- static_assert(alignof(T) == 1, "T must have an alignment of 1 to avoid crashes due to unaligned writes on 32-bit ARM targets. Use Write<T> instead.");
- return reinterpret_cast<T*>(GetWritePtr(sizeof(T)));
- }
- template<class T>
- bool Write(const T & in_data)
- {
- if (AkUInt8* pWrite = GetWritePtr(sizeof(T)))
- {
- AK::WriteUnaligned<T>(pWrite, in_data);
- return true;
- }
- else
- return false;
- }
-
- private:
- bool Grow(
- AkInt32 in_cBytes
- );
- AkInt32 m_cBytes;
- AkUInt8 * m_pBytes;
-
- AkInt32 m_cPos;
-
- AkMemPoolId m_pool;
- };
- class WriteBytesBuffer
- : public AK::IWriteBytes
- {
- public:
- AKSOUNDENGINE_API WriteBytesBuffer();
- AKSOUNDENGINE_API virtual ~WriteBytesBuffer();
- AKSOUNDENGINE_API void SetBuffer(AkUInt8* in_pBytes, AkInt32 in_cSize);
-
- AKSOUNDENGINE_API virtual bool WriteBytes(
- const void* in_pData,
- AkInt32 in_cBytes,
- AkInt32& out_cWritten);
-
- AKSOUNDENGINE_API AkInt32 GetPos() const;
- AKSOUNDENGINE_API void Clear();
- private:
- AkUInt8* m_pBytes;
- AkInt32 m_cSize;
- AkInt32 m_cPos;
- };
- }
|