Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: ppapi/shared_impl/function_group_base.h

Issue 7082036: Convert more interfaces to the new thunk system. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ 5 #ifndef PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_
6 #define PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ 6 #define PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_
7 7
8 #include <stddef.h> // For NULL.
9
10 #define FOR_ALL_PPAPI_FUNCTION_APIS(F) \
11 F(PPB_CharSet_FunctionAPI) \
12 F(PPB_CursorControl_FunctionAPI) \
13 F(PPB_Find_FunctionAPI) \
14 F(PPB_Font_FunctionAPI) \
15 F(ResourceCreationAPI)
16
8 namespace ppapi { 17 namespace ppapi {
9 18
19 // Forward declare all the function APIs.
10 namespace thunk { 20 namespace thunk {
11 class PPB_CharSet_FunctionAPI; 21 #define DECLARE_FUNCTION_CLASS(FUNCTIONS) class FUNCTIONS;
12 class PPB_CursorControl_FunctionAPI; 22 FOR_ALL_PPAPI_FUNCTION_APIS(DECLARE_FUNCTION_CLASS)
13 class PPB_Font_FunctionAPI; 23 #undef DECLARE_FUNCTION_CLASS
14 class ResourceCreationAPI; 24 } // namespace thunk
15 }
16 25
17 class FunctionGroupBase { 26 class FunctionGroupBase {
18 public: 27 public:
28 virtual ~FunctionGroupBase();
29
19 // Dynamic casting for this object. Returns the pointer to the given type if 30 // Dynamic casting for this object. Returns the pointer to the given type if
20 // it's supported. 31 // Inheritance-based dynamic casting for this object. Returns the pointer to
21 virtual thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI() { 32 // the given type if it's supported. Derived classes override these AsXXX
piman 2011/06/01 00:41:08 nit: I can't quite parse this comment. Please fix
22 return NULL; 33 #define DEFINE_TYPE_GETTER(FUNCTIONS) \
23 } 34 virtual thunk::FUNCTIONS* As##FUNCTIONS();
24 virtual thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI() { 35 FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_TYPE_GETTER)
25 return NULL; 36 #undef DEFINE_TYPE_GETTER
26 }
27 virtual thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() {
28 return NULL;
29 }
30 virtual thunk::ResourceCreationAPI* AsResourceCreation() {
31 return NULL;
32 }
33 37
38 // Template-based dynamic casting. See specializations below.
34 template <typename T> T* GetAs() { return NULL; } 39 template <typename T> T* GetAs() { return NULL; }
35 }; 40 };
36 41
37 template<> 42 // Template-based dynamic casting. These specializatins forward to the
piman 2011/06/01 00:41:08 typo: specializations
38 inline thunk::PPB_CharSet_FunctionAPI* FunctionGroupBase::GetAs() { 43 // AsXXX virtual functions to return whether the given type is supported.
39 return AsCharSet_FunctionAPI(); 44 #define DEFINE_FUNCTION_CAST(FUNCTIONS) \
40 } 45 template<> inline thunk::FUNCTIONS* FunctionGroupBase::GetAs() { \
41 template<> 46 return As##FUNCTIONS(); \
42 inline thunk::PPB_CursorControl_FunctionAPI* FunctionGroupBase::GetAs() { 47 }
43 return AsCursorControl_FunctionAPI(); 48 FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_FUNCTION_CAST)
44 } 49 #undef DEFINE_FUNCTION_CAST
45 template<>
46 inline thunk::PPB_Font_FunctionAPI* FunctionGroupBase::GetAs() {
47 return AsFont_FunctionAPI();
48 }
49 template<>
50 inline ppapi::thunk::ResourceCreationAPI* FunctionGroupBase::GetAs() {
51 return AsResourceCreation();
52 }
53 50
54 } // namespace ppapi 51 } // namespace ppapi
55 52
56 #endif // PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ 53 #endif // PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698