More Related Content
More from Tatsuya Ishikawa
More from Tatsuya Ishikawa (16)
私とC++ in 例外安全day
- 34. private:
static T* __stdcall NewCore(unsigned int size)
{
return new T[size];
}
static void __stdcall DeleteCore(T* ptr)
{
if (ptr)
{
delete[] ptr;
}
}
};
- 40. template <typename Ret, int fileNo, int lineNo>
struct AOPLog {
//DLL関数の型
typedef Ret (__stdcall *FuncType)();
//ログ
static std::string& Log()
{ static std::string log; return log; }
//DLL関数
static FuncType& Func()
{ static FuncType func; return func; }
//ログ出力と呼び出し
static Ret __stdcall Invoke()
{ Print(Log()); return Func(); }
};
- 41. //戻り値voidで特殊化
template <int fileNo, int lineNo>
struct AOPLog<void, fileNo, lineNo> {
typedef void(__stdcall *FuncType)();
static std::string& Log()
{ static std::string log; return log; }
static FuncType& Func()
{ static FuncType func; return func; }
static void __stdcall Invoke()
{ Print(Log()); Func(); }
};
- 42. //ログ入り関数ロード
template<int fileNo, int lineNo, typename Ret>
void MakeLog(HMODULE h,
Ret (__stdcall *&func)(), LPCSTR name)
{
typedef AOPLog<Ret, fileNo, lineNo> T;
if (s_logMode) {
T::Func() =
(T::FuncType)::GetProcAddress(h,name);
T::Log() = funcName;
func = T::Invoke;
} else {
func = (T::FuncType)::GetProcAddress(h,name);
}
}