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

Side by Side Diff: sky/engine/bindings2/nullable.h

Issue 918333002: Add the c++ code part of bindings2/ (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Updated per earlier reviews Created 5 years, 10 months 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
« no previous file with comments | « sky/engine/bindings2/mojo_natives.cc ('k') | sky/engine/bindings2/scheduled_action.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 2014 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 SKY_ENGINE_BINDINGS2_NULLABLE_H_
6 #define SKY_ENGINE_BINDINGS2_NULLABLE_H_
7
8 #include "base/logging.h"
9
10 namespace blink {
11
12 template <typename T>
13 class Nullable {
14 public:
15 Nullable() : value_(), is_null_(true) {}
16 Nullable(const T& value) : value_(value), is_null_(false) {}
17 Nullable(const Nullable& other)
18 : value_(other.value_), is_null_(other.is_null_) {}
19
20 Nullable& operator=(const Nullable& other) = default;
21
22 void set(const T& value) {
23 value_ = value;
24 is_null_ = false;
25 }
26
27 const T& get() const {
28 DCHECK(!is_null_);
29 return value_;
30 }
31 T& get() {
32 DCHECK(!is_null_);
33 return value_;
34 }
35
36 bool is_null() const { return is_null_; }
37
38 // See comment in RefPtr.h about what UnspecifiedBoolType is.
39 typedef const T* UnspecifiedBoolType;
40 operator UnspecifiedBoolType() const { return is_null_ ? 0 : &value_; }
41
42 bool operator==(const Nullable& other) const {
43 return (is_null_ && other.is_null_) ||
44 (!is_null_ && !other.is_null_ && value_ == other.value_);
45 }
46
47 private:
48 T value_;
49 bool is_null_;
50 };
51
52 } // namespace blink
53
54 #endif // SKY_ENGINE_BINDINGS2_NULLABLE_H_
OLDNEW
« no previous file with comments | « sky/engine/bindings2/mojo_natives.cc ('k') | sky/engine/bindings2/scheduled_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698