You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.0 KiB
C

1 year ago
#pragma execution_character_set("utf-8")
#pragma once
#include <mutex>
#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;
};