TTSPtr.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //TTSPtr - [2020-04-13 11:57:47]
  2. #ifndef _TTSPTR_H_
  3. #define _TTSPTR_H_
  4. #include "common.h"
  5. /*
  6. 0016779E TTSPtr<TNMVert>::TTSPtr()
  7. 001677BE TTSPtr<TNMVert>::TTSPtr(TNMVert*)
  8. 00166E50 TTSPtr<TNMVert>::~TTSPtr()
  9. 00167840 TTSPtr<TNMVert>::operator=(TTSPtr<TNMVert> const&)
  10. 00168AFC TTSPtr<TNMVert>::Release()
  11. struct TNMVert {
  12. int field_0;
  13. int field_4;
  14. };
  15. TTSPtr 智能指针
  16. 外部指针不能重复绑定,否则会崩溃
  17. */
  18. template <typename T>
  19. class TTSPtr {
  20. public:
  21. //0016779E
  22. TTSPtr() {
  23. pT_0 = 0;
  24. pRef_4 = new int;
  25. *pRef_4 = 0;
  26. ++(*pRef_4);
  27. };
  28. //-------------------------------------------------------------------------------------------------
  29. //001677BE
  30. TTSPtr(T *pNode) {
  31. pT_0 = pNode;
  32. pRef_4 = new int;
  33. *pRef_4 = 0;
  34. ++(*pRef_4);
  35. };
  36. //-------------------------------------------------------------------------------------------------
  37. //00166E50 TTSPtr_TNMVert
  38. ~TTSPtr() {
  39. int dr1 = *pRef_4;
  40. dr1--;
  41. *pRef_4 = dr1;
  42. if (dr1 == 0) {
  43. if (pT_0)
  44. delete pT_0;
  45. //loc_166E66
  46. if (pRef_4)
  47. delete pRef_4;
  48. }
  49. //loc_166E6E
  50. };
  51. //-------------------------------------------------------------------------------------------------
  52. //00167840
  53. TTSPtr<T> &operator=(TTSPtr<T> const &other) {
  54. if (this != &other) {
  55. --(*pRef_4);
  56. if (*pRef_4 == 0) {
  57. if (pT_0)
  58. delete pT_0;
  59. if (pRef_4)
  60. delete pRef_4;
  61. }
  62. //loc_167864
  63. this->pT_0 = other.pT_0;
  64. this->pRef_4 = other.pRef_4;
  65. ++(*other.pRef_4);
  66. }
  67. //loc_167872
  68. return *this;
  69. };
  70. //-------------------------------------------------------------------------------------------------
  71. inline bool operator==(TTSPtr<T> const &other) { //合理的猜测这个函数是被inline
  72. if (pT_0 == other.pT_0) {
  73. return true;
  74. }
  75. return false;
  76. }
  77. //-------------------------------------------------------------------------------------------------
  78. //00168AFC
  79. void Release() {
  80. --(*pRef_4);
  81. if (*pRef_4 == 0) {
  82. if (pT_0)
  83. delete pT_0;
  84. if (pRef_4)
  85. delete pRef_4;
  86. }
  87. //loc_168B1A
  88. pT_0 = nullptr;
  89. pRef_4 = new int;
  90. *pRef_4 = 0;
  91. ++(*pRef_4);
  92. };
  93. //-------------------------------------------------------------------------------------------------
  94. T *pT_0;
  95. int *pRef_4;
  96. };
  97. #endif //_TTSPTR_H_