OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ | |
6 #define PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ | |
7 | |
8 #include <stddef.h> // For NULL. | |
9 | |
10 #include "ppapi/shared_impl/ppapi_shared_export.h" | |
11 | |
12 #define FOR_ALL_PPAPI_FUNCTION_APIS(F) \ | |
13 F(PPB_Instance_FunctionAPI) \ | |
14 F(ResourceCreationAPI) | |
15 | |
16 namespace ppapi { | |
17 | |
18 // Forward declare all the function APIs. | |
19 namespace thunk { | |
20 #define DECLARE_FUNCTION_CLASS(FUNCTIONS) class FUNCTIONS; | |
21 FOR_ALL_PPAPI_FUNCTION_APIS(DECLARE_FUNCTION_CLASS) | |
22 #undef DECLARE_FUNCTION_CLASS | |
23 } // namespace thunk | |
24 | |
25 class PPAPI_SHARED_EXPORT FunctionGroupBase { | |
26 public: | |
27 virtual ~FunctionGroupBase(); | |
28 | |
29 // Dynamic casting for this object. Returns the pointer to the given type if | |
30 // Inheritance-based dynamic casting for this object. Returns the pointer to | |
31 // the given type if it's supported. Derived classes override the functions | |
32 // they support to return the interface. | |
33 #define DEFINE_TYPE_GETTER(FUNCTIONS) \ | |
34 virtual thunk::FUNCTIONS* As##FUNCTIONS(); | |
35 FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_TYPE_GETTER) | |
36 #undef DEFINE_TYPE_GETTER | |
37 | |
38 // Template-based dynamic casting. See specializations below. | |
39 template <typename T> T* GetAs() { return NULL; } | |
40 }; | |
41 | |
42 // Template-based dynamic casting. These specializations forward to the | |
43 // AsXXX virtual functions to return whether the given type is supported. | |
44 #define DEFINE_FUNCTION_CAST(FUNCTIONS) \ | |
45 template<> inline thunk::FUNCTIONS* FunctionGroupBase::GetAs() { \ | |
46 return As##FUNCTIONS(); \ | |
47 } | |
48 FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_FUNCTION_CAST) | |
49 #undef DEFINE_FUNCTION_CAST | |
50 | |
51 } // namespace ppapi | |
52 | |
53 #endif // PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ | |
OLD | NEW |