|
1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Thin callback wrapper |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // include guard for the whole file content |
|
22 #ifndef __TSHWCALLBACK_H__ |
|
23 #define __TSHWCALLBACK_H__ |
|
24 |
|
25 /** |
|
26 * Helper class to construct a TCallBack from any |
|
27 * public non static TInt (*method)() of a class |
|
28 * Usage: |
|
29 * TShwCallBack< %ClassName%, %MethodName% >( |
|
30 * %ClassPointer% ) |
|
31 * Example: |
|
32 * TShwCallBack< CShwEngineImpl, DoStartL >( |
|
33 * this ); |
|
34 */ |
|
35 template< class Object, TInt (Object::*Method)() > |
|
36 NONSHARABLE_CLASS( TShwCallBack ) : public TCallBack |
|
37 { |
|
38 public: |
|
39 /** |
|
40 * Constructor. |
|
41 * @param aInstance the object instance of the class |
|
42 */ |
|
43 inline TShwCallBack( Object* aInstance ) |
|
44 : TCallBack( &DelegateL, aInstance ) |
|
45 {} |
|
46 |
|
47 private: |
|
48 /** |
|
49 * The callback delegator. Inlined as we dont want |
|
50 * extra method to be created, static so that base |
|
51 * class can call it without pointer to this. |
|
52 * @param aInstance the instance to call back |
|
53 * @return the return value for the TCallBack |
|
54 */ |
|
55 inline static TInt DelegateL( TAny* aInstance ) |
|
56 { |
|
57 // Dispatch the call to the real objects method |
|
58 return ( static_cast< Object* >( aInstance )->*Method )(); |
|
59 } |
|
60 }; |
|
61 |
|
62 |
|
63 #endif // __TSHWCALLBACK_H__ |