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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_MAY_OWN_PTR_DEV_H_
6 #define PPAPI_CPP_DEV_MAY_OWN_PTR_DEV_H_
7
8 #include "ppapi/cpp/logging.h"
9
10 namespace pp {
11
12 enum NotOwned {
13 NOT_OWNED
14 };
15
16 namespace internal {
17
18 template <class T>
19 class MayOwnPtr {
20 public:
21 MayOwnPtr(T* value, NotOwned) : value_(value), owned_(false) {
22 }
23
24 MayOwnPtr() : value_(new T()), owned_(true) {
25 }
26
27 explicit MayOwnPtr(const T& other) : value_(new T(other)),
28 owned_(true) {
29 }
30
31 MayOwnPtr(const MayOwnPtr& other) : value_(new T(*other.value_)),
32 owned_(true) {
33 }
34
35 ~MayOwnPtr() {
36 if (owned_)
37 delete value_;
38 }
39
40 MayOwnPtr& operator=(const MayOwnPtr& other) {
41 if (this == &other)
42 return *this;
43
44 value_ = new T(*other.value_);
45 owned_ = true;
46
47 return *this;
48 }
49
50 const T* get() const {
51 return value_;
52 }
53
54 T* get() {
55 return value_;
56 }
57
58 T& operator*() const {
59 return *value_;
60 }
61
62 T* operator->() const {
63 return value_;
64 }
65
66 bool owned() const {
67 return owned_;
68 }
69
70 private:
71 T* value_;
72 bool owned_;
73 };
74
75 } // namespace internal
76 } // namespace pp
77
78 #endif // PPAPI_CPP_DEV_MAY_OWN_PTR_DEV_H_
OLDNEW
« 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