// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. // 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_NP_CLASS_H_ #define O3D_GPU_PLUGIN_NP_UTILS_NP_CLASS_H_ #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" #include "o3d/gpu_plugin/np_utils/np_headers.h" // This file implements NPGetClass. 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 { namespace np_class_impl { // This template version of the NPClass allocate function creates a subclass // of BaseNPObject. template static NPObject* Allocate(NPP npp, NPClass*) { return new NPObjectType(npp); } // These implementations of the NPClass functions forward to the virtual // functions in DefaultNPObject. template static void Deallocate(NPObject* object) { delete static_cast(object); } template static void Invalidate(NPObject* object) { return static_cast(object)->Invalidate(); } template static bool HasMethod(NPObject* object, NPIdentifier name) { return static_cast(object)->HasMethod(name); } template static bool Invoke(NPObject* object, NPIdentifier name, const NPVariant* args, uint32_t num_args, NPVariant* result) { return static_cast(object)->Invoke( name, args, num_args, result); } template static bool InvokeDefault(NPObject* object, const NPVariant* args, uint32_t num_args, NPVariant* result) { return static_cast(object)->InvokeDefault( args, num_args, result); } template static bool HasProperty(NPObject* object, NPIdentifier name) { return static_cast(object)->HasProperty(name); } template static bool GetProperty(NPObject* object, NPIdentifier name, NPVariant* result) { return static_cast(object)->GetProperty(name, result); } template static bool SetProperty(NPObject* object, NPIdentifier name, const NPVariant* value) { return static_cast(object)->SetProperty(name, value); } template static bool RemoveProperty(NPObject* object, NPIdentifier name) { return static_cast(object)->RemoveProperty(name); } template static bool Enumerate(NPObject* object, NPIdentifier** names, uint32_t* count) { return static_cast(object)->Enumerate(names, count); }; template static bool Construct(NPObject* object, const NPVariant* args, uint32_t num_args, NPVariant* result) { return static_cast(object)->Construct( args, num_args, result); } } // namespace np_class_impl; template const NPClass* NPGetClass() { static const NPClass np_class = { NP_CLASS_STRUCT_VERSION, np_class_impl::Allocate, np_class_impl::Deallocate, np_class_impl::Invalidate, np_class_impl::HasMethod, np_class_impl::Invoke, np_class_impl::InvokeDefault, np_class_impl::HasProperty, np_class_impl::GetProperty, np_class_impl::SetProperty, np_class_impl::RemoveProperty, np_class_impl::Enumerate, np_class_impl::Construct, }; return &np_class; }; } // namespace gpu_plugin } // namespace o3d #endif // O3D_GPU_PLUGIN_NP_UTILS_NP_CLASS_H_