123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #ifndef _AK_IBYTES_H
- #define _AK_IBYTES_H
- #include <wchar.h>
- #include <AK/Tools/Common/AkPlatformFuncs.h>
- namespace AK
- {
-
-
-
-
- class IReadBytes
- {
- public:
-
-
-
-
-
- virtual bool ReadBytes(
- void * in_pData,
- AkInt32 in_cBytes,
- AkInt32 & out_cRead
- ) = 0;
-
-
-
-
-
-
-
-
-
- template<class T>
- bool Read(
- T & out_data)
- {
- AkInt32 cRead;
- return ReadBytes(&out_data, sizeof(T), cRead);
- }
-
-
-
-
- template<class T>
- T Read()
- {
- T value;
- AkInt32 cRead;
- ReadBytes(&value, sizeof(T), cRead);
- return value;
- }
-
-
- template<class CHAR_T>
- bool ReadString(
- CHAR_T * out_pszString,
- AkInt32 in_nMax)
- {
- AkInt32 cChars;
- if (!Read<AkInt32>(cChars))
- return false;
- bool bRet = true;
- if (cChars > 0)
- {
- AkInt32 cRead;
- if (cChars < in_nMax)
- {
- ReadBytes(out_pszString, cChars * sizeof(CHAR_T), cRead);
- out_pszString[cChars] = 0;
- bRet = cRead == (AkInt32)(cChars * sizeof(CHAR_T));
- }
- else
- {
- ReadBytes(out_pszString, in_nMax * sizeof(CHAR_T), cRead);
- out_pszString[in_nMax - 1] = 0;
- bRet = cRead == (AkInt32)(in_nMax * sizeof(CHAR_T));
- if (bRet)
- {
-
- AkInt32 cRemaining = cChars - in_nMax;
- CHAR_T * pTemp = new CHAR_T[cRemaining];
- ReadBytes(pTemp, cRemaining * sizeof(CHAR_T), cRead);
- bRet = cRead == (AkInt32)(cRemaining * sizeof(CHAR_T));
- delete[] pTemp;
- }
- }
- }
- else
- {
- out_pszString[0] = 0;
- }
- return bRet;
- }
-
- };
-
-
-
-
- class IWriteBytes
- {
- public:
-
-
-
-
-
- virtual bool WriteBytes(
- const void * in_pData,
- AkInt32 in_cBytes,
- AkInt32 & out_cWritten
- ) = 0;
-
-
-
-
-
-
-
- template<class T>
- bool Write(
- const T & in_data)
- {
- AkInt32 cWritten;
- return WriteBytes(&in_data, sizeof(T), cWritten);
- }
-
-
- bool WriteString(
- const wchar_t * in_pszString)
- {
- if (in_pszString != NULL)
- {
- size_t cChars = wcslen(in_pszString);
- if (!Write<AkUInt32>((AkUInt32)cChars))
- return false;
- AkInt32 cWritten = 0;
- AkInt32 cToWrite = (AkInt32)(cChars * sizeof(wchar_t));
- if (cChars > 0)
- {
- WriteBytes(in_pszString, cToWrite, cWritten);
- }
- return cWritten == cToWrite;
- }
- return Write<AkUInt32>(0);
- }
-
-
- bool WriteString(
- const char * in_pszString)
- {
- if (in_pszString != NULL)
- {
- size_t cChars = strlen(in_pszString);
- if (!Write<AkUInt32>((AkUInt32)cChars))
- return false;
- AkInt32 cWritten = 0;
- if (cChars > 0)
- {
- WriteBytes(in_pszString, (AkInt32)cChars, cWritten);
- }
- return cWritten == (AkInt32)cChars;
- }
- return Write<AkUInt32>(0);
- }
-
- };
-
-
-
-
- class IWriteBuffer : public IWriteBytes
- {
- public:
-
-
-
-
-
- virtual AkInt32 Count() const = 0;
-
-
- virtual AkUInt8 * Bytes() const = 0;
-
- virtual void SetCount(AkInt32 in_cBytes) = 0;
-
-
- virtual bool Reserve(AkInt32 in_cBytes) = 0;
-
- virtual void Clear() = 0;
-
- virtual AkUInt8 * Detach() = 0;
-
- };
- }
- #endif
|