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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# 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 ;
} ;