| OLD | NEW |
| 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: |
| 19 virtual ~FunctionGroupBase() {} | 28 virtual ~FunctionGroupBase(); |
| 20 | 29 |
| 21 // 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 |
| 22 // it's supported. | 31 // Inheritance-based dynamic casting for this object. Returns the pointer to |
| 23 virtual thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI() { | 32 // the given type if it's supported. Derived classes override the functions |
| 24 return NULL; | 33 // they support to return the interface. |
| 25 } | 34 #define DEFINE_TYPE_GETTER(FUNCTIONS) \ |
| 26 virtual thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI() { | 35 virtual thunk::FUNCTIONS* As##FUNCTIONS(); |
| 27 return NULL; | 36 FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_TYPE_GETTER) |
| 28 } | 37 #undef DEFINE_TYPE_GETTER |
| 29 virtual thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() { | |
| 30 return NULL; | |
| 31 } | |
| 32 virtual thunk::ResourceCreationAPI* AsResourceCreation() { | |
| 33 return NULL; | |
| 34 } | |
| 35 | 38 |
| 39 // Template-based dynamic casting. See specializations below. |
| 36 template <typename T> T* GetAs() { return NULL; } | 40 template <typename T> T* GetAs() { return NULL; } |
| 37 }; | 41 }; |
| 38 | 42 |
| 39 template<> | 43 // Template-based dynamic casting. These specializations forward to the |
| 40 inline thunk::PPB_CharSet_FunctionAPI* FunctionGroupBase::GetAs() { | 44 // AsXXX virtual functions to return whether the given type is supported. |
| 41 return AsCharSet_FunctionAPI(); | 45 #define DEFINE_FUNCTION_CAST(FUNCTIONS) \ |
| 42 } | 46 template<> inline thunk::FUNCTIONS* FunctionGroupBase::GetAs() { \ |
| 43 template<> | 47 return As##FUNCTIONS(); \ |
| 44 inline thunk::PPB_CursorControl_FunctionAPI* FunctionGroupBase::GetAs() { | 48 } |
| 45 return AsCursorControl_FunctionAPI(); | 49 FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_FUNCTION_CAST) |
| 46 } | 50 #undef DEFINE_FUNCTION_CAST |
| 47 template<> | |
| 48 inline thunk::PPB_Font_FunctionAPI* FunctionGroupBase::GetAs() { | |
| 49 return AsFont_FunctionAPI(); | |
| 50 } | |
| 51 template<> | |
| 52 inline ppapi::thunk::ResourceCreationAPI* FunctionGroupBase::GetAs() { | |
| 53 return AsResourceCreation(); | |
| 54 } | |
| 55 | 51 |
| 56 } // namespace ppapi | 52 } // namespace ppapi |
| 57 | 53 |
| 58 #endif // PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ | 54 #endif // PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ |
| OLD | NEW |