Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1700)

Unified Diff: ppapi/cpp/dev/may_own_ptr_dev.h

Issue 60173003: Draft: apps APIs in Pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/cpp/dev/from_c_type_converter_dev.h ('k') | ppapi/cpp/dev/optional_dev.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « ppapi/cpp/dev/from_c_type_converter_dev.h ('k') | ppapi/cpp/dev/optional_dev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698