pointerremap.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWSaveLoad *
  23. * *
  24. * $Archive:: /Commando/Code/wwsaveload/pointerremap.h $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 4/30/01 1:54p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef POINTERREMAP_H
  39. #define POINTERREMAP_H
  40. #ifdef _UNIX
  41. #include "osdep/osdep.h"
  42. #endif
  43. #include "always.h"
  44. #include "vector.h"
  45. class RefCountClass;
  46. class PointerRemapClass
  47. {
  48. public:
  49. PointerRemapClass(void);
  50. ~PointerRemapClass(void);
  51. void Reset(void);
  52. void Process(void);
  53. void Register_Pointer (void *old_pointer, void *new_pointer);
  54. #ifdef WWDEBUG
  55. void Request_Pointer_Remap (void **pointer_to_convert,const char * file,int line);
  56. void Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert,const char * file, int line);
  57. #else
  58. void Request_Pointer_Remap (void **pointer_to_convert);
  59. void Request_Ref_Counted_Pointer_Remap (RefCountClass **pointer_to_convert);
  60. #endif
  61. private:
  62. struct PtrPairStruct
  63. {
  64. PtrPairStruct(void) {}
  65. PtrPairStruct(void * oldptr,void * newptr) : OldPointer(oldptr),NewPointer(newptr) {}
  66. bool operator == (const PtrPairStruct & that) { return ((OldPointer == that.OldPointer) && (NewPointer == that.NewPointer)); }
  67. bool operator != (const PtrPairStruct & that) { return !(*this == that); }
  68. void * OldPointer;
  69. void * NewPointer;
  70. };
  71. struct PtrRemapStruct
  72. {
  73. PtrRemapStruct(void) {}
  74. bool operator == (const PtrRemapStruct & that) { return (PointerToRemap == that.PointerToRemap); }
  75. bool operator != (const PtrRemapStruct & that) { return !(*this == that); }
  76. void ** PointerToRemap;
  77. #ifdef WWDEBUG
  78. const char * File;
  79. int Line;
  80. #endif
  81. };
  82. void Process_Request_Table(DynamicVectorClass<PtrRemapStruct> & request_table,bool refcount);
  83. static int __cdecl ptr_pair_compare_function(void const * ptr1, void const * ptr2);
  84. static int __cdecl ptr_request_compare_function(void const * ptr1, void const * ptr2);
  85. /*
  86. ** Array of pointers associated with ID values to assist in swizzling.
  87. */
  88. DynamicVectorClass<PtrPairStruct> PointerPairTable;
  89. DynamicVectorClass<PtrRemapStruct> PointerRequestTable;
  90. DynamicVectorClass<PtrRemapStruct> RefCountRequestTable;
  91. };
  92. #endif