]> Dogcows Code - chaz/yoink/blobdiff - src/stlplus/containers/simple_ptr.hpp
import stlplus 3.7
[chaz/yoink] / src / stlplus / containers / simple_ptr.hpp
index 08fff036eb91612865a8207b777e57deaa91e303..ffe2c8afeee60a56feeab042205db5a54f5b013f 100644 (file)
@@ -2,9 +2,8 @@
 #define STLPLUS_SIMPLE_PTR\r
 ////////////////////////////////////////////////////////////////////////////////\r
 \r
-//   Author:    Daniel Milton, Andy Rushton\r
-//   Copyright: (c) Southampton University 1999-2004\r
-//              (c) Daniel Milton, Andy Rushton 2004-2009\r
+//   Author:    Daniel Milton\r
+//   Copyright: (c) Daniel Milton           2002 onwards\r
 //   License:   BSD License, see ../docs/license.html\r
 \r
 //   A smart pointer is a memory-managing pointer to an object. If you like, it\r
@@ -76,11 +75,6 @@ namespace stlplus
     // create a null pointer\r
     simple_ptr_base(void);\r
 \r
-    // create a pointer containing a *copy* of the object using the template parameter C\r
-    // this copy is taken because the pointer class maintains a dynamically allocated object\r
-    // and the T& may not be (usually is not) dynamically allocated\r
-    explicit simple_ptr_base(const T& data) throw(illegal_copy);\r
-\r
     // create a pointer containing a dynamically created object\r
     // Note: the object must be allocated *by the user* with new\r
     // constructor form - must be called in the form smart_ptr_base<type> x(new type(args))\r
@@ -122,8 +116,6 @@ namespace stlplus
     //////////////////////////////////////////////////////////////////////////////\r
     // explicit function forms of the above assignment and dereference operators\r
 \r
-    // set the value - note that this does a copy using the C template parameter\r
-    void set_value(const T& data) throw(illegal_copy);\r
     // get the value\r
     T& value(void) throw(null_dereference);\r
     const T& value(void) const throw(null_dereference);\r
@@ -167,6 +159,14 @@ namespace stlplus
     // to copy the object with the right copy semantics. If the copy functor\r
     // is no_copy, an exception will be thrown.\r
 \r
+    // create a pointer containing a *copy* of the object using the template parameter C\r
+    // this copy is taken because the pointer class maintains a dynamically allocated object\r
+    // and the T& may not be (usually is not) dynamically allocated\r
+    explicit simple_ptr_base(const T& data) throw(illegal_copy);\r
+\r
+    // set the value - note that this does a copy using the C template parameter\r
+    void set_value(const T& data) throw(illegal_copy);\r
+\r
     // make this pointer unique with respect to any other references to the same object\r
     // if this pointer is already unique, it does nothing - otherwise it copies the object\r
     void make_unique(void) throw(illegal_copy);\r
@@ -176,22 +176,6 @@ namespace stlplus
     void copy(const simple_ptr_base<T,C>&) throw(illegal_copy);\r
 \r
     //////////////////////////////////////////////////////////////////////////////\r
-    // functions that involve casting\r
-\r
-#ifdef STLPLUS_MEMBER_TEMPLATES\r
-\r
-    // dynamic cast of underlying pointer to a derived/parent\r
-    template<typename T2> simple_ptr_base<T2,C> dyn_cast(void) const;\r
-\r
-    // static cast of underlying pointer to a derived/parent\r
-    template<typename T2> simple_ptr_base<T2,C> stat_cast(void) const;\r
-\r
-    // cast of underlying pointer to a base - while keeping the same ref-counted object\r
-    template<typename T2> simple_ptr_base<T2,C> cast(void) const;\r
-\r
-#endif\r
-\r
-    //////////////////////////////////////////////////////////////////////////////\r
 \r
   protected:\r
     T* m_pointer;\r
@@ -224,10 +208,30 @@ namespace stlplus
     simple_ptr<T>& operator=(const T& data) {set_value(data); return *this;}\r
     simple_ptr<T>& operator=(T* data) {set(data); return *this;}\r
     ~simple_ptr(void) {}\r
+\r
+#ifdef STLPLUS_MEMBER_TEMPLATES\r
+    // functions that involve casting\r
+    // moved from base class for two main reasons, though the second is a feature of the first:\r
+\r
+    // 1. GCC cannot cast the previous base result of simple_ptr_base<T2, constructor_copy<T> >\r
+    //    as a simple_ptr<T2> even though it used to look like a duck and quack like a duck.\r
+    //    I think it was really complaining that the copy class was not guaranteed to be the same.\r
+\r
+    // 2. Within the cast routines, one pointer type tried accessing private data of the other\r
+    //    pointer type and even though they are really the same type, was not allowed. Because\r
+    //    of this, the "private" function _make_alias is utilised to get the same result.\r
+\r
+    // By having the cast functions in each derived class, you are guaranteed to use the same\r
+    // copy class - no question. GCC is ok with this.\r
+\r
+    template<typename T2> simple_ptr<T2> dyn_cast(void) const;\r
+    template<typename T2> simple_ptr<T2> stat_cast(void) const;\r
+    template<typename T2> simple_ptr<T2> cast(void) const;\r
+#endif\r
   };\r
 \r
   ////////////////////////////////////////////////////////////////////////////////\r
-  // smart_ptr_clone  for polymorphic class hierarchies which have a clone method\r
+  // simple_ptr_clone  for polymorphic class hierarchies which have a clone method\r
 \r
   template <typename T>\r
   class simple_ptr_clone : public simple_ptr_base<T, clone_copy<T> >\r
@@ -239,21 +243,35 @@ namespace stlplus
     simple_ptr_clone<T>& operator=(const T& data) {set_value(data); return *this;}\r
     simple_ptr_clone<T>& operator=(T* data) {set(data); return *this;}\r
     ~simple_ptr_clone(void) {}\r
-  };\r
+\r
+#ifdef STLPLUS_MEMBER_TEMPLATES\r
+    // functions that involve casting\r
+    // moved from base class - see simple_ptr above\r
+    template<typename T2> simple_ptr_clone<T2> dyn_cast(void) const;\r
+    template<typename T2> simple_ptr_clone<T2> stat_cast(void) const;\r
+    template<typename T2> simple_ptr_clone<T2> cast(void) const;\r
+#endif\r
+};\r
 \r
   ////////////////////////////////////////////////////////////////////////////////\r
-  // smart_ptr_nocopy for any class that cannot or should not be copied\r
+  // simple_ptr_nocopy for any class that cannot or should not be copied\r
 \r
   template <typename T>\r
   class simple_ptr_nocopy : public simple_ptr_base<T, no_copy<T> >\r
   {\r
   public:\r
     simple_ptr_nocopy(void) {}\r
-    explicit simple_ptr_nocopy(const T& data) : simple_ptr_base<T, no_copy<T> >(data) {}\r
     explicit simple_ptr_nocopy(T* data) : simple_ptr_base<T, no_copy<T> >(data) {}\r
-    simple_ptr_nocopy<T>& operator=(const T& data) {set_value(data); return *this;}\r
     simple_ptr_nocopy<T>& operator=(T* data) {set(data); return *this;}\r
     ~simple_ptr_nocopy(void) {}\r
+\r
+#ifdef STLPLUS_MEMBER_TEMPLATES\r
+    // functions that involve casting\r
+    // moved from base class - see simple_ptr above\r
+    template<typename T2> simple_ptr_nocopy<T2> dyn_cast(void) const;\r
+    template<typename T2> simple_ptr_nocopy<T2> stat_cast(void) const;\r
+    template<typename T2> simple_ptr_nocopy<T2> cast(void) const;\r
+#endif\r
   };\r
 \r
   ////////////////////////////////////////////////////////////////////////////////\r
This page took 0.022575 seconds and 4 git commands to generate.