Chromium Code Reviews| 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..7c58922bf672b74ed05f8c1765e4073d18160604 |
| --- /dev/null |
| +++ b/ppapi/cpp/dev/struct_wrapper_base_dev.h |
| @@ -0,0 +1,72 @@ |
| +// 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/cpp/dev/may_own_ptr_dev.h" |
| + |
| +namespace pp { |
| +namespace internal { |
| + |
| +// 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.
|
| +// whether a class is a struct wrapper. |
| +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
|
| +}; |
| + |
| +// The base class for struct wrappers. |
| +template <typename Type, typename ArrayType = void> |
| +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
|
| + public: |
| + // The C struct type that this class acts as a wrapper for. |
| + typedef Type CType; |
| + // The corresponding C array type, used by pp::Array. |
| + typedef ArrayType CArrayType; |
| + |
| + // The corresponding C output parameter type. |
| + typedef CType* COutputType; |
| + // The corresponding C input parameter type. |
| + typedef const CType* CInputType; |
| + |
| + StructWrapperBase() {} |
| + |
| + // It doesn't take ownership of |storage|, therefore |storage| must live |
| + // 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
|
| + 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. :)
|
| + |
| + 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: |
|
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.
|
| + // Subclasses should implement these methods to notify members that raw update |
| + // to the C struct has started / ended. |
| + virtual void NotifyStartRawUpdate() = 0; |
| + 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
|
| + |
| + MayOwnPtr<CType> storage_; |
| + |
| + private: |
| + // Although subclasses usually support copying and assignment, they shouldn't |
| + // try to copy or assign the contents of this class. |
| + 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_ |