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

Side by Side Diff: Source/wtf/RawPtr.h

Issue 170603003: Use nullptr_t for RefPtr, PassRefPtr and RawPtr. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Final rebase Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/PassRefPtr.h ('k') | Source/wtf/RefPtr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 26 matching lines...) Expand all
37 // interface (get, clear) of other pointer types such as RefPtr, 37 // interface (get, clear) of other pointer types such as RefPtr,
38 // Persistent and Member. This is used for the Blink garbage 38 // Persistent and Member. This is used for the Blink garbage
39 // collection work in order to be able to write shared code that will 39 // collection work in order to be able to write shared code that will
40 // use reference counting or garbage collection based on a 40 // use reference counting or garbage collection based on a
41 // compile-time flag. 41 // compile-time flag.
42 42
43 namespace WTF { 43 namespace WTF {
44 44
45 template<typename T> 45 template<typename T>
46 class RawPtr { 46 class RawPtr {
47 WTF_DISALLOW_CONSTRUCTION_FROM_ZERO(RawPtr);
48 WTF_DISALLOW_ZERO_ASSIGNMENT(RawPtr);
47 public: 49 public:
48 RawPtr() : m_ptr(0) { } 50 RawPtr() : m_ptr(0) { }
51 RawPtr(std::nullptr_t) : m_ptr(0) { }
49 RawPtr(T* ptr) : m_ptr(ptr) { } 52 RawPtr(T* ptr) : m_ptr(ptr) { }
50 RawPtr(const RawPtr& other) 53 RawPtr(const RawPtr& other)
51 : m_ptr(other.get()) 54 : m_ptr(other.get())
52 { 55 {
53 } 56 }
54 template<typename U> 57 template<typename U>
55 RawPtr(const RawPtr<U>& other) 58 RawPtr(const RawPtr<U>& other)
56 : m_ptr(other.get()) 59 : m_ptr(other.get())
57 { 60 {
58 } 61 }
(...skipping 21 matching lines...) Expand all
80 return *this; 83 return *this;
81 } 84 }
82 85
83 template<typename U> 86 template<typename U>
84 RawPtr& operator=(RawPtr<U> ptr) 87 RawPtr& operator=(RawPtr<U> ptr)
85 { 88 {
86 m_ptr = ptr.get(); 89 m_ptr = ptr.get();
87 return *this; 90 return *this;
88 } 91 }
89 92
93 RawPtr& operator=(std::nullptr_t)
94 {
95 m_ptr = 0;
96 return *this;
97 }
98
90 operator T*() const { return m_ptr; } 99 operator T*() const { return m_ptr; }
91 T& operator*() const { return *m_ptr; } 100 T& operator*() const { return *m_ptr; }
92 T* operator->() const { return m_ptr; } 101 T* operator->() const { return m_ptr; }
93 102
94 void swap(RawPtr& o) 103 void swap(RawPtr& o)
95 { 104 {
96 std::swap(m_ptr, o.m_ptr); 105 std::swap(m_ptr, o.m_ptr);
97 } 106 }
98 107
99 108
100 private: 109 private:
101 T* m_ptr; 110 T* m_ptr;
102 }; 111 };
103 112
104 template<typename T, typename U> inline RawPtr<T> static_pointer_cast(const RawP tr<U>& p) 113 template<typename T, typename U> inline RawPtr<T> static_pointer_cast(const RawP tr<U>& p)
105 { 114 {
106 return RawPtr<T>(static_cast<T*>(p.get())); 115 return RawPtr<T>(static_cast<T*>(p.get()));
107 } 116 }
108 117
109 } // namespace WTF 118 } // namespace WTF
110 119
111 using WTF::RawPtr; 120 using WTF::RawPtr;
112 121
113 #endif 122 #endif
OLDNEW
« no previous file with comments | « Source/wtf/PassRefPtr.h ('k') | Source/wtf/RefPtr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698