1 Star 0 Fork 32

bysl/CM-Server

forked from 留天下/CM-Server 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tool.h 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
留天下 提交于 2019-02-22 13:22 . net redo done!
#ifndef TOOL_H
#define TOOL_H
#include<string>
#include<sstream>
#include<atomic>
#include<mutex>
#define CLASS_ESSENTAIL(__TYPE__) \
private: \
__TYPE__(){} \
public: \
virtual ~__TYPE__(){}
#define Inherit(__TYPE__) :public __TYPE__
//单实例设计模式基本参数
#define SINGLE_ATTRIBUTES(__TYPE__) \
private: \
static __TYPE__* m_instance; \
static std::atomic<__TYPE__*> m_load; \
static std::mutex m_mutex
//定义单实例设计模式的基本参数
#define DEFINE_SINGLE_ATTRIBUTES(__TYPE__) \
std::atomic<__TYPE__*> __TYPE__::m_load; \
std::mutex __TYPE__::m_mutex; \
__TYPE__* __TYPE__::m_instance = nullptr
//获取单实例设计模式的实例对象
#define GET_SINGLE_OBJECT(__TYPE__) \
public: \
static __TYPE__* getInstance() \
{ \
m_instance = m_load.load(std::memory_order_relaxed); \
std::atomic_thread_fence(std::memory_order_acquire); \
if (m_instance == nullptr) \
{ \
std::lock_guard<std::mutex> lock(m_mutex); \
m_instance = m_load.load(std::memory_order_relaxed); \
if (m_instance == nullptr) \
{ \
m_instance = new __TYPE__; \
std::atomic_thread_fence(std::memory_order_release); \
m_load.store(m_instance, std::memory_order_release); \
} \
} \
return m_instance; \
}
#define GettingAndSetting(varType,varName,funName) \
protected: varType varName; \
public: virtual varType get##funName(void){return varName;} \
public: virtual void set##funName(varType var) {varName=var;}
#define PROPERTY__REF(varType, varName, funName) \
protected: varType varName; \
public: virtual varType& get##funName(void){return varName;} \
public: virtual void set##funName(const varType& var){varName=var;}
#define NTS numberToString
std::string numberToString(float number);
bool isNum(const std::string & number);
#endif // TOOL_H
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/bysl/CM-Server.git
git@gitee.com:bysl/CM-Server.git
bysl
CM-Server
CM-Server
master

搜索帮助