#pragma execution_character_set("utf-8") #pragma once #include #include "Data.h" class DataFactory { public: static DataFactory * GetInstance() { if(!m_pInstance) { m_mutex.lock(); if(!m_pInstance) { m_pInstance = new DataFactory(); } m_mutex.unlock(); } return m_pInstance; } // 根据设备类型建造不同的设备 static Data *createData(int type); private: DataFactory(){}; private: static DataFactory *m_pInstance; static std::mutex m_mutex; private: // 垃圾回收类,它的唯一工作就是在析构函数中删除DeviceFactory的实例 class Garbo { public: ~Garbo() { if (DataFactory::m_pInstance) { delete DataFactory::m_pInstance; } } }; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数 static Garbo m_Garbo; };