版本

menu_open

include/AK/IBytes.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
00003 released in source code form as part of the SDK installer package.
00004 
00005 Commercial License Usage
00006 
00007 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
00008 may use this file in accordance with the end user license agreement provided 
00009 with the software or, alternatively, in accordance with the terms contained in a
00010 written agreement between you and Audiokinetic Inc.
00011 
00012 Apache License Usage
00013 
00014 Alternatively, this file may be used under the Apache License, Version 2.0 (the 
00015 "Apache License"); you may not use this file except in compliance with the 
00016 Apache License. You may obtain a copy of the Apache License at 
00017 http://www.apache.org/licenses/LICENSE-2.0.
00018 
00019 Unless required by applicable law or agreed to in writing, software distributed
00020 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
00021 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
00022 the specific language governing permissions and limitations under the License.
00023 
00024   Version: <VERSION>  Build: <BUILDNUMBER>
00025   Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
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                         // Read extra characters in temp buffer.
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 之旅