diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-01 02:12:55 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-01 02:12:55 +0000 |
commit | 1598e4a9f0fe3572b7f2bb9459c26ec208fcbf12 (patch) | |
tree | 10cae214da22b6ed0da1d7651fc068e046adc3cd /ppapi/shared_impl/function_group_base.h | |
parent | d0922eaaa02cf79caaa21f29613e4995fa0d2048 (diff) | |
download | chromium_src-1598e4a9f0fe3572b7f2bb9459c26ec208fcbf12.zip chromium_src-1598e4a9f0fe3572b7f2bb9459c26ec208fcbf12.tar.gz chromium_src-1598e4a9f0fe3572b7f2bb9459c26ec208fcbf12.tar.bz2 |
Convert more interfaces to the new thunk system. This goes up to and including
the ones starting with "F".
Since this adds a lot more interfaces, I added the macro stuff we used for the
old system to generate the various template specializations. This involded a
lot of renaming since the As* needs to match the name (I was previously leaving
off the "PPB_" part). I did other misc cleanup to the infrastructure.
Review URL: http://codereview.chromium.org/7082036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87415 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl/function_group_base.h')
-rw-r--r-- | ppapi/shared_impl/function_group_base.h | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/ppapi/shared_impl/function_group_base.h b/ppapi/shared_impl/function_group_base.h index 4f98396..6f828ae 100644 --- a/ppapi/shared_impl/function_group_base.h +++ b/ppapi/shared_impl/function_group_base.h @@ -5,53 +5,49 @@ #ifndef PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ #define PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ +#include <stddef.h> // For NULL. + +#define FOR_ALL_PPAPI_FUNCTION_APIS(F) \ + F(PPB_CharSet_FunctionAPI) \ + F(PPB_CursorControl_FunctionAPI) \ + F(PPB_Find_FunctionAPI) \ + F(PPB_Font_FunctionAPI) \ + F(ResourceCreationAPI) + namespace ppapi { +// Forward declare all the function APIs. namespace thunk { -class PPB_CharSet_FunctionAPI; -class PPB_CursorControl_FunctionAPI; -class PPB_Font_FunctionAPI; -class ResourceCreationAPI; -} +#define DECLARE_FUNCTION_CLASS(FUNCTIONS) class FUNCTIONS; +FOR_ALL_PPAPI_FUNCTION_APIS(DECLARE_FUNCTION_CLASS) +#undef DECLARE_FUNCTION_CLASS +} // namespace thunk class FunctionGroupBase { public: - virtual ~FunctionGroupBase() {} + virtual ~FunctionGroupBase(); // Dynamic casting for this object. Returns the pointer to the given type if - // it's supported. - virtual thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI() { - return NULL; - } - virtual thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI() { - return NULL; - } - virtual thunk::PPB_Font_FunctionAPI* AsFont_FunctionAPI() { - return NULL; - } - virtual thunk::ResourceCreationAPI* AsResourceCreation() { - return NULL; - } - + // Inheritance-based dynamic casting for this object. Returns the pointer to + // the given type if it's supported. Derived classes override the functions + // they support to return the interface. + #define DEFINE_TYPE_GETTER(FUNCTIONS) \ + virtual thunk::FUNCTIONS* As##FUNCTIONS(); + FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_TYPE_GETTER) + #undef DEFINE_TYPE_GETTER + + // Template-based dynamic casting. See specializations below. template <typename T> T* GetAs() { return NULL; } }; -template<> -inline thunk::PPB_CharSet_FunctionAPI* FunctionGroupBase::GetAs() { - return AsCharSet_FunctionAPI(); -} -template<> -inline thunk::PPB_CursorControl_FunctionAPI* FunctionGroupBase::GetAs() { - return AsCursorControl_FunctionAPI(); -} -template<> -inline thunk::PPB_Font_FunctionAPI* FunctionGroupBase::GetAs() { - return AsFont_FunctionAPI(); -} -template<> -inline ppapi::thunk::ResourceCreationAPI* FunctionGroupBase::GetAs() { - return AsResourceCreation(); -} +// Template-based dynamic casting. These specializations forward to the +// AsXXX virtual functions to return whether the given type is supported. +#define DEFINE_FUNCTION_CAST(FUNCTIONS) \ + template<> inline thunk::FUNCTIONS* FunctionGroupBase::GetAs() { \ + return As##FUNCTIONS(); \ + } +FOR_ALL_PPAPI_FUNCTION_APIS(DEFINE_FUNCTION_CAST) +#undef DEFINE_FUNCTION_CAST } // namespace ppapi |