@@ -166,22 +166,24 @@ class robj_sharedptr
166
166
167
167
public:
168
168
robj_sharedptr ()
169
- : m_ptr(nullptr )
170
- {}
171
- robj_sharedptr (redisObject *ptr)
172
- : m_ptr(ptr)
173
- {
169
+ : m_ptr(nullptr )
170
+ {}
171
+ explicit robj_sharedptr (redisObject *ptr)
172
+ : m_ptr(ptr)
173
+ {
174
+ if (m_ptr)
174
175
incrRefCount (ptr);
175
- }
176
+ }
176
177
~robj_sharedptr ()
177
178
{
178
179
if (m_ptr)
179
180
decrRefCount (m_ptr);
180
181
}
181
182
robj_sharedptr (const robj_sharedptr& other)
182
- {
183
- m_ptr = other.m_ptr ;
184
- incrRefCount (m_ptr);
183
+ : m_ptr(other.m_ptr)
184
+ {
185
+ if (m_ptr)
186
+ incrRefCount (m_ptr);
185
187
}
186
188
187
189
robj_sharedptr (robj_sharedptr&& other)
@@ -192,41 +194,19 @@ class robj_sharedptr
192
194
193
195
robj_sharedptr &operator =(const robj_sharedptr& other)
194
196
{
195
- if (m_ptr)
196
- decrRefCount (m_ptr);
197
- m_ptr = other.m_ptr ;
198
- incrRefCount (m_ptr);
197
+ robj_sharedptr tmp (other);
198
+ using std::swap;
199
+ swap (m_ptr, tmp.m_ptr );
199
200
return *this ;
200
201
}
201
202
robj_sharedptr &operator =(redisObject *ptr)
202
203
{
203
- if (m_ptr)
204
- decrRefCount (m_ptr);
205
- m_ptr = ptr;
206
- incrRefCount (m_ptr);
204
+ robj_sharedptr tmp (ptr);
205
+ using std::swap;
206
+ swap (m_ptr, tmp.m_ptr );
207
207
return *this ;
208
208
}
209
-
210
- bool operator ==(const robj_sharedptr &other) const
211
- {
212
- return m_ptr == other.m_ptr ;
213
- }
214
-
215
- bool operator ==(const void *p) const
216
- {
217
- return m_ptr == p;
218
- }
219
-
220
- bool operator !=(const robj_sharedptr &other) const
221
- {
222
- return m_ptr != other.m_ptr ;
223
- }
224
-
225
- bool operator !=(const void *p) const
226
- {
227
- return m_ptr != p;
228
- }
229
-
209
+
230
210
redisObject* operator ->() const
231
211
{
232
212
return m_ptr;
@@ -237,7 +217,7 @@ class robj_sharedptr
237
217
return !m_ptr;
238
218
}
239
219
240
- operator bool () const {
220
+ explicit operator bool () const {
241
221
return !!m_ptr;
242
222
}
243
223
@@ -247,8 +227,39 @@ class robj_sharedptr
247
227
}
248
228
249
229
redisObject *get () { return m_ptr; }
230
+ const redisObject *get () const { return m_ptr; }
250
231
};
251
232
233
+ inline bool operator ==(const robj_sharedptr &lhs, const robj_sharedptr &rhs)
234
+ {
235
+ return lhs.get () == rhs.get ();
236
+ }
237
+
238
+ inline bool operator !=(const robj_sharedptr &lhs, const robj_sharedptr &rhs)
239
+ {
240
+ return !(lhs == rhs);
241
+ }
242
+
243
+ inline bool operator ==(const robj_sharedptr &lhs, const void *p)
244
+ {
245
+ return lhs.get () == p;
246
+ }
247
+
248
+ inline bool operator ==(const void *p, const robj_sharedptr &rhs)
249
+ {
250
+ return rhs == p;
251
+ }
252
+
253
+ inline bool operator !=(const robj_sharedptr &lhs, const void *p)
254
+ {
255
+ return !(lhs == p);
256
+ }
257
+
258
+ inline bool operator !=(const void *p, const robj_sharedptr &rhs)
259
+ {
260
+ return !(rhs == p);
261
+ }
262
+
252
263
/* Error codes */
253
264
#define C_OK 0
254
265
#define C_ERR -1
0 commit comments