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

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

Issue 137483003: Add template aliases to support both reference counting and garbage collection for a transition per… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ENABLE(OILPAN) Created 6 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 | Annotate | Revision Log
« Source/heap/Handle.h ('K') | « Source/heap/HeapTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2014 Google, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
haraken 2014/01/16 05:21:22 Not APPLE :) Please use the copyright in heap/Heap
Mads Ager (chromium) 2014/01/16 07:04:15 Heh! Without thinking I copied this from RefPtr.h.
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef WTF_Ptr_h
27 #define WTF_Ptr_h
28
29 // Ptr is a simple wrapper for a raw pointer that provides the
30 // interface (get, clear) of other pointer types such as RefPtr,
haraken 2014/01/16 05:21:22 Are compilers smart enough to optimize Ptr operati
Mads Ager (chromium) 2014/01/16 07:04:15 Yes, they should be. The issue that we saw when we
haraken 2014/01/16 07:06:40 Makes sense. Thanks for the clarification.
31 // Persistent and Member. This is used for the Blink garbage
32 // collection work in order to be able to write shared code that will
33 // use reference counting or garbage collection based on a
34 // compile-time flag.
35
36 namespace WTF {
37
38 template<typename T>
39 class Ptr {
40 public:
41 Ptr(T* ptr) : m_ptr(ptr) { }
42 Ptr(std::nullptr_t) : m_ptr(0) { }
43
44 template<typename U>
45 Ptr(const Ptr<U>& other)
46 : m_ptr(other.get())
47 {
48 }
49
50 T* get() const { return m_ptr; }
51 void clear() { m_ptr = 0; }
52
53 Ptr& operator=(T* ptr)
54 {
55 m_ptr = ptr;
56 return *this;
57 }
58
59 Ptr& operator=(std::nullptr_t)
60 {
61 m_ptr = 0;
62 return *this;
63 }
64
65 operator T*() const { return m_ptr; }
66 T& operator*() const { return *m_ptr; }
haraken 2014/01/16 05:21:22 Don't we need: const T& operator*() const; ?
Mads Ager (chromium) 2014/01/16 07:04:15 I don't think so, no. T itself can be something li
67 T* operator->() const { return m_ptr; }
68 bool operator!() const { return !m_ptr; }
69
70 // This conversion operator allows implicit conversion to bool but
71 // not to other integer types.
72 typedef T* Ptr::*UnspecifiedBoolType;
73 operator UnspecifiedBoolType() const { return m_ptr ? &m_ptr : 0; }
74
75 private:
76 T* m_ptr;
77 };
78
79 } // namespace WTF
80
81 using WTF::Ptr;
82
83 #endif
OLDNEW
« Source/heap/Handle.h ('K') | « Source/heap/HeapTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698