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

Unified Diff: o3d/gpu_plugin/np_utils/np_class.h

Issue 196032: Replaced BaseNPObject with DefaultNPObject because...... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
« no previous file with comments | « o3d/gpu_plugin/np_utils/dynamic_np_object.cc ('k') | o3d/gpu_plugin/np_utils/np_class_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: o3d/gpu_plugin/np_utils/np_class.h
===================================================================
--- o3d/gpu_plugin/np_utils/np_class.h (revision 24889)
+++ o3d/gpu_plugin/np_utils/np_class.h (working copy)
@@ -2,134 +2,127 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef O3D_GPU_PLUGIN_NP_UTILS_BASE_NP_OBJECT_H_
-#define O3D_GPU_PLUGIN_NP_UTILS_BASE_NP_OBJECT_H_
+#ifndef O3D_GPU_PLUGIN_NP_UTILS_NP_CLASS_H_
+#define O3D_GPU_PLUGIN_NP_UTILS_NP_CLASS_H_
+#include "o3d/gpu_plugin/np_utils/np_object_pointer.h"
#include "third_party/npapi/bindings/npapi.h"
#include "third_party/npapi/bindings/npruntime.h"
+// This file implements NPGetClass<T>. This function returns an NPClass
+// that can be used to instantiate an NPObject subclass T. The NPClass
+// function pointers will invoke the most derived corresponding member
+// functions in T.
+
namespace o3d {
namespace gpu_plugin {
-// This class is a base class for NPObjects implemented in C++. It forwards
-// The NPObject calls through to virtual functions implemented by the subclass.
-class BaseNPObject : public NPObject {
- public:
- // Returns the NPClass for the concrete BaseNPObject subclass T.
- template <typename NPObjectType>
- static const NPClass* GetNPClass();
-
- NPP npp() const {
- return npp_;
- }
-
- // Override these in subclass.
- virtual void Invalidate();
-
- virtual bool HasMethod(NPIdentifier name);
-
- virtual bool Invoke(NPIdentifier name,
- const NPVariant* args,
- uint32_t num_args,
- NPVariant* result);
-
- virtual bool InvokeDefault(const NPVariant* args,
- uint32_t num_args,
- NPVariant* result);
-
- virtual bool HasProperty(NPIdentifier name);
-
- virtual bool GetProperty(NPIdentifier name, NPVariant* result);
-
- virtual bool SetProperty(NPIdentifier name, const NPVariant* value);
-
- virtual bool RemoveProperty(NPIdentifier name);
-
- virtual bool Enumerate(NPIdentifier** names,
- uint32_t* count);
-
- virtual bool Construct(const NPVariant* args,
- uint32_t num_args,
- NPVariant* result);
-
- protected:
-
- explicit BaseNPObject(NPP npp);
- virtual ~BaseNPObject();
-
- private:
+namespace np_class_impl {
// This template version of the NPClass allocate function creates a subclass
// of BaseNPObject.
template <typename NPObjectType>
- static NPObject* AllocateImpl(NPP npp, NPClass*) {
+ static NPObject* Allocate(NPP npp, NPClass*) {
return new NPObjectType(npp);
}
// These implementations of the NPClass functions forward to the virtual
- // functions in BaseNPObject.
- static void DeallocateImpl(NPObject* object);
+ // functions in DefaultNPObject.
+ template <typename NPObjectType>
+ static void Deallocate(NPObject* object) {
+ delete static_cast<NPObjectType*>(object);
+ }
- static void InvalidateImpl(NPObject* object);
+ template <typename NPObjectType>
+ static void Invalidate(NPObject* object) {
+ return static_cast<NPObjectType*>(object)->Invalidate();
+ }
- static bool HasMethodImpl(NPObject* object, NPIdentifier name);
+ template <typename NPObjectType>
+ static bool HasMethod(NPObject* object, NPIdentifier name) {
+ return static_cast<NPObjectType*>(object)->HasMethod(name);
+ }
- static bool InvokeImpl(NPObject* object,
- NPIdentifier name,
- const NPVariant* args,
- uint32_t num_args,
- NPVariant* result);
+ template <typename NPObjectType>
+ static bool Invoke(NPObject* object,
+ NPIdentifier name,
+ const NPVariant* args,
+ uint32_t num_args,
+ NPVariant* result) {
+ return static_cast<NPObjectType*>(object)->Invoke(
+ name, args, num_args, result);
+ }
- static bool InvokeDefaultImpl(NPObject* object,
- const NPVariant* args,
- uint32_t num_args,
- NPVariant* result);
+ template <typename NPObjectType>
+ static bool InvokeDefault(NPObject* object,
+ const NPVariant* args,
+ uint32_t num_args,
+ NPVariant* result) {
+ return static_cast<NPObjectType*>(object)->InvokeDefault(
+ args, num_args, result);
+ }
- static bool HasPropertyImpl(NPObject* object, NPIdentifier name);
+ template <typename NPObjectType>
+ static bool HasProperty(NPObject* object, NPIdentifier name) {
+ return static_cast<NPObjectType*>(object)->HasProperty(name);
+ }
- static bool GetPropertyImpl(NPObject* object,
- NPIdentifier name,
- NPVariant* result);
+ template <typename NPObjectType>
+ static bool GetProperty(NPObject* object,
+ NPIdentifier name,
+ NPVariant* result) {
+ return static_cast<NPObjectType*>(object)->GetProperty(name, result);
+ }
- static bool SetPropertyImpl(NPObject* object,
+ template <typename NPObjectType>
+ static bool SetProperty(NPObject* object,
NPIdentifier name,
- const NPVariant* value);
+ const NPVariant* value) {
+ return static_cast<NPObjectType*>(object)->SetProperty(name, value);
+ }
- static bool RemovePropertyImpl(NPObject* object, NPIdentifier name);
+ template <typename NPObjectType>
+ static bool RemoveProperty(NPObject* object, NPIdentifier name) {
+ return static_cast<NPObjectType*>(object)->RemoveProperty(name);
+ }
- static bool EnumerateImpl(NPObject* object,
+ template <typename NPObjectType>
+ static bool Enumerate(NPObject* object,
NPIdentifier** names,
- uint32_t* count);
+ uint32_t* count) {
+ return static_cast<NPObjectType*>(object)->Enumerate(names, count);
+ };
- static bool ConstructImpl(NPObject* object,
+ template <typename NPObjectType>
+ static bool Construct(NPObject* object,
const NPVariant* args,
uint32_t num_args,
- NPVariant* result);
+ NPVariant* result) {
+ return static_cast<NPObjectType*>(object)->Construct(
+ args, num_args, result);
+ }
+} // namespace np_class_impl;
- NPP npp_;
-
- DISALLOW_COPY_AND_ASSIGN(BaseNPObject);
-};
-
template <typename NPObjectType>
-const NPClass* BaseNPObject::GetNPClass() {
- static NPClass np_class = {
+const NPClass* NPGetClass() {
+ static const NPClass np_class = {
NP_CLASS_STRUCT_VERSION,
- AllocateImpl<NPObjectType>,
- DeallocateImpl,
- InvalidateImpl,
- HasMethodImpl,
- InvokeImpl,
- InvokeDefaultImpl,
- HasPropertyImpl,
- GetPropertyImpl,
- SetPropertyImpl,
- RemovePropertyImpl,
- EnumerateImpl,
- ConstructImpl,
+ np_class_impl::Allocate<NPObjectType>,
+ np_class_impl::Deallocate<NPObjectType>,
+ np_class_impl::Invalidate<NPObjectType>,
+ np_class_impl::HasMethod<NPObjectType>,
+ np_class_impl::Invoke<NPObjectType>,
+ np_class_impl::InvokeDefault<NPObjectType>,
+ np_class_impl::HasProperty<NPObjectType>,
+ np_class_impl::GetProperty<NPObjectType>,
+ np_class_impl::SetProperty<NPObjectType>,
+ np_class_impl::RemoveProperty<NPObjectType>,
+ np_class_impl::Enumerate<NPObjectType>,
+ np_class_impl::Construct<NPObjectType>,
};
return &np_class;
};
+
} // namespace gpu_plugin
} // namespace o3d
-#endif // O3D_GPU_PLUGIN_NP_UTILS_BASE_NP_OBJECT_H_
+#endif // O3D_GPU_PLUGIN_NP_UTILS_NP_CLASS_H_
« no previous file with comments | « o3d/gpu_plugin/np_utils/dynamic_np_object.cc ('k') | o3d/gpu_plugin/np_utils/np_class_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698