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