| Index: ppapi/cpp/dev/may_own_ptr_dev.h
|
| diff --git a/ppapi/cpp/dev/may_own_ptr_dev.h b/ppapi/cpp/dev/may_own_ptr_dev.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d67d72fa9dd3a6d35c205c717f001584ee032ba3
|
| --- /dev/null
|
| +++ b/ppapi/cpp/dev/may_own_ptr_dev.h
|
| @@ -0,0 +1,78 @@
|
| +// 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_MAY_OWN_PTR_DEV_H_
|
| +#define PPAPI_CPP_DEV_MAY_OWN_PTR_DEV_H_
|
| +
|
| +#include "ppapi/cpp/logging.h"
|
| +
|
| +namespace pp {
|
| +
|
| +enum NotOwned {
|
| + NOT_OWNED
|
| +};
|
| +
|
| +namespace internal {
|
| +
|
| +template <class T>
|
| +class MayOwnPtr {
|
| + public:
|
| + MayOwnPtr(T* value, NotOwned) : value_(value), owned_(false) {
|
| + }
|
| +
|
| + MayOwnPtr() : value_(new T()), owned_(true) {
|
| + }
|
| +
|
| + explicit MayOwnPtr(const T& other) : value_(new T(other)),
|
| + owned_(true) {
|
| + }
|
| +
|
| + MayOwnPtr(const MayOwnPtr& other) : value_(new T(*other.value_)),
|
| + owned_(true) {
|
| + }
|
| +
|
| + ~MayOwnPtr() {
|
| + if (owned_)
|
| + delete value_;
|
| + }
|
| +
|
| + MayOwnPtr& operator=(const MayOwnPtr& other) {
|
| + if (this == &other)
|
| + return *this;
|
| +
|
| + value_ = new T(*other.value_);
|
| + owned_ = true;
|
| +
|
| + return *this;
|
| + }
|
| +
|
| + const T* get() const {
|
| + return value_;
|
| + }
|
| +
|
| + T* get() {
|
| + return value_;
|
| + }
|
| +
|
| + T& operator*() const {
|
| + return *value_;
|
| + }
|
| +
|
| + T* operator->() const {
|
| + return value_;
|
| + }
|
| +
|
| + bool owned() const {
|
| + return owned_;
|
| + }
|
| +
|
| + private:
|
| + T* value_;
|
| + bool owned_;
|
| +};
|
| +
|
| +} // namespace internal
|
| +} // namespace pp
|
| +
|
| +#endif // PPAPI_CPP_DEV_MAY_OWN_PTR_DEV_H_
|
|
|