include/AK/IBytes.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00030
00031 #ifndef _AK_IBYTES_H
00032 #define _AK_IBYTES_H
00033
00034 #include <wchar.h>
00035 #include <AK/Tools/Common/AkPlatformFuncs.h>
00036
00037 namespace AK
00038 {
00041 class IReadBytes
00042 {
00043 public:
00046
00047
00050 virtual bool ReadBytes(
00051 void * in_pData,
00052 AkInt32 in_cBytes,
00053 AkInt32 & out_cRead
00054 ) = 0;
00055
00057
00060
00061
00065 template<class T>
00066 bool Read(
00067 T & out_data )
00068 {
00069 AkInt32 cRead;
00070 return ReadBytes( &out_data, sizeof( T ), cRead );
00071 }
00072
00077 template<class T>
00078 T Read()
00079 {
00080 T value;
00081
00082 AkInt32 cRead;
00083 ReadBytes( &value, sizeof( T ), cRead );
00084
00085 return value;
00086 }
00087
00090 bool ReadString(
00091 wchar_t * out_pszString,
00092 AkInt32 in_nMax )
00093 {
00094 AkInt32 cChars;
00095 if ( !Read<AkInt32>( cChars ) )
00096 return false;
00097
00098 bool bRet = true;
00099
00100 if ( cChars > 0 )
00101 {
00102 AkInt32 cRead;
00103
00104 if ( cChars < in_nMax )
00105 {
00106 ReadBytes( out_pszString, cChars * sizeof( wchar_t ), cRead );
00107 out_pszString[ cChars ] = 0;
00108
00109 bRet = cRead == (AkInt32)( cChars * sizeof( wchar_t ) );
00110 }
00111 else
00112 {
00113 ReadBytes( out_pszString, in_nMax * sizeof( wchar_t ), cRead );
00114 out_pszString[ in_nMax - 1 ] = 0;
00115
00116 bRet = cRead == (AkInt32)( in_nMax * sizeof(wchar_t));
00117
00118 if ( bRet )
00119 {
00120
00121 AkInt32 cRemaining = cChars - in_nMax;
00122
00123 wchar_t * pTemp = new wchar_t[ cRemaining ];
00124
00125 ReadBytes( pTemp, cRemaining * sizeof( wchar_t ), cRead );
00126
00127 bRet = cRead == (AkInt32)(cRemaining * sizeof(wchar_t));
00128
00129 delete [] pTemp;
00130 }
00131 }
00132 }
00133 else
00134 {
00135 out_pszString[ 0 ] = 0;
00136 }
00137
00138 return bRet;
00139 }
00141 };
00142
00145 class IWriteBytes
00146 {
00147 public:
00150
00151
00154 virtual bool WriteBytes(
00155 const void * in_pData,
00156 AkInt32 in_cBytes,
00157 AkInt32 & out_cWritten
00158 ) = 0;
00159
00161
00164
00165
00169 template<class T>
00170 bool Write(
00171 const T & in_data )
00172 {
00173 AkInt32 cWritten;
00174 return WriteBytes( &in_data, sizeof( T ), cWritten );
00175 }
00176
00179 bool WriteString(
00180 const wchar_t * in_pszString )
00181 {
00182 if ( in_pszString != NULL )
00183 {
00184 size_t cChars = wcslen( in_pszString );
00185 if ( !Write<AkUInt32>( (AkUInt32) cChars ) )
00186 return false;
00187
00188 AkInt32 cWritten = 0;
00189 AkInt32 cToWrite = (AkInt32)( cChars * sizeof( wchar_t ) );
00190
00191 if ( cChars > 0 )
00192 {
00193 WriteBytes( in_pszString, cToWrite, cWritten );
00194 }
00195
00196 return cWritten == cToWrite;
00197 }
00198 return Write<AkUInt32>( 0 );
00199 }
00200
00203 bool WriteString(
00204 const char * in_pszString )
00205 {
00206 if ( in_pszString != NULL )
00207 {
00208 size_t cChars = strlen( in_pszString );
00209 if ( !Write<AkUInt32>( (AkUInt32) cChars ) )
00210 return false;
00211
00212 AkInt32 cWritten = 0;
00213
00214 if ( cChars > 0 )
00215 {
00216 WriteBytes( in_pszString, (AkInt32) cChars, cWritten );
00217 }
00218
00219 return cWritten == (AkInt32) cChars;
00220 }
00221 return Write<AkUInt32>( 0 );
00222 }
00224 };
00225
00228 class IWriteBuffer : public IWriteBytes
00229 {
00230 public:
00233
00234
00237 virtual AkInt32 Count() const = 0;
00238
00241 virtual AkUInt8 * Bytes() const = 0;
00242
00244 virtual void SetCount( AkInt32 in_cBytes ) = 0;
00245
00248 virtual bool Reserve( AkInt32 in_cBytes ) = 0;
00249
00251 virtual void Clear() = 0;
00252
00254 virtual AkUInt8 * Detach() = 0;
00255
00257 };
00258 }
00259
00260 #endif // _AK_IBYTES_H
介绍一下自己的项目。我们会竭力为您提供帮助。
来注册自己的项目,我们帮您快速入门,不带任何附加条件!
开始 Wwise 之旅