AkKeyDef.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*******************************************************************************
  2. The content of this file includes portions of the AUDIOKINETIC Wwise Technology
  3. released in source code form as part of the SDK installer package.
  4. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Apache License Usage
  10. Alternatively, this file may be used under the Apache License, Version 2.0 (the
  11. "Apache License"); you may not use this file except in compliance with the
  12. Apache License. You may obtain a copy of the Apache License at
  13. http://www.apache.org/licenses/LICENSE-2.0.
  14. Unless required by applicable law or agreed to in writing, software distributed
  15. under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  16. OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
  17. the specific language governing permissions and limitations under the License.
  18. Copyright (c) 2023 Audiokinetic Inc.
  19. *******************************************************************************/
  20. #ifndef _KEYDEF_H_
  21. #define _KEYDEF_H_
  22. #include <AK/Tools/Common/AkArray.h> //For ArrayPoolDefault
  23. template <class T_KEY, class T_ITEM>
  24. struct MapStruct
  25. {
  26. T_KEY key;
  27. T_ITEM item;
  28. bool operator ==(const MapStruct& in_Op) const
  29. {
  30. return ( (key == in_Op.key) /*&& (item == in_Op.item)*/ );
  31. }
  32. void Transfer(MapStruct<T_KEY, T_ITEM>& in_rSource)
  33. {
  34. key = in_rSource.key;
  35. item.Transfer(in_rSource.item); //transfer ownership of resources.
  36. }
  37. };
  38. // A helper struct that can be used as a T_ITEM in an CAkKeyArray, when you need to only preform a shallow copy
  39. // on the data that you are referencing. For example if you wanted to to use an AkArray type.
  40. // NOTE: AllocData() and FreeData() must be explicitly called, or else pData can be manually Alloc'd/Free'd.
  41. template < typename T_KEY, typename T_DATA, class T_ALLOC = ArrayPoolDefault >
  42. struct AkKeyDataPtrStruct: public T_ALLOC
  43. {
  44. AkKeyDataPtrStruct(): pData(NULL) {}
  45. AkKeyDataPtrStruct(T_KEY in_key): key(in_key), pData(NULL) {}
  46. T_KEY key;
  47. T_DATA* pData;
  48. bool operator ==(const AkKeyDataPtrStruct<T_KEY,T_DATA>& in_Op) const
  49. {
  50. return ( key == in_Op.key );
  51. }
  52. bool AllocData()
  53. {
  54. AKASSERT( !pData );
  55. pData = (T_DATA*) T_ALLOC::Alloc( sizeof( T_DATA ));
  56. if (pData)
  57. {
  58. AkPlacementNew( pData ) T_DATA();
  59. return true;
  60. }
  61. return false;
  62. }
  63. void FreeData()
  64. {
  65. if( pData )
  66. {
  67. pData->~T_DATA();
  68. T_ALLOC::Free(pData);
  69. pData = NULL;
  70. }
  71. }
  72. static AkForceInline T_KEY& Get( AkKeyDataPtrStruct<T_KEY, T_DATA>& in_val ) { return in_val.key; }
  73. };
  74. #endif //_KEYDEF_H_