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

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

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 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
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 29 matching lines...) Expand all
40 40
41 // RawPtr is a simple wrapper for a raw pointer that provides the 41 // RawPtr is a simple wrapper for a raw pointer that provides the
42 // interface (get, clear) of other pointer types such as RefPtr, 42 // interface (get, clear) of other pointer types such as RefPtr,
43 // Persistent and Member. This is used for the Blink garbage 43 // Persistent and Member. This is used for the Blink garbage
44 // collection work in order to be able to write shared code that will 44 // collection work in order to be able to write shared code that will
45 // use reference counting or garbage collection based on a 45 // use reference counting or garbage collection based on a
46 // compile-time flag. 46 // compile-time flag.
47 47
48 namespace WTF { 48 namespace WTF {
49 49
50 template<typename T> 50 template <typename T>
51 class RawPtr { 51 class RawPtr {
52 USING_FAST_MALLOC(RawPtr); 52 USING_FAST_MALLOC(RawPtr);
53 public: 53
54 RawPtr() 54 public:
55 { 55 RawPtr() {
56 #if ENABLE(ASSERT) 56 #if ENABLE(ASSERT)
57 m_ptr = reinterpret_cast<T*>(rawPtrZapValue); 57 m_ptr = reinterpret_cast<T*>(rawPtrZapValue);
58 #endif 58 #endif
59 } 59 }
60 RawPtr(std::nullptr_t) : m_ptr(0) { } 60 RawPtr(std::nullptr_t) : m_ptr(0) {}
61 RawPtr(T* ptr) : m_ptr(ptr) { } 61 RawPtr(T* ptr) : m_ptr(ptr) {}
62 explicit RawPtr(T& reference) : m_ptr(&reference) { } 62 explicit RawPtr(T& reference) : m_ptr(&reference) {}
63 RawPtr(const RawPtr& other) 63 RawPtr(const RawPtr& other) : m_ptr(other.get()) {}
64 : m_ptr(other.get())
65 {
66 }
67 64
68 template<typename U> 65 template <typename U>
69 RawPtr(const RawPtr<U>& other, EnsurePtrConvertibleArgDecl(U, T)) 66 RawPtr(const RawPtr<U>& other, EnsurePtrConvertibleArgDecl(U, T))
70 : m_ptr(other.get()) 67 : m_ptr(other.get()) {}
71 {
72 }
73 68
74 // Hash table deleted values, which are only constructed and never copied or destroyed. 69 // Hash table deleted values, which are only constructed and never copied or d estroyed.
75 RawPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { } 70 RawPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) {}
76 bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue (); } 71 bool isHashTableDeletedValue() const {
72 return m_ptr == hashTableDeletedValue();
73 }
77 74
78 T* get() const { return m_ptr; } 75 T* get() const { return m_ptr; }
79 void clear() { m_ptr = 0; } 76 void clear() { m_ptr = 0; }
80 RawPtr<T> release() 77 RawPtr<T> release() {
81 { 78 RawPtr<T> tmp = m_ptr;
82 RawPtr<T> tmp = m_ptr; 79 m_ptr = 0;
83 m_ptr = 0; 80 return tmp;
84 return tmp; 81 }
85 } 82 T* leakRef() {
86 T* leakRef() 83 T* ptr = m_ptr;
87 { 84 m_ptr = 0;
88 T* ptr = m_ptr; 85 return ptr;
89 m_ptr = 0; 86 }
90 return ptr; 87 T* leakPtr() {
91 } 88 T* ptr = m_ptr;
92 T* leakPtr() 89 m_ptr = 0;
93 { 90 return ptr;
94 T* ptr = m_ptr; 91 }
95 m_ptr = 0;
96 return ptr;
97 }
98 92
99 template<typename U> 93 template <typename U>
100 RawPtr& operator=(U* ptr) 94 RawPtr& operator=(U* ptr) {
101 { 95 m_ptr = ptr;
102 m_ptr = ptr; 96 return *this;
103 return *this; 97 }
104 }
105 98
106 template<typename U> 99 template <typename U>
107 RawPtr& operator=(RawPtr<U> ptr) 100 RawPtr& operator=(RawPtr<U> ptr) {
108 { 101 m_ptr = ptr.get();
109 m_ptr = ptr.get(); 102 return *this;
110 return *this; 103 }
111 }
112 104
113 RawPtr& operator=(std::nullptr_t) 105 RawPtr& operator=(std::nullptr_t) {
114 { 106 m_ptr = 0;
115 m_ptr = 0; 107 return *this;
116 return *this; 108 }
117 }
118 109
119 operator T*() const { return m_ptr; } 110 operator T*() const { return m_ptr; }
120 T& operator*() const { return *m_ptr; } 111 T& operator*() const { return *m_ptr; }
121 T* operator->() const { return m_ptr; } 112 T* operator->() const { return m_ptr; }
122 bool operator!() const { return !m_ptr; } 113 bool operator!() const { return !m_ptr; }
123 114
124 void swap(RawPtr& o) 115 void swap(RawPtr& o) { std::swap(m_ptr, o.m_ptr); }
125 {
126 std::swap(m_ptr, o.m_ptr);
127 }
128 116
129 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); } 117 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
130 118
131 private: 119 private:
132 static const uintptr_t rawPtrZapValue = 0x3a3a3a3a; 120 static const uintptr_t rawPtrZapValue = 0x3a3a3a3a;
133 T* m_ptr; 121 T* m_ptr;
134 }; 122 };
135 123
136 template<typename T, typename U> inline RawPtr<T> static_pointer_cast(const RawP tr<U>& p) 124 template <typename T, typename U>
137 { 125 inline RawPtr<T> static_pointer_cast(const RawPtr<U>& p) {
138 return RawPtr<T>(static_cast<T*>(p.get())); 126 return RawPtr<T>(static_cast<T*>(p.get()));
139 } 127 }
140 128
141 template<typename T> inline T* getPtr(const RawPtr<T>& p) 129 template <typename T>
142 { 130 inline T* getPtr(const RawPtr<T>& p) {
143 return p.get(); 131 return p.get();
144 } 132 }
145 133
146 } // namespace WTF 134 } // namespace WTF
147 135
148 using WTF::RawPtr; 136 using WTF::RawPtr;
149 137
150 #endif 138 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/PrintStream.cpp ('k') | third_party/WebKit/Source/wtf/RefCounted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698