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.
5 #ifndef PPAPI_CPP_EXTENSIONS_OPTIONAL_H_
6 #define PPAPI_CPP_EXTENSIONS_OPTIONAL_H_
14 Optional() : value_(NULL) {
16 // Takes ownership of |value|.
17 explicit Optional(T* value) : value_(value) {
19 Optional(const T& value) : value_(new T(value)) {
21 Optional(const Optional<T>& other)
22 : value_(other.value_ ? new T(*other.value_) : NULL) {
29 Optional<T>& operator=(const T& other) {
34 value_ = new T(other);
39 Optional<T>& operator=(const Optional<T>& other) {
40 if (value_ == other.value_)
45 value_ = new T(*other.value_);
58 // Should only be used when IsSet() is true.
59 T& operator*() const {
63 // Should only be used when IsSet() is true.
64 T* operator->() const {
69 // Takes ownership of |value|.
84 void Swap(Optional<T>* other) {
86 value_ = other->value_;
97 #endif // PPAPI_CPP_EXTENSIONS_OPTIONAL_H_