tasn pushed a commit to branch master.

http://git.enlightenment.org/bindings/cxx/eflxx.git/commit/?id=fcd0e50a2248f51ab48e3ff6ce1b9a292918f449

commit fcd0e50a2248f51ab48e3ff6ce1b9a292918f449
Author: Andreas Volz <[email protected]>
Date:   Mon Apr 12 20:50:26 2010 +0000

    cast possibility for smart pointers
    
    
    SVN revision: 47973
---
 eflxx/include/eflxx/CountedPtr.h | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/eflxx/include/eflxx/CountedPtr.h b/eflxx/include/eflxx/CountedPtr.h
index 0de851a..92ebab1 100644
--- a/eflxx/include/eflxx/CountedPtr.h
+++ b/eflxx/include/eflxx/CountedPtr.h
@@ -21,6 +21,8 @@ class CountedPtr {
     long* count;   // shared number of owners
 
   public:
+    template <typename S> friend class CountedPtr;
+    
     // initialize pointer with existing pointer
     // - requires that the pointer p is a return value of new
     explicit CountedPtr (T* p=0)
@@ -29,20 +31,43 @@ class CountedPtr {
     }
 
     // copy pointer (one more owner)
-    CountedPtr (const CountedPtr<T>& p) throw()
+    CountedPtr (const CountedPtr<T>& p)
      : ptr(p.ptr), count(p.count) 
     {
         ++*count;
     }
-
+    
+    template <class S>
+    CountedPtr (const CountedPtr<S>& p)
+      : ptr(p.ptr), count(p.count) 
+    {
+        ++*count;
+    }
+    
+    template <class S>
+    static CountedPtr<T> cast_static (const CountedPtr<S>& p)
+    {
+        T *obj = static_cast <T*> (&(*p));
+        
+        return CountedPtr<T> (obj);
+    }
+    
+    template <class S>
+    static CountedPtr<T> cast_dynamic (const CountedPtr<S>& p)
+    {
+        T *obj = dynamic_cast <T*> (&(*p));
+        
+        return CountedPtr<T> (obj);
+    }
+    
     // destructor (delete value if this was the last owner)
-    ~CountedPtr () throw() 
+    ~CountedPtr ()
     {
         dispose();
     }
 
     // assignment (unshare old and share new value)
-    CountedPtr<T>& operator= (const CountedPtr<T>& p) throw() 
+    CountedPtr<T>& operator= (const CountedPtr<T>& p) 
     {
         if (this != &p) {
             dispose();
@@ -54,11 +79,11 @@ class CountedPtr {
     }
 
     // access the value to which the pointer refers
-    T& operator*() const throw() 
+    T& operator*() const
     {
         return *ptr;
     }
-    T* operator->() const throw() 
+    T* operator->() const 
     {
         return ptr;
     }

-- 


Reply via email to