Commit eebca79d authored by captainwong's avatar captainwong

fix grammer false

parent 0baf541c
#pragma once
#include "C:/Global/LocalLock.h"
#include "C:/Global/mtverify.h"
#include "C:/Global/FileOper.h"
#include "C:/Global/Log.h"
#define LOG CLog::WriteLog
#define LOGA CLog::WriteLogA
#define LOGW CLog::WriteLogW
class LogFunction {
private:
const char* _func_name;
public:
LogFunction(const char* func_name) : _func_name(func_name) { LOGA("%s in\n", _func_name); }
~LogFunction() { LOGA("%s out\n", _func_name); }
};
#define LOG_FUNCTION(func_name) LogFunction _log_function_object(func_name);
#define LOG_FUNCTION_AUTO LOG_FUNCTION(__FUNCTION__)
#include "C:/Global/MyWSAError.h"
#include "c:/Global/observer_macro.h"
#define NAMESPACE_END };
#define DECLARE_UNCOPYABLE(classname) \
private:\
classname(const classname&) {}\
classname& operator=(const classname&) {}
// singleton
#define DECLARE_SINGLETON(class_name) \
private: \
class_name(); \
static class_name* m_pInstance; \
static CLock m_lock4Instance; \
public: \
static class_name* GetInstance() { \
m_lock4Instance.Lock(); \
if (m_pInstance == NULL){ \
static class_name obj; \
m_pInstance = &obj; \
} \
m_lock4Instance.UnLock(); \
return m_pInstance; \
}
#define IMPLEMENT_SINGLETON(class_name) \
class_name* class_name::m_pInstance = NULL; \
CLock class_name::m_lock4Instance;
// getter & setter
#define DECLARE_GETTER(type, val) \
type get##val() const { \
return val; \
}
#define DECLARE_SETTER(type, val) \
void set##val(type param) { \
val = param;\
}
#define DEALARE_GETTER_SETTER(type, val) \
DECLARE_GETTER(type, val) \
DECLARE_SETTER(type, val)
#define DEALARE_GETTER_SETTER_INT(val) \
DECLARE_GETTER(int, val) \
DECLARE_SETTER(int, val)
#define DECLARE_GETTER_STRING(val) \
const wchar_t* get##val() const { \
return val; \
}
#define DECLARE_SETTER_STRING(val) \
void set##val(const wchar_t* param) { \
if (param) { \
int len = wcslen(param); \
if (val) { delete[] val; } \
val = new wchar_t[len + 1]; \
wcscpy_s(val, len + 1, param); \
} else { \
if (val) { delete[] val; } \
val = new wchar_t[1]; \
val[0] = 0; \
} \
}
#define DECLARE_GETTER_SETTER_STRING(val) \
DECLARE_GETTER_STRING(val); \
DECLARE_SETTER_STRING(val);
#pragma once
#include "C:/Global/LocalLock.h"
#include "C:/Global/mtverify.h"
#include "C:/Global/FileOper.h"
#include "C:/Global/Log.h"
#define LOG CLog::WriteLog
#define LOGA CLog::WriteLogA
#define LOGW CLog::WriteLogW
class LogFunction {
private:
const char* _func_name;
public:
LogFunction(const char* func_name) : _func_name(func_name) { LOGA("%s in\n", _func_name); }
~LogFunction() { LOGA("%s out\n", _func_name); }
};
#define LOG_FUNCTION(func_name) LogFunction _log_function_object(func_name);
#define AUTO_LOG_FUNCTION LOG_FUNCTION(__FUNCTION__)
#include "C:/Global/MyWSAError.h"
#include "c:/Global/observer_macro.h"
#define NAMESPACE_END };
#define DECLARE_UNCOPYABLE(classname) \
private:\
classname(const classname&) {}\
classname& operator=(const classname&) {}
// singleton
#define DECLARE_SINGLETON(class_name) \
private: \
class_name(); \
static class_name* m_pInstance; \
static CLock m_lock4Instance; \
public: \
static class_name* GetInstance() { \
m_lock4Instance.Lock(); \
if (m_pInstance == NULL){ \
static class_name obj; \
m_pInstance = &obj; \
} \
m_lock4Instance.UnLock(); \
return m_pInstance; \
}
#define IMPLEMENT_SINGLETON(class_name) \
class_name* class_name::m_pInstance = NULL; \
CLock class_name::m_lock4Instance;
// getter & setter
#define DECLARE_GETTER(type, val) \
type get##val() const { \
return val; \
}
#define DECLARE_SETTER(type, val) \
void set##val(type param) { \
val = param;\
}
#define DECLARE_GETTER_SETTER(type, val) \
DECLARE_GETTER(type, val) \
DECLARE_SETTER(type, val)
#define DECLARE_GETTER_SETTER_INT(val) \
DECLARE_GETTER(int, val) \
DECLARE_SETTER(int, val)
#define DECLARE_GETTER_STRING(val) \
const wchar_t* get##val() const { \
return val; \
}
#define DECLARE_SETTER_STRING(val) \
void set##val(const wchar_t* param) { \
if (param) { \
int len = wcslen(param); \
if (val) { delete[] val; } \
val = new wchar_t[len + 1]; \
wcscpy_s(val, len + 1, param); \
} else { \
if (val) { delete[] val; } \
val = new wchar_t[1]; \
val[0] = 0; \
} \
}
#define DECLARE_GETTER_SETTER_STRING(val) \
DECLARE_GETTER_STRING(val); \
DECLARE_SETTER_STRING(val);
#define INITIALIZE_STRING(val) { val = new wchar_t[1]; val[0] = 0; }
\ No newline at end of file
// place this macro in your class's header file, in your class's definition
#define DECLARE_OBSERVER(callback, param_type) \
protected: \
typedef callback _callback; \
typedef const param_type _param_type; \
typedef struct callback##Info { \
DECLARE_UNCOPYABLE(callback##Info) \
public: \
callback##Info() : _udata(NULL), _on_result(NULL) {} \
callback##Info(void* udata, _callback on_result) : _udata(udata), _on_result(on_result) {} \
void* _udata; \
_callback _on_result; \
}_callbackInfo; \
std::list<_callbackInfo *> _observerList; \
CLock _lock4ObserverList; \
public: \
void RegisterObserver(void* udata, callback cb); \
void UnRegisterObserver(void* udata); \
void NotifyObservers(_param_type param);
// place this macro in your class's cpp file
#define IMPLEMENT_OBSERVER(class_name) \
void class_name::RegisterObserver(void* udata, _callback cb) \
{ \
LOG_FUNCTION_AUTO; \
_lock4ObserverList.Lock(); \
_callbackInfo *observer = new _callbackInfo(udata, cb); \
_observerList.push_back(observer); \
_lock4ObserverList.UnLock(); \
} \
void class_name::UnRegisterObserver(void* udata) \
{ \
LOG_FUNCTION_AUTO; \
_lock4ObserverList.Lock(); \
std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \
while (iter != _observerList.end()) { \
_callbackInfo* observer = *iter; \
if (observer->_udata == udata) { \
delete observer; \
_observerList.erase(iter); \
break; \
} \
iter++; \
} \
_lock4ObserverList.UnLock(); \
} \
void class_name::NotifyObservers(_param_type param) \
{ \
LOG_FUNCTION_AUTO; \
_lock4ObserverList.Lock(); \
std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \
while (iter != _observerList.end()) { \
_callbackInfo * observer = *iter++; \
observer->_on_result(observer->_udata, param); \
} \
_lock4ObserverList.UnLock(); \
}
// place this macro in your class's destruct function.
#define DESTROY_OBSERVER \
{ \
std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \
while (iter != _observerList.end()) { \
_callbackInfo * observer = *iter++; \
delete observer; \
} \
_observerList.clear(); \
}
// place this macro in your class's header file, in your class's definition
#define DECLARE_OBSERVER(callback, param_type) \
protected: \
typedef callback _callback; \
typedef const param_type _param_type; \
typedef struct callback##Info { \
DECLARE_UNCOPYABLE(callback##Info) \
public: \
callback##Info() : _udata(NULL), _on_result(NULL) {} \
callback##Info(void* udata, _callback on_result) : _udata(udata), _on_result(on_result) {} \
void* _udata; \
_callback _on_result; \
}_callbackInfo; \
std::list<_callbackInfo *> _observerList; \
CLock _lock4ObserverList; \
public: \
void RegisterObserver(void* udata, callback cb); \
void UnRegisterObserver(void* udata); \
void NotifyObservers(_param_type param);
// place this macro in your class's cpp file
#define IMPLEMENT_OBSERVER(class_name) \
void class_name::RegisterObserver(void* udata, _callback cb) \
{ \
AUTO_LOG_FUNCTION; \
_lock4ObserverList.Lock(); \
_callbackInfo *observer = new _callbackInfo(udata, cb); \
_observerList.push_back(observer); \
_lock4ObserverList.UnLock(); \
} \
void class_name::UnRegisterObserver(void* udata) \
{ \
AUTO_LOG_FUNCTION; \
_lock4ObserverList.Lock(); \
std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \
while (iter != _observerList.end()) { \
_callbackInfo* observer = *iter; \
if (observer->_udata == udata) { \
delete observer; \
_observerList.erase(iter); \
break; \
} \
iter++; \
} \
_lock4ObserverList.UnLock(); \
} \
void class_name::NotifyObservers(_param_type param) \
{ \
AUTO_LOG_FUNCTION; \
_lock4ObserverList.Lock(); \
std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \
while (iter != _observerList.end()) { \
_callbackInfo * observer = *iter++; \
observer->_on_result(observer->_udata, param); \
} \
_lock4ObserverList.UnLock(); \
}
// place this macro in your class's destruct function.
#define DESTROY_OBSERVER \
{ \
AUTO_LOG_FUNCTION; \
std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \
while (iter != _observerList.end()) { \
_callbackInfo * observer = *iter++; \
delete observer; \
} \
_observerList.clear(); \
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment