Update of /cvsroot/mahogany/M/include
In directory sc8-pr-cvs1:/tmp/cvs-serv8984/include
Modified Files:
pointers.h strutil.h
Log Message:
Renamed AutoPtr to scoped_ptr
Index: pointers.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/pointers.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -b -u -2 -r1.7 -r1.8
--- pointers.h 16 Oct 2003 12:17:10 -0000 1.7
+++ pointers.h 16 Oct 2003 13:05:06 -0000 1.8
@@ -222,4 +222,7 @@
{
public:
+ /// same as auto_ptr<>::element_type
+ typedef T element_type;
+
/// Default constructor creates NULL pointer.
WeakRef() : m_pointer(NULL) {}
@@ -272,33 +275,56 @@
-// Equivalent of auto_ptr, but with private copy constructor and assignment
+/// Mostly boost::scoped_ptr clone.
template <class T>
-class AutoPtr
+class scoped_ptr
{
public:
- AutoPtr() { NewDefault(); }
- AutoPtr(T *copy) { NewCopy(); }
- ~AutoPtr() { Destroy(); }
+ /// same as auto_ptr<>::element_type
+ typedef T element_type;
+
+ /// a scalar type which doesn't risk to be converted to anything
+ typedef T *(scoped_ptr<T>::*unspecified_bool_type)() const;
+
+ /// Default constructor initializes to @c NULL.
+ scoped_ptr() : m_pointer(NULL) {}
- void Initialize(T *copy)
+ /// Takes ownership of raw pointer
+ scoped_ptr(T *copy) : m_pointer(copy) {}
+
+ /// Destructor deletes held pointer if it is not @c NULL.
+ ~scoped_ptr() { if( m_pointer ) delete m_pointer; }
+
+ /// Late construction. Delete previously help pointer.
+ void set(T *copy)
{
- Destroy();
+ if( m_pointer )
+ delete m_pointer;
m_pointer = copy;
}
- operator T *() { return Get(); }
- T *operator->() { return Get(); }
+ /// Return stored pointer.
+ T *get() const { return m_pointer; }
+
+ /// Allow use of this class as pointer.
+ T *operator->() const { return get(); }
+
+ /**
+ Implicit, but safe, conversion to bool.
+
+ It's copy of similar method in RefCounter.
+ */
+ operator unspecified_bool_type() const // never throws
+ {
+ return m_pointer ? &scoped_ptr<T>::get : NULL;
+ }
private:
- void NewDefault() { m_pointer = 0; }
- void NewCopy(T *copy) { m_pointer = copy; }
- void Destroy() { if( m_pointer ) delete m_pointer; }
+ /// Copy constructor is private.
+ scoped_ptr(const scoped_ptr<T>& copy) {}
- T *Get() { return m_pointer; }
+ /// Assignment operator is private.
+ void operator=(const scoped_ptr<T>& copy) {}
T *m_pointer;
-
- AutoPtr(const AutoPtr<T>& copy) {}
- void operator=(const AutoPtr<T>& copy) {}
};
Index: strutil.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/strutil.h,v
retrieving revision 1.68
retrieving revision 1.69
diff -b -u -2 -r1.68 -r1.69
--- strutil.h 12 Oct 2003 12:10:57 -0000 1.68
+++ strutil.h 16 Oct 2003 13:05:06 -0000 1.69
@@ -378,5 +378,5 @@
bool m_useRE;
// a RE to detect the start of the signature
- AutoPtr<wxRegEx> m_reSig;
+ scoped_ptr<wxRegEx> m_reSig;
#endif
};
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates