Commit eebca79d authored by captainwong's avatar captainwong

fix grammer false

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