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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/shared_impl/function_group_base.h
===================================================================
--- ppapi/shared_impl/function_group_base.h (revision 87260)
+++ ppapi/shared_impl/function_group_base.h (working copy)
@@ -5,51 +5,48 @@
#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();
+
// 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 these AsXXX
piman 2011/06/01 00:41:08 nit: I can't quite parse this comment. Please fix
+ #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 specializatins forward to the
piman 2011/06/01 00:41:08 typo: specializations
+// 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

Powered by Google App Engine
This is Rietveld 408576698