123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
-
- #ifndef _AK_MIXERINPUTMAP_H_
- #define _AK_MIXERINPUTMAP_H_
- #include <AK/SoundEngine/Common/AkTypes.h>
- #include <AK/SoundEngine/Common/IAkPluginMemAlloc.h>
- #include <AK/Tools/Common/AkArray.h>
- #include <AK/SoundEngine/Common/IAkPlugin.h>
- template <class KEY, class USER_DATA>
- struct AkInputMapSlot
- {
- KEY key;
- USER_DATA * pUserData;
- AkInputMapSlot() : key( NULL ), pUserData( NULL ) {}
- bool operator ==(const AkInputMapSlot& in_Op) const { return (key == in_Op.key); }
- };
- template <class KEY, class USER_DATA>
- class AkMixerInputMap : public AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>
- {
- public:
- typedef AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator> BaseClass;
-
- USER_DATA * Exists( KEY in_key )
- {
- typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator it = FindEx(in_key);
- return ( it != BaseClass::End() ) ? (*it).pUserData : NULL;
- }
-
- USER_DATA * AddInput(KEY in_key)
- {
- typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator it = FindEx(in_key);
- if ( it != BaseClass::End() )
- return (*it).pUserData;
- else
- {
- AkInputMapSlot<KEY, USER_DATA> * pSlot = AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::AddLast();
- if ( pSlot )
- {
- pSlot->pUserData = AK_PLUGIN_NEW( AkPluginArrayAllocator::GetAllocator(), USER_DATA );
- if ( pSlot->pUserData )
- {
- pSlot->key = in_key;
- return pSlot->pUserData;
- }
- BaseClass::RemoveLast();
- }
- }
- return NULL;
- }
-
- bool RemoveInput(KEY in_key)
- {
- typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator it = FindEx( in_key );
- if ( it != BaseClass::End() )
- {
- AKASSERT( (*it).pUserData );
- AK_PLUGIN_DELETE( AkPluginArrayAllocator::GetAllocator(), (*it).pUserData );
- BaseClass::EraseSwap( it );
- return true;
- }
- return false;
- }
-
- typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator EraseSwap(typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator& in_rIter)
- {
- if ((*in_rIter).pUserData)
- {
- AK_PLUGIN_DELETE(AkPluginArrayAllocator::GetAllocator(), (*in_rIter).pUserData);
- }
- return BaseClass::EraseSwap(in_rIter);
- }
-
- void Term()
- {
- if ( BaseClass::m_pItems )
- {
- RemoveAll();
- AkPluginArrayAllocator::Free( BaseClass::m_pItems );
- BaseClass::m_pItems = 0;
- BaseClass::m_ulReserved = 0;
- }
- }
-
- typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator FindEx( KEY in_key ) const
- {
- AkInputMapSlot<KEY, USER_DATA> mapSlot;
- mapSlot.key = in_key;
- return BaseClass::FindEx( mapSlot );
- }
-
- void RemoveAll()
- {
- for ( typename AkArray<AkInputMapSlot<KEY, USER_DATA>, const AkInputMapSlot<KEY, USER_DATA>&, AkPluginArrayAllocator>::Iterator it = BaseClass::Begin(), itEnd = BaseClass::End(); it != itEnd; ++it )
- {
- AKASSERT( (*it).pUserData );
- AK_PLUGIN_DELETE( AkPluginArrayAllocator::GetAllocator(), (*it).pUserData );
- (*it).~AkInputMapSlot();
- }
- BaseClass::m_uLength = 0;
- }
- };
- #endif
|