OROCHI
 
Loading...
Searching...
No Matches
GxCallback.h
Go to the documentation of this file.
1//===========================================================================
10//===========================================================================
11#pragma once
12
13GX_CORE_NAMESPACE_BEGIN()
14
15//===========================================================================
17//===========================================================================
19{
20 //-----------------------------------------------------------
22 //-----------------------------------------------------------
24public:
27 {
28 public:
29 //--------------------------------------------------------------
31 //--------------------------------------------------------------
33
35 typedef s32 (*STATIC_FUNC)( void*, void* );
37 typedef s32 (GxClassBaseRoot::*MEMBER_FUNC)( void*, void* );
38
40 enum class TYPE
41 {
42 INVALID,
43 STATIC,
44 CLASSMEMBER,
45 };
46
48 //--------------------------------------------------------------
50 //--------------------------------------------------------------
52
54 GxHandlerBase( void ) : _type(TYPE::INVALID), _pOwner(nullptr){}
55
56 protected:
58 GxHandlerBase( STATIC_FUNC pStaticFunction ) : _type(TYPE::STATIC), _pOwner(nullptr), _pStaticFunction(pStaticFunction) {}
60 GxHandlerBase( void* pOwner, MEMBER_FUNC pMemberFunction ) : _type(TYPE::CLASSMEMBER), _pOwner(pOwner), _pMemberFunction(pMemberFunction) {}
61 public:
63 virtual ~GxHandlerBase( void ) {}
64
66 GxHandlerBase( const GxHandlerBase& handler );
67
69 const GxHandlerBase& operator = (const GxHandlerBase& handler);
70
72 //--------------------------------------------------------------
74 //--------------------------------------------------------------
76
78 s32 invoke( void* pSource, void* pArgument ) const;
79
81 constexpr void clear( void ) { _type = TYPE::INVALID; _pOwner = nullptr; _pStaticFunction = nullptr; }
82
83 protected:
88 virtual s32 invokeInner(void* /*pSource*/, void* /*pArgument*/) const { return 0; }
89
91 //--------------------------------------------------------------
93 //--------------------------------------------------------------
95 protected:
98
99 union
100 {
101 GX_CHAR _dummy[8];
102 STATIC_FUNC _pStaticFunction;
103 MEMBER_FUNC _pMemberFunction;
104 };
105
107 };
108
109 class GxHandlerStatic;
110 template <class T> class GxHandlerClass;
111
113
115};
116
117//===========================================================================
119//===========================================================================
121{
122 //-----------------------------------------------------------
124 //-----------------------------------------------------------
126public:
130 ~GxHandlerStatic( void ) override {}
131
133 GxHandlerStatic( const GxHandlerStatic& handler ) : GxHandlerBase( handler ) {}
135 GxHandlerStatic& operator = (const GxHandlerStatic& handler) { GxHandlerBase::operator = (handler); return *this; }
136
138 //--------------------------------------------------------------
140 //--------------------------------------------------------------
142protected:
144 s32 invokeInner( void* pSource, void* pArgument ) const override;
145
147};
148
149//===========================================================================
151//===========================================================================
152template <class T>
154{
155 //-----------------------------------------------------------
157 //-----------------------------------------------------------
159public:
160 //-------------------------------------------------------------------------
164 //-------------------------------------------------------------------------
165 GxHandlerClass( T* pOwner, MEMBER_FUNC pMemberFunction ) : GxCallback::GxHandlerBase( pOwner, pMemberFunction ) {}
166
168 GxHandlerClass( const GxHandlerClass& handler ) : GxHandlerBase( handler ) {}
170 constexpr GxHandlerClass& operator = ( const GxHandlerClass& handler ) { GxHandlerBase::operator = (handler); return *this; }
171
173 //--------------------------------------------------------------
175 //--------------------------------------------------------------
177protected:
178 //-------------------------------------------------------------------------
183 //-------------------------------------------------------------------------
184 s32 invokeInner( void* pSource, void* pArgument ) const override
185 {
186 if( !_pOwner || !_pMemberFunction )
187 {
188 return 0;
189 }
190 return (static_cast<T*>(_pOwner)->*_pMemberFunction)( pSource, pArgument );
191 }
192
194};
195
196//===========================================================================
197// 関数定義作成マクロ
198//===========================================================================
200#define GX_CALLBACK_HANDLER_STATIC(__static_func__) \
201 GxCallback::GxHandlerStatic( static_cast<GxCallback::GxHandlerStatic::STATIC_FUNC>(__static_func__) )
202
204#define GX_CALLBACK_HANDLER_CLASS(__class__, __pOwner__, __func__ ) \
205 GxCallback::GxHandlerClass<__class__>( __pOwner__, (GxCallback::GxHandlerClass<__class__>::MEMBER_FUNC) &__class__::__func__ )
206// GxCallback::GxHandlerClass<__class__>( __pOwner__, static_cast<GxCallback::GxHandlerClass<__class__>::MEMBER_FUNC>(&__class__::__func__) )
207
208GX_CORE_NAMESPACE_END()
void GxTypedObject
その他
Definition GxDefine.h:213
@ INVALID
無効なビュー
ハンドラ基本クラス
Definition GxCallback.h:27
GxHandlerBase(void)
デフォルトコンストラクタ
Definition GxCallback.h:54
virtual s32 invokeInner(void *, void *) const
Definition GxCallback.h:88
const GxHandlerBase & operator=(const GxHandlerBase &handler)
代入演算子
Definition GxCallback.cpp:37
virtual ~GxHandlerBase(void)
デストラクタ
Definition GxCallback.h:63
constexpr void clear(void)
設定内容のをクリア
Definition GxCallback.h:81
s32(GxClassBaseRoot::*) MEMBER_FUNC(void *, void *)
クラスメンバ関数コールバック型
Definition GxCallback.h:37
GxHandlerBase(STATIC_FUNC pStaticFunction)
コンストラクタ
Definition GxCallback.h:58
TYPE _type
ハンドラタイプ
Definition GxCallback.h:96
GxTypedObject * _pOwner
コールバック関数を持つクラスのポインタ(スタティック関数の場合はnullptr)
Definition GxCallback.h:97
STATIC_FUNC _pStaticFunction
スタティック関数用コールバック関数
Definition GxCallback.h:102
s32(*) STATIC_FUNC(void *, void *)
スタティック関数コールバック型
Definition GxCallback.h:35
MEMBER_FUNC _pMemberFunction
クラスメンバ関数用コールバック関数
Definition GxCallback.h:103
TYPE
ハンドラの種類
Definition GxCallback.h:41
GxHandlerBase(void *pOwner, MEMBER_FUNC pMemberFunction)
コンストラクタ
Definition GxCallback.h:60
スタティック関数用ハンドラ
Definition GxCallback.h:154
constexpr GxHandlerClass & operator=(const GxHandlerClass &handler)
代入演算子
Definition GxCallback.h:170
GxHandlerClass(T *pOwner, MEMBER_FUNC pMemberFunction)
Definition GxCallback.h:165
s32 invokeInner(void *pSource, void *pArgument) const override
Definition GxCallback.h:184
GxHandlerClass(const GxHandlerClass &handler)
コピーコンストラクタ
Definition GxCallback.h:168
スタティック関数用ハンドラクラス
Definition GxCallback.h:121
~GxHandlerStatic(void) override
デストラクタ
Definition GxCallback.h:130
GxHandlerStatic(STATIC_FUNC pFunc)
コンストラクタ
Definition GxCallback.cpp:71
GxHandlerStatic(const GxHandlerStatic &handler)
コピーコンストラクタ
Definition GxCallback.h:133
GxHandlerStatic & operator=(const GxHandlerStatic &handler)
代入演算子
Definition GxCallback.h:135
s32 invokeInner(void *pSource, void *pArgument) const override
関数の実行
Definition GxCallback.cpp:82
コールバック管理クラス
Definition GxCallback.h:19
static const GxHandlerBase INVALID_CALLBACK
クラスメンバ関数用ハンドラ
Definition GxCallback.h:112
基底クラス
Definition GxBase.h:51