Update of /cvsroot/pclasses/pclasses2/include/pclasses
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32619/include/pclasses
Modified Files:
SharedPtr.h
Log Message:
- Removed "operator bool()" from SharedPtr, it's dangerous
- Added more compare operators to SharedPtr
Index: SharedPtr.h
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/SharedPtr.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- SharedPtr.h 20 May 2005 14:21:29 -0000 1.3
+++ SharedPtr.h 24 May 2005 03:07:32 -0000 1.4
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2004 by Christian Prochnow *
+ * Copyright (C) 2004,2005 by Christian Prochnow, SecuLogiX GmbH *
* cp...@se... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -47,6 +47,9 @@
~SharedPtr() throw()
{ _ptr->putRef(); }
+ bool null() const throw()
+ { return !_ptr->ptr; }
+
Type* get() const throw()
{ return _ptr->ptr; }
@@ -72,9 +75,6 @@
Type* operator->() throw()
{ return _ptr->ptr; }
- operator bool() const throw()
- { return _ptr->ptr ? true : false; }
-
SharedPtr& operator=(Type* ptr) throw(OutOfMemory)
{
SharedPtr(ptr).swap(*this);
@@ -96,9 +96,31 @@
bool operator==(const SharedPtr& ptr) const throw()
{ return _ptr == ptr._ptr; }
+ bool operator==(const Type* ptr) const throw()
+ { return _ptr == ptr; }
+
+ template <class Type2>
+ bool operator==(const SharedPtr<Type2>& ptr) const throw()
+ { return _ptr == ptr.get(); }
+
+ template <class Type2>
+ bool operator==(const Type2* ptr) const throw()
+ { return _ptr == ptr; }
+
bool operator!=(const SharedPtr& ptr) const throw()
{ return _ptr != ptr._ptr; }
+ bool operator!=(Type* ptr) const throw()
+ { return _ptr != ptr; }
+
+ template <class Type2>
+ bool operator!=(const SharedPtr<Type2>& ptr) const throw()
+ { return _ptr != ptr.get(); }
+
+ template <class Type2>
+ bool operator!=(const Type2* ptr) const throw()
+ { return _ptr != ptr; }
+
private:
//! Private data structure
|