OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef PPAPI_CPP_DEV_STRUCT_WRAPPER_BASE_DEV_ |
| 6 #define PPAPI_CPP_DEV_STRUCT_WRAPPER_BASE_DEV_ |
| 7 |
| 8 #include "ppapi/c/dev/pp_optional_structs_dev.h" |
| 9 #include "ppapi/cpp/dev/array_dev.h" |
| 10 #include "ppapi/cpp/dev/may_own_ptr_dev.h" |
| 11 #include "ppapi/cpp/logging.h" |
| 12 #include "ppapi/cpp/var.h" |
| 13 |
| 14 namespace pp { |
| 15 namespace internal { |
| 16 |
| 17 // The only purpose of this class is for CallbackOutputTraits to determined |
| 18 // whether a class is a struct wrapper. |
| 19 class StructWrapperIdentifier { |
| 20 }; |
| 21 |
| 22 template <class Type, class ArrayType = void> |
| 23 class StructWrapperBase : public StructWrapperIdentifier { |
| 24 public: |
| 25 typedef Type CType; |
| 26 typedef ArrayType CArrayType; |
| 27 |
| 28 typedef CType* COutputType; |
| 29 typedef const CType* CInputType; |
| 30 |
| 31 StructWrapperBase() { |
| 32 } |
| 33 |
| 34 // For struct / array members. |
| 35 // It doesn't take ownership of |storage|, therefore |storage| must live |
| 36 // longer than this object. |
| 37 StructWrapperBase(CType* storage, NotOwned) : storage_(storage, NOT_OWNED) { |
| 38 } |
| 39 |
| 40 virtual ~StructWrapperBase() { |
| 41 } |
| 42 |
| 43 // For input parameters to call PPB_* functions. |
| 44 const CType* ToStruct() const { |
| 45 return storage_.get(); |
| 46 } |
| 47 |
| 48 // For output parameters to call PPB_* functions. The returned pointer is |
| 49 // still owned by this object. And after it is used, EndRawUpdate() must be |
| 50 // called. |
| 51 CType* StartRawUpdate() { |
| 52 NotifyStartRawUpdate(); |
| 53 return storage_.get(); |
| 54 } |
| 55 |
| 56 void EndRawUpdate() { |
| 57 NotifyEndRawUpdate(); |
| 58 } |
| 59 |
| 60 protected: |
| 61 virtual void NotifyStartRawUpdate() = 0; |
| 62 virtual void NotifyEndRawUpdate() = 0; |
| 63 |
| 64 MayOwnPtr<CType> storage_; |
| 65 |
| 66 private: |
| 67 // Disallow copy and assign. |
| 68 StructWrapperBase(const StructWrapperBase<CType, CArrayType>& other); |
| 69 StructWrapperBase<CType, CArrayType>& operator=( |
| 70 const StructWrapperBase<CType, CArrayType>& other); |
| 71 }; |
| 72 |
| 73 } // namespace internal |
| 74 } // namespace pp |
| 75 |
| 76 #endif // PPAPI_CPP_DEV_STRUCT_WRAPPER_BASE_DEV_ |
OLD | NEW |