00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef SIM_FOUNDATION_HOOK_HOOK_UTIL_H
00038 #define SIM_FOUNDATION_HOOK_HOOK_UTIL_H
00039
00040 #include "Sim/Foundation/Hook/Hook.h"
00041
00042 namespace Onikiri
00043 {
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 template <
00056 typename ClassType,
00057 typename HookPointType
00058 >
00059 NOINLINE void HookEntryBody(
00060 ClassType* obj,
00061 void (ClassType::*MethodPtr)(),
00062 HookPointType* hookPoint
00063 ){
00064 hookPoint->Trigger(obj, HookType::HOOK_BEFORE);
00065
00066 if( !hookPoint->HasAround() ) {
00067
00068 (obj->*MethodPtr)();
00069 } else {
00070
00071 hookPoint->Trigger(obj, HookType::HOOK_AROUND);
00072 }
00073
00074 hookPoint->Trigger(obj, HookType::HOOK_AFTER);
00075 }
00076
00077
00078 template <
00079 typename ClassType,
00080 typename HookPointType
00081 >
00082 INLINE void HookEntry(
00083 ClassType* obj,
00084 void (ClassType::*MethodPtr)(),
00085 HookPointType* hookPoint
00086 ){
00087 if( hookPoint->IsAnyHookRegistered() ){
00088 HookEntryBody( obj, MethodPtr, hookPoint );
00089 }
00090 else{
00091
00092 (obj->*MethodPtr)();
00093 }
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 template <
00110 typename ClassType,
00111 typename HookPointType,
00112 typename HookParamType
00113 >
00114 NOINLINE void HookEntryBody(
00115 ClassType* obj,
00116 void (ClassType::*MethodPtr)( HookParamType* param ),
00117 HookPointType* hookPoint,
00118 HookParamType* hookParam
00119 ){
00120 hookPoint->Trigger(obj, hookParam, HookType::HOOK_BEFORE);
00121
00122 if( !hookPoint->HasAround() ) {
00123
00124 (obj->*MethodPtr)(hookParam);
00125 } else {
00126
00127 hookPoint->Trigger(obj, hookParam, HookType::HOOK_AROUND);
00128 }
00129
00130 hookPoint->Trigger(obj, hookParam, HookType::HOOK_AFTER);
00131 }
00132
00133 template <
00134 typename ClassType,
00135 typename HookPointType,
00136 typename HookParamType
00137 >
00138 INLINE void HookEntry(
00139 ClassType* obj,
00140 void (ClassType::*MethodPtr)( HookParamType* param ),
00141 HookPointType* hookPoint,
00142 HookParamType* hookParam
00143 ){
00144 if( hookPoint->IsAnyHookRegistered() ){
00145 HookEntryBody( obj, MethodPtr, hookPoint, hookParam );
00146 }
00147 else{
00148
00149 (obj->*MethodPtr)(hookParam);
00150 }
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 template <
00166 typename ClassType,
00167 typename HookPointType
00168 >
00169 NOINLINE void HookEntryBody(
00170 ClassType* obj,
00171 void (ClassType::*MethodPtr)( OpIterator op ),
00172 HookPointType* hookPoint,
00173 OpIterator op
00174 ){
00175 hookPoint->Trigger( op, obj, HookType::HOOK_BEFORE);
00176
00177 if( !hookPoint->HasAround() ) {
00178
00179 (obj->*MethodPtr)( op );
00180 } else {
00181
00182 hookPoint->Trigger( op, obj, HookType::HOOK_AROUND);
00183 }
00184
00185 hookPoint->Trigger( op, obj, HookType::HOOK_AFTER);
00186 }
00187
00188 template <
00189 typename ClassType,
00190 typename HookPointType
00191 >
00192 INLINE void HookEntry(
00193 ClassType* obj,
00194 void (ClassType::*MethodPtr)( OpIterator op ),
00195 HookPointType* hookPoint,
00196 OpIterator op
00197 ){
00198 if( hookPoint->IsAnyHookRegistered() ){
00199 HookEntryBody( obj, MethodPtr, hookPoint, op );
00200 }
00201 else{
00202
00203 (obj->*MethodPtr)( op );
00204 }
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 template <
00222 typename ClassType,
00223 typename HookPointType,
00224 typename Parameter
00225 >
00226 NOINLINE void HookEntryBody(
00227 ClassType* obj,
00228 void (ClassType::*MethodPtr)( OpIterator op, Parameter param ),
00229 HookPointType* hookPoint,
00230 OpIterator op,
00231 Parameter param
00232 ){
00233 hookPoint->Trigger( op, obj, param, HookType::HOOK_BEFORE);
00234
00235 if( !hookPoint->HasAround() ) {
00236
00237 (obj->*MethodPtr)( op, param );
00238 } else {
00239
00240 hookPoint->Trigger( op, obj, param, HookType::HOOK_AROUND);
00241 }
00242
00243 hookPoint->Trigger( op, obj, param, HookType::HOOK_AFTER);
00244 }
00245
00246 template <
00247 typename ClassType,
00248 typename HookPointType,
00249 typename Parameter
00250 >
00251 INLINE void HookEntry(
00252 ClassType* obj,
00253 void (ClassType::*MethodPtr)( OpIterator op, Parameter param ),
00254 HookPointType* hookPoint,
00255 OpIterator op,
00256 Parameter param
00257 ){
00258 if( hookPoint->IsAnyHookRegistered() ){
00259 HookEntryBody( obj, MethodPtr, hookPoint, op, param );
00260 }
00261 else{
00262
00263 (obj->*MethodPtr)( op, param );
00264 }
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 template < typename Caller, typename HookPoint >
00295 INLINE bool HookSectionBefore( Caller* caller, HookPoint* hookPoint )
00296 {
00297 hookPoint->Trigger( caller, HookType::HOOK_BEFORE );
00298 if( hookPoint->HasAround() ){
00299 HookSectionAfter( caller, hookPoint );
00300 return true;
00301 }
00302 else{
00303 return false;
00304 }
00305 }
00306
00307 template < typename Caller, typename HookPoint >
00308 INLINE bool HookSectionAfter( Caller* caller, HookPoint* hookPoint )
00309 {
00310 if( hookPoint->HasAround() ){
00311 hookPoint->Trigger( caller, HookType::HOOK_AROUND );
00312 }
00313
00314 hookPoint->Trigger( caller, HookType::HOOK_AFTER );
00315 return true;
00316 }
00317
00318 #define HOOK_SECTION( hookPoint ) \
00319 for( \
00320 bool onikiri_exitSection = HookSectionBefore( this, &hookPoint ); \
00321 !onikiri_exitSection; \
00322 onikiri_exitSection = HookSectionAfter( this, &hookPoint ) \
00323 )
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336 template < typename Caller, typename HookPoint >
00337 INLINE bool HookSectionBefore( Caller* caller, HookPoint* hookPoint, OpIterator op )
00338 {
00339 hookPoint->Trigger( op, caller, HookType::HOOK_BEFORE );
00340 if( hookPoint->HasAround() ){
00341 HookSectionAfter( caller, hookPoint, op );
00342 return true;
00343 }
00344 else{
00345 return false;
00346 }
00347 }
00348
00349 template < typename Caller, typename HookPoint >
00350 INLINE bool HookSectionAfter( Caller* caller, HookPoint* hookPoint, OpIterator op )
00351 {
00352 if( hookPoint->HasAround() ){
00353 hookPoint->Trigger( op, caller, HookType::HOOK_AROUND );
00354 }
00355
00356 hookPoint->Trigger( op, caller, HookType::HOOK_AFTER );
00357 return true;
00358 }
00359
00360 #define HOOK_SECTION_OP( hookPoint, op ) \
00361 for( \
00362 bool onikiri_exitSection = HookSectionBefore( this, &hookPoint, op ); \
00363 !onikiri_exitSection; \
00364 onikiri_exitSection = HookSectionAfter( this, &hookPoint, op ) \
00365 )
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 template < typename Caller, typename HookPoint, typename Parameter >
00378 INLINE bool HookSectionBefore( Caller* caller, HookPoint* hookPoint, Parameter* param )
00379 {
00380 hookPoint->Trigger( caller, param, HookType::HOOK_BEFORE );
00381 if( hookPoint->HasAround() ){
00382 HookSectionAfter( caller, hookPoint, param );
00383 return true;
00384 }
00385 else{
00386 return false;
00387 }
00388 }
00389
00390 template < typename Caller, typename HookPoint, typename Parameter >
00391 INLINE bool HookSectionAfter( Caller* caller, HookPoint* hookPoint, Parameter* param )
00392 {
00393 if( hookPoint->HasAround() ){
00394 hookPoint->Trigger( caller, param, HookType::HOOK_AROUND );
00395 }
00396
00397 hookPoint->Trigger( caller, param, HookType::HOOK_AFTER );
00398 return true;
00399 }
00400
00401 #define HOOK_SECTION_PARAM( hookPoint, param ) \
00402 for( \
00403 bool onikiri_exitSection = HookSectionBefore( this, &hookPoint, ¶m ); \
00404 !onikiri_exitSection; \
00405 onikiri_exitSection = HookSectionAfter( this, &hookPoint, ¶m ) \
00406 )
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 template < typename Caller, typename HookPoint, typename Parameter >
00418 INLINE bool HookSectionBefore( Caller* caller, HookPoint* hookPoint, OpIterator op, Parameter* param )
00419 {
00420 hookPoint->Trigger( op, caller, param, HookType::HOOK_BEFORE );
00421 if( hookPoint->HasAround() ){
00422 HookSectionAfter( caller, hookPoint, op, param );
00423 return true;
00424 }
00425 else{
00426 return false;
00427 }
00428 }
00429
00430 template < typename Caller, typename HookPoint, typename Parameter >
00431 INLINE bool HookSectionAfter( Caller* caller, HookPoint* hookPoint, OpIterator op, Parameter* param )
00432 {
00433 if( hookPoint->HasAround() ){
00434 hookPoint->Trigger( op, caller, param, HookType::HOOK_AROUND );
00435 }
00436
00437 hookPoint->Trigger( op, caller, param, HookType::HOOK_AFTER );
00438 return true;
00439 }
00440
00441 #define HOOK_SECTION_OP_PARAM( hookPoint, op, param ) \
00442 for( \
00443 bool onikiri_exitSection = HookSectionBefore( this, &hookPoint, op, ¶m ); \
00444 !onikiri_exitSection; \
00445 onikiri_exitSection = HookSectionAfter( this, &hookPoint, op, ¶m ) \
00446 )
00447
00448 }
00449
00450 #endif
00451