Chromium Code Reviews| Index: ppapi/cpp/output_traits.h |
| diff --git a/ppapi/cpp/output_traits.h b/ppapi/cpp/output_traits.h |
| index 31cdbbe11220eccddd739c7fac6f00d27be6409f..24f1f06b24a84ffdb2c06ffdc7f0fb474e282082 100644 |
| --- a/ppapi/cpp/output_traits.h |
| +++ b/ppapi/cpp/output_traits.h |
| @@ -9,6 +9,8 @@ |
| #include "ppapi/c/pp_resource.h" |
| #include "ppapi/cpp/array_output.h" |
| +#include "ppapi/cpp/dev/array_dev.h" |
| +#include "ppapi/cpp/dev/struct_wrapper_base_dev.h" |
| #include "ppapi/cpp/resource.h" |
| /// @file |
| @@ -123,17 +125,46 @@ struct ResourceCallbackOutputTraits { |
| } |
| }; |
| +// This class is parameterized by derived classes of |
| +// pp::StructWrapperIdentifier, for example, |
| +// StructWrapperCallbackOutputTraits<pp::alarms::Alarm_Dev>. It is used as a |
| +// base class for CallbackOutputTraits below. |
| +template<typename T> |
| +struct StructWrapperCallbackOutputTraits { |
| + typedef typename T::COutputType APIArgType; |
| + typedef T StorageType; |
| + |
| + // Returns the underlying C struct of |t|, which can be passed to the browser |
| + // as an output parameter. |
| + static inline APIArgType StorageToAPIArg(StorageType& t) { |
| + return t.StartRawUpdate(); |
| + } |
| + |
| + // For each |t| passed into StorageToAPIArg(), this method must be called |
| + // exactly once in order to match StartRawUpdate() and EndRawUpdate(). |
| + static inline T& StorageToPluginArg(StorageType& t) { |
| + t.EndRawUpdate(); |
| + return t; |
| + } |
| + |
| + static inline void Initialize(StorageType* /* t */) {} |
| +}; |
| + |
| // The general templatized base class for all CallbackOutputTraits. This class |
| -// covers both resources and POD (ints, structs, etc.) by inheriting from the |
| -// appropriate base class depending on whether the given type derives from |
| -// pp::Resource. This trick allows us to do this once rather than writing |
| -// specializations for every resource object type. |
| +// covers resources, struct wrapper objects and POD (ints, structs, etc.) |
| +// by inheriting from the appropriate base class depending on whether the given |
| +// type derives from pp::Resource or pp::StructWrapperIdentifier. This trick |
| +// allows us to do this once rather than writing specializations for every |
| +// object type. |
| template<typename T> |
| struct CallbackOutputTraits |
| - : public InheritIf<GenericCallbackOutputTraits<T>, |
| - !IsBaseOf<Resource, T>::value>, |
| - public InheritIf<ResourceCallbackOutputTraits<T>, |
| - IsBaseOf<Resource, T>::value> { |
| + : public InheritIf<ResourceCallbackOutputTraits<T>, |
| + IsBaseOf<Resource, T>::value>, |
| + public InheritIf<StructWrapperCallbackOutputTraits<T>, |
| + IsBaseOf<StructWrapperIdentifier, T>::value>, |
| + public InheritIf<GenericCallbackOutputTraits<T>, |
| + !IsBaseOf<Resource, T>::value && |
| + !IsBaseOf<StructWrapperIdentifier, T>::value> { |
| }; |
| // A specialization of CallbackOutputTraits for pp::Var output parameters. |
| @@ -184,6 +215,28 @@ struct CallbackOutputTraits<bool> { |
| } |
| }; |
| +// A specialization of CallbackOutputTraits for pp::Array parameters. |
| +template<typename T> |
| +struct CallbackOutputTraits<Array<T> > { |
|
dmichael (off chromium)
2013/12/17 18:03:25
Would it be practical to put this in the header fo
yzshen1
2013/12/17 23:52:21
It seems we put most output traits in this file. F
|
| + typedef typename Array<T>::COutputType APIArgType; |
| + typedef Array<T> StorageType; |
| + |
| + // Returns the underlying C struct of |t|, which can be passed to the browser |
| + // as an output parameter. |
| + static inline APIArgType StorageToAPIArg(StorageType& t) { |
| + return t.StartRawUpdate(); |
| + } |
| + |
| + // For each |t| passed into StorageToAPIArg(), this method must be called |
| + // exactly once in order to match StartRawUpdate() and EndRawUpdate(). |
| + static inline Array<T>& StorageToPluginArg(StorageType& t) { |
| + t.EndRawUpdate(); |
| + return t; |
| + } |
| + |
| + static inline void Initialize(StorageType* /* t */) {} |
| +}; |
| + |
| // Array output parameters ----------------------------------------------------- |
| // Output traits for vectors of all "plain old data" (POD) types. It is |