Chromium Code Reviews| 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/cpp/dev/may_own_ptr_dev.h" | |
| 9 | |
| 10 namespace pp { | |
| 11 namespace internal { | |
| 12 | |
| 13 // The only purpose of this class is for CallbackOutputTraits to determined | |
|
dmichael (off chromium)
2013/12/17 18:03:25
determined->determine
yzshen1
2013/12/17 23:52:21
Done.
| |
| 14 // whether a class is a struct wrapper. | |
| 15 class StructWrapperIdentifier { | |
|
dmichael (off chromium)
2013/12/17 18:03:25
I mentioned this elsewhere, but I don't think you
yzshen1
2013/12/17 23:52:21
I think one good thing about this approach is that
dmichael (off chromium)
2013/12/18 18:24:04
Similarly, it also leaves part of the public API o
yzshen1
2013/12/18 19:18:56
Thanks David!
I think you persuaded me. I will re
dmichael (off chromium)
2013/12/19 15:57:44
Thanks, Yuzhu! I hope it turns out clean. If it ca
yzshen1
2013/12/19 17:57:58
I think it looks nice now. You have a good point t
| |
| 16 }; | |
| 17 | |
| 18 // The base class for struct wrappers. | |
| 19 template <typename Type, typename ArrayType = void> | |
| 20 class StructWrapperBase : public StructWrapperIdentifier { | |
|
dmichael (off chromium)
2013/12/17 18:03:25
It seems slightly messy to me to have this as a ba
yzshen1
2013/12/17 23:52:21
I made this StructWrapperBase class based on the f
dmichael (off chromium)
2013/12/18 18:24:04
Alternately, if you need the typedefs, maybe you c
| |
| 21 public: | |
| 22 // The C struct type that this class acts as a wrapper for. | |
| 23 typedef Type CType; | |
| 24 // The corresponding C array type, used by pp::Array. | |
| 25 typedef ArrayType CArrayType; | |
| 26 | |
| 27 // The corresponding C output parameter type. | |
| 28 typedef CType* COutputType; | |
| 29 // The corresponding C input parameter type. | |
| 30 typedef const CType* CInputType; | |
| 31 | |
| 32 StructWrapperBase() {} | |
| 33 | |
| 34 // It doesn't take ownership of |storage|, therefore |storage| must live | |
| 35 // longer than this object. |storage| must be zero-initialized. | |
|
dmichael (off chromium)
2013/12/17 18:03:25
I think you mean that the caller must zero-initial
yzshen1
2013/12/17 23:52:21
Right, the contents pointed to by |storage| must b
| |
| 36 StructWrapperBase(CType* storage, NotOwned) : storage_(storage, NOT_OWNED) {} | |
|
dmichael (off chromium)
2013/12/17 18:03:25
If there's not a constructor that takes ownership,
yzshen1
2013/12/17 23:52:21
I was thinking NOT_OWNED makes it more obvious tha
dmichael (off chromium)
2013/12/18 18:24:04
Sorry, I realized later that a default-constructed
yzshen1
2013/12/18 19:18:56
I did the MayOwnPtr<> design mostly for accessing
dmichael (off chromium)
2013/12/19 15:57:44
Do you mean in PP_Alarms_Alarm_Dev?
yzshen1
2013/12/19 17:57:58
Yes. Typo. :)
| |
| 37 | |
| 38 virtual ~StructWrapperBase() {} | |
| 39 | |
| 40 // For input parameters to call PPB_* functions. | |
| 41 const CType* ToStruct() const { return storage_.get(); } | |
| 42 | |
| 43 // For output parameters to call PPB_* functions. The returned pointer is | |
| 44 // still owned by this object. And after it is used, EndRawUpdate() must be | |
| 45 // called. | |
| 46 CType* StartRawUpdate() { | |
| 47 NotifyStartRawUpdate(); | |
| 48 return storage_.get(); | |
| 49 } | |
| 50 | |
| 51 void EndRawUpdate() { NotifyEndRawUpdate(); } | |
| 52 | |
| 53 protected: | |
|
dmichael (off chromium)
2013/12/17 18:03:25
If subclasses aren't supposed to _invoke_ these, m
yzshen1
2013/12/17 23:52:21
You are right. Thanks! Done.
| |
| 54 // Subclasses should implement these methods to notify members that raw update | |
| 55 // to the C struct has started / ended. | |
| 56 virtual void NotifyStartRawUpdate() = 0; | |
| 57 virtual void NotifyEndRawUpdate() = 0; | |
|
dmichael (off chromium)
2013/12/17 18:03:25
I think these wouldn't be necessary if the struct
yzshen1
2013/12/17 23:52:21
I used them so that the public section of the subc
| |
| 58 | |
| 59 MayOwnPtr<CType> storage_; | |
| 60 | |
| 61 private: | |
| 62 // Although subclasses usually support copying and assignment, they shouldn't | |
| 63 // try to copy or assign the contents of this class. | |
| 64 StructWrapperBase(const StructWrapperBase<CType, CArrayType>& other); | |
| 65 StructWrapperBase<CType, CArrayType>& operator=( | |
| 66 const StructWrapperBase<CType, CArrayType>& other); | |
| 67 }; | |
| 68 | |
| 69 } // namespace internal | |
| 70 } // namespace pp | |
| 71 | |
| 72 #endif // PPAPI_CPP_DEV_STRUCT_WRAPPER_BASE_DEV_ | |
| OLD | NEW |