Update of /cvsroot/mahogany/M/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14005/include
Modified Files:
pointers.h
Log Message:
renamed scoped_ptr::set() to reset(); added scoped_array
Index: pointers.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/pointers.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -b -u -2 -r1.8 -r1.9
--- pointers.h 16 Oct 2003 13:05:06 -0000 1.8
+++ pointers.h 11 Jul 2004 12:55:44 -0000 1.9
@@ -293,10 +293,9 @@
/// Destructor deletes held pointer if it is not @c NULL.
- ~scoped_ptr() { if( m_pointer ) delete m_pointer; }
+ ~scoped_ptr() { delete m_pointer; }
/// Late construction. Delete previously help pointer.
- void set(T *copy)
+ void reset(T *copy = NULL)
{
- if( m_pointer )
delete m_pointer;
m_pointer = copy;
@@ -329,4 +328,57 @@
};
+/// Mostly boost::scoped_array clone.
+template <class T>
+class scoped_array
+{
+public:
+ /// 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_array<T>::*unspecified_bool_type)() const;
+
+ /// Default constructor initializes to @c NULL.
+ scoped_array() : m_pointer(NULL) {}
+
+ /// Takes ownership of raw pointer
+ scoped_array(T *copy) : m_pointer(copy) {}
+
+ /// Destructor deletes held pointer if it is not @c NULL.
+ ~scoped_array() { delete [] m_pointer; }
+
+ /// Late construction. Delete previously help pointer.
+ void reset(T *copy = NULL)
+ {
+ delete[] m_pointer;
+ m_pointer = copy;
+ }
+
+ /// 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_array<T>::get : NULL;
+ }
+
+private:
+ /// Copy constructor is private.
+ scoped_array(const scoped_array<T>& copy) {}
+
+ /// Assignment operator is private.
+ void operator=(const scoped_array<T>& copy) {}
+
+ T *m_pointer;
+};
+
/**
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates