// FTTSPtr - [2020-04-13 11:57:47]
#ifndef _FTTSPTR_H_
#define _FTTSPTR_H_

#include <stdio.h>
#include <stdlib.h>

/*
001BD412 FTTSPtr<CFTTRenderToTexture>::FTTSPtr(CFTTRenderToTexture*)
001BD440 FTTSPtr<CFTTRenderToTexture>::~FTTSPtr()
*/

template <typename T>
class FTTSPtr {
public:
  FTTSPtr(T* p) {
    pType_0 = p;
    if (p != nullptr) {
      // 001BD41C
      pRefCount_4 = new int;
      *pRefCount_4 = 0;

      (*pRefCount_4)++;
    } else {
      // loc_1BD434
      pRefCount_4 = nullptr;
    }
    // loc_1BD438
  };

  ~FTTSPtr() {
    if (pRefCount_4 != nullptr) {
      // 001BD448
      (*pRefCount_4)--;

      if (*pRefCount_4 == 0) {  //引用计数器为0, 说明要删除对象
        // 001BD450
        if (pType_0 != nullptr)
          delete pType_0;

        if (pRefCount_4 != nullptr)  //此处原始代码重复判断是否为空 Anderson
          delete pRefCount_4;
      }
    }
    // loc_1BD462
  };

  T* pType_0;
  int* pRefCount_4;  //引用计数器
};

#endif  //_FTTSPTR_H_