Index: ppapi/cpp/output_traits.h |
diff --git a/ppapi/cpp/output_traits.h b/ppapi/cpp/output_traits.h |
index 31cdbbe11220eccddd739c7fac6f00d27be6409f..f0f1809e1ba4b389f96023ab4c37bef1fdd5d3b6 100644 |
--- a/ppapi/cpp/output_traits.h |
+++ b/ppapi/cpp/output_traits.h |
@@ -9,6 +9,9 @@ |
#include "ppapi/c/pp_resource.h" |
#include "ppapi/cpp/array_output.h" |
+#include "ppapi/cpp/dev/array_dev.h" |
+#include "ppapi/cpp/dev/from_c_type_converter_dev.h" |
+#include "ppapi/cpp/dev/struct_wrapper_base_dev.h" |
#include "ppapi/cpp/resource.h" |
/// @file |
@@ -123,17 +126,40 @@ struct ResourceCallbackOutputTraits { |
} |
}; |
+template<typename T> |
+struct StructWrapperCallbackOutputTraits { |
+ typedef typename T::COutputType APIArgType; |
+ typedef FromCTypeConverter<T> StorageType; |
+ |
+ static inline APIArgType StorageToAPIArg(StorageType& t) { |
+ return t.StartRawUpdate(); |
+ } |
+ |
+ static inline T& StorageToPluginArg(StorageType& t) { |
+ t.EndRawUpdate(); |
+ return t.value(); |
+ } |
+ |
+ 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 StructWrapperIdentifier. This trick |
+// allows us to do this once rather than writing specializations for every |
+// object type. |
+// TODO(yzshen): I will need to add specializtion for Optional<T>. Other than |
+// that I think it should be fine. |
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 +210,24 @@ struct CallbackOutputTraits<bool> { |
} |
}; |
+template<typename T> |
+struct CallbackOutputTraits<Array<T> > { |
+ typedef typename Array<T>::COutputType APIArgType; |
+ typedef Array<T> StorageType; |
+ |
+ static inline APIArgType StorageToAPIArg(StorageType& t) { |
+ return t.StartRawUpdate(); |
+ } |
+ |
+ 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 |