include/AK/Plugin/PluginServices/AkMixerInputMap.h
説明を見る。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
00028 #ifndef _AK_MIXERINPUTMAP_H_
00029 #define _AK_MIXERINPUTMAP_H_
00030
00031 #include <AK/SoundEngine/Common/AkTypes.h>
00032
00033 #include <AK/SoundEngine/Common/IAkPluginMemAlloc.h>
00034 #include <AK/Tools/Common/AkArray.h>
00035 #include <AK/SoundEngine/Common/IAkPlugin.h>
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 template <class USER_DATA>
00063 struct AkInputMapSlot
00064 {
00065 AK::IAkMixerInputContext * pContext;
00066 USER_DATA * pUserData;
00067
00068 AkInputMapSlot() : pContext( NULL ), pUserData( NULL ) {}
00069 bool operator ==(const AkInputMapSlot& in_Op) const { return ( pContext == in_Op.pContext ); }
00070 };
00071
00072
00073
00074 class AkPluginArrayAllocator
00075 {
00076 public:
00077 AkForceInline AkPluginArrayAllocator() : m_pAllocator( NULL ) {}
00078 AkForceInline void Init( AK::IAkPluginMemAlloc * in_pAllocator ) { m_pAllocator = in_pAllocator; }
00079 protected:
00080 AkForceInline void * Alloc( size_t in_uSize ) { AKASSERT( m_pAllocator || !"Allocator not set. Did you forget to call AkMixerInputMap::Init()?" ); return AK_PLUGIN_ALLOC( m_pAllocator, in_uSize ); }
00081 AkForceInline void Free( void * in_pAddress ) { AKASSERT( m_pAllocator || !"Allocator not set. Did you forget to call AkMixerInputMap::Init()?" ); AK_PLUGIN_FREE( m_pAllocator, in_pAddress ); }
00082 AkForceInline AK::IAkPluginMemAlloc * GetAllocator() { return m_pAllocator; }
00083 private:
00084 AK::IAkPluginMemAlloc * m_pAllocator;
00085 };
00086
00087
00088 template <class USER_DATA>
00089 class AkMixerInputMap : public AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>
00090 {
00091 public:
00092 typedef AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1> BaseClass;
00093
00094
00095 USER_DATA * Exists( AK::IAkMixerInputContext * in_pInput )
00096 {
00097 typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput );
00098 return ( it != BaseClass::End() ) ? (*it).pUserData : NULL;
00099 }
00100
00101
00102 USER_DATA * AddInput( AK::IAkMixerInputContext * in_pInput )
00103 {
00104 typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput );
00105 if ( it != BaseClass::End() )
00106 return (*it).pUserData;
00107 else
00108 {
00109 AkInputMapSlot<USER_DATA> * pSlot = AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::AddLast();
00110 if ( pSlot )
00111 {
00112 pSlot->pUserData = AK_PLUGIN_NEW( AkPluginArrayAllocator::GetAllocator(), USER_DATA );
00113 if ( pSlot->pUserData )
00114 {
00115 pSlot->pContext = in_pInput;
00116 return pSlot->pUserData;
00117 }
00118 BaseClass::RemoveLast();
00119 }
00120 }
00121 return NULL;
00122 }
00123
00124
00125 bool RemoveInput( AK::IAkMixerInputContext * in_pInput )
00126 {
00127 typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = FindEx( in_pInput );
00128 if ( it != BaseClass::End() )
00129 {
00130 AKASSERT( (*it).pUserData );
00131 AK_PLUGIN_DELETE( AkPluginArrayAllocator::GetAllocator(), (*it).pUserData );
00132 BaseClass::EraseSwap( it );
00133 return true;
00134 }
00135 return false;
00136 }
00137
00138
00139 void Term()
00140 {
00141 if ( BaseClass::m_pItems )
00142 {
00143 RemoveAll();
00144 AkPluginArrayAllocator::Free( BaseClass::m_pItems );
00145 BaseClass::m_pItems = 0;
00146 BaseClass::m_ulReserved = 0;
00147 }
00148 }
00149
00150
00151 typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator FindEx( AK::IAkMixerInputContext * in_pInput ) const
00152 {
00153 AkInputMapSlot<USER_DATA> mapSlot;
00154 mapSlot.pContext = in_pInput;
00155 return BaseClass::FindEx( mapSlot );
00156 }
00157
00158
00159 void RemoveAll()
00160 {
00161 for ( typename AkArray<AkInputMapSlot<USER_DATA>, const AkInputMapSlot<USER_DATA>&, AkPluginArrayAllocator, 1>::Iterator it = BaseClass::Begin(), itEnd = BaseClass::End(); it != itEnd; ++it )
00162 {
00163 AKASSERT( (*it).pUserData );
00164 AK_PLUGIN_DELETE( AkPluginArrayAllocator::GetAllocator(), (*it).pUserData );
00165 (*it).~AkInputMapSlot();
00166 }
00167 BaseClass::m_uLength = 0;
00168 }
00169 };
00170
00171 #endif // _AK_MIXERINPUTMAP_H_
あなたのプロジェクトについて教えてください。ご不明な点はありませんか。
プロジェクトを登録していただくことで、ご利用開始のサポートをいたします。
Wwiseからはじめよう