Index: ppapi/cpp/dev/struct_wrapper_base_dev.h |
diff --git a/ppapi/cpp/dev/struct_wrapper_base_dev.h b/ppapi/cpp/dev/struct_wrapper_base_dev.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2a7809a421fac9152d93d3210585504e3e4ca624 |
--- /dev/null |
+++ b/ppapi/cpp/dev/struct_wrapper_base_dev.h |
@@ -0,0 +1,76 @@ |
+// Copyright (c) 2013 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 PPAPI_CPP_DEV_STRUCT_WRAPPER_BASE_DEV_ |
+#define PPAPI_CPP_DEV_STRUCT_WRAPPER_BASE_DEV_ |
+ |
+#include "ppapi/c/dev/pp_optional_structs_dev.h" |
+#include "ppapi/cpp/dev/array_dev.h" |
+#include "ppapi/cpp/dev/may_own_ptr_dev.h" |
+#include "ppapi/cpp/logging.h" |
+#include "ppapi/cpp/var.h" |
+ |
+namespace pp { |
+namespace internal { |
+ |
+// The only purpose of this class is for CallbackOutputTraits to determined |
+// whether a class is a struct wrapper. |
+class StructWrapperIdentifier { |
+}; |
+ |
+template <class Type, class ArrayType = void> |
+class StructWrapperBase : public StructWrapperIdentifier { |
+ public: |
+ typedef Type CType; |
+ typedef ArrayType CArrayType; |
+ |
+ typedef CType* COutputType; |
+ typedef const CType* CInputType; |
+ |
+ StructWrapperBase() { |
+ } |
+ |
+ // For struct / array members. |
+ // It doesn't take ownership of |storage|, therefore |storage| must live |
+ // longer than this object. |
+ StructWrapperBase(CType* storage, NotOwned) : storage_(storage, NOT_OWNED) { |
+ } |
+ |
+ virtual ~StructWrapperBase() { |
+ } |
+ |
+ // For input parameters to call PPB_* functions. |
+ const CType* ToStruct() const { |
+ return storage_.get(); |
+ } |
+ |
+ // For output parameters to call PPB_* functions. The returned pointer is |
+ // still owned by this object. And after it is used, EndRawUpdate() must be |
+ // called. |
+ CType* StartRawUpdate() { |
+ NotifyStartRawUpdate(); |
+ return storage_.get(); |
+ } |
+ |
+ void EndRawUpdate() { |
+ NotifyEndRawUpdate(); |
+ } |
+ |
+ protected: |
+ virtual void NotifyStartRawUpdate() = 0; |
+ virtual void NotifyEndRawUpdate() = 0; |
+ |
+ MayOwnPtr<CType> storage_; |
+ |
+ private: |
+ // Disallow copy and assign. |
+ StructWrapperBase(const StructWrapperBase<CType, CArrayType>& other); |
+ StructWrapperBase<CType, CArrayType>& operator=( |
+ const StructWrapperBase<CType, CArrayType>& other); |
+}; |
+ |
+} // namespace internal |
+} // namespace pp |
+ |
+#endif // PPAPI_CPP_DEV_STRUCT_WRAPPER_BASE_DEV_ |