Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/intrusive_ptr.h

Issue 29548581: Issue 4128, 5138 - Add Parser and Serializer implemented in C++ Base URL: https://github.com/adblockplus/adblockpluscore.git
Patch Set: Created Sept. 18, 2017, 5:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 virtual ~ref_counted() 54 virtual ~ref_counted()
55 { 55 {
56 assert(mRefCount == 0, u"Destroying a ref-counted object with a non-zero ref erence count"_str); 56 assert(mRefCount == 0, u"Destroying a ref-counted object with a non-zero ref erence count"_str);
57 } 57 }
58 58
59 private: 59 private:
60 int mRefCount; 60 int mRefCount;
61 }; 61 };
62 62
63 template<typename T, 63 template<typename T>
64 class = typename std::enable_if<std::is_base_of<ref_counted,T>::value>::type >
65 class intrusive_ptr 64 class intrusive_ptr
66 { 65 {
66 static_assert(std::is_base_of<ref_counted, T>::value, "The class T should inhe rit ref_counted");
67 public: 67 public:
68 explicit intrusive_ptr() 68 explicit intrusive_ptr()
69 : mPointer(nullptr) 69 : mPointer(nullptr)
70 { 70 {
71 } 71 }
72 72
73 explicit intrusive_ptr(T* pointer, bool addRef = true) 73 explicit intrusive_ptr(T* pointer, bool addRef = true)
74 : mPointer(pointer) 74 : mPointer(pointer)
75 { 75 {
76 if (mPointer && addRef) 76 if (mPointer && addRef)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 { 112 {
113 intrusive_ptr(other).swap(*this); 113 intrusive_ptr(other).swap(*this);
114 return *this; 114 return *this;
115 } 115 }
116 116
117 void reset() 117 void reset()
118 { 118 {
119 intrusive_ptr().swap(*this); 119 intrusive_ptr().swap(*this);
120 } 120 }
121 121
122 void reset(T* other) 122 void reset(T* other, bool addRef = true)
123 { 123 {
124 intrusive_ptr(other).swap(*this); 124 intrusive_ptr(other, addRef).swap(*this);
125 } 125 }
126 126
127 const T* get() const 127 const T* get() const
128 { 128 {
129 return mPointer; 129 return mPointer;
130 } 130 }
131 131
132 T* get() 132 T* get()
133 { 133 {
134 return mPointer; 134 return mPointer;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 inline bool operator==(const T* a, const intrusive_ptr<U>& b) 208 inline bool operator==(const T* a, const intrusive_ptr<U>& b)
209 { 209 {
210 return a == b.get(); 210 return a == b.get();
211 } 211 }
212 212
213 template<typename T, typename U> 213 template<typename T, typename U>
214 inline bool operator!=(const T* a, intrusive_ptr<U> const& b) 214 inline bool operator!=(const T* a, intrusive_ptr<U> const& b)
215 { 215 {
216 return a != b.get(); 216 return a != b.get();
217 } 217 }
OLDNEW

Powered by Google App Engine
This is Rietveld