Index: code/branches/consolecommands3/src/libraries/core/Executor.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.cc	(revision 7195)
+++ code/branches/consolecommands3/src/libraries/core/Executor.cc	(revision 7196)
@@ -44,5 +44,4 @@
     Executor::Executor(Functor* functor, const std::string& name)
     {
-        this->references_ = 0;
         this->functor_ = functor;
         this->name_ = name;
Index: code/branches/consolecommands3/src/libraries/core/Executor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Executor.h	(revision 7195)
+++ code/branches/consolecommands3/src/libraries/core/Executor.h	(revision 7196)
@@ -36,4 +36,5 @@
 #include "util/MultiType.h"
 #include "Functor.h"
+#include "ExecutorPtr.h"
 
 namespace orxonox
@@ -112,10 +113,4 @@
 
         private:
-            inline void incrementReferenceCount()
-                { ++this->references_; }
-            inline void decrementReferenceCount()
-                { --this->references_; if (this->references_ == 0) delete this; }
-
-            int references_;
             static int instances_s;
     };
@@ -198,21 +193,4 @@
     };
 
-
-
-    typedef SharedPtr<Executor> ExecutorPtr;
-
-    typedef SharedChildPtr<ExecutorStatic, Executor> ExecutorStaticPtr;
-
-    template <class T>
-    class ExecutorMemberPtr : public SharedChildPtr<ExecutorMember<T>, Executor>
-    {
-        public:
-            inline ExecutorMemberPtr() : SharedChildPtr<ExecutorMember<T>, Executor>() {}
-            inline ExecutorMemberPtr(ExecutorMember<T>* pointer) : SharedChildPtr<ExecutorMember<T>, Executor>(pointer) {}
-//            inline ExecutorMemberPtr(const ExecutorMemberPtr& other) : SharedChildPtr<ExecutorMember<T>, Executor>(other) {}
-    };
-
-
-
     inline Executor* createExecutor(Functor* functor, const std::string& name = "")
     {
Index: code/branches/consolecommands3/src/libraries/core/ExecutorPtr.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/ExecutorPtr.h	(revision 7196)
+++ code/branches/consolecommands3/src/libraries/core/ExecutorPtr.h	(revision 7196)
@@ -0,0 +1,71 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ExecutorPtr_H__
+#define _ExecutorPtr_H__
+
+#include "CorePrereqs.h"
+#include "SharedPtr.h"
+
+namespace orxonox
+{
+    typedef SharedPtr<Executor> ExecutorPtr;
+
+    typedef SharedPtr<ExecutorStatic> ExecutorStaticPtr;
+
+    template <class T>
+    class ExecutorMemberPtr : public SharedPtr<ExecutorMember<T> >
+    {
+        public:
+            inline ExecutorMemberPtr() : SharedPtr<ExecutorMember<T> >() {}
+            inline ExecutorMemberPtr(ExecutorMember<T>* pointer) : SharedPtr<ExecutorMember<T> >(pointer) {}
+//            inline ExecutorMemberPtr(const ExecutorMemberPtr& other) : SharedPtr<ExecutorMember<T> >(other) {}
+            template <class O>
+            inline ExecutorMemberPtr(const SharedPtr<O>& other) : SharedPtr<ExecutorMember<T> >(other) {}
+/*
+            inline const ExecutorMemberPtr& operator=(const ExecutorMemberPtr& other) { this->SharedPtr<ExecutorMember<T> >::operator=(other); return *this; }
+            template <class O>
+            inline const ExecutorMemberPtr& operator=(const SharedPtr<O>& other) { this->SharedPtr<ExecutorMember<T> >::operator=(other); return *this; }
+*/
+        private:
+//            inline ExecutorMemberPtr(ExecutorMember<T>* pointer, int* counter) : SharedPtr<ExecutorMember<T> >(pointer, counter) {}
+    };
+/*
+    typedef SharedChildPtr<ExecutorStatic, Executor> ExecutorStaticPtr;
+
+    template <class T>
+    class ExecutorMemberPtr : public SharedChildPtr<ExecutorMember<T>, Executor>
+    {
+        public:
+            inline ExecutorMemberPtr() : SharedChildPtr<ExecutorMember<T>, Executor>() {}
+            inline ExecutorMemberPtr(ExecutorMember<T>* pointer) : SharedChildPtr<ExecutorMember<T>, Executor>(pointer) {}
+    };
+*/
+}
+
+#endif /* _ExecutorPtr_H__ */
Index: code/branches/consolecommands3/src/libraries/core/Functor.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/Functor.h	(revision 7195)
+++ code/branches/consolecommands3/src/libraries/core/Functor.h	(revision 7196)
@@ -38,5 +38,5 @@
 #include "util/Debug.h"
 #include "util/MultiType.h"
-#include "SharedPtr.h"
+#include "FunctorPtr.h"
 
 namespace orxonox
@@ -104,5 +104,5 @@
 
         public:
-            Functor() : references_(0) { ++instances_s; COUT(0) << "functor ++: " << instances_s << std::endl; }
+            Functor() { ++instances_s; COUT(0) << "functor ++: " << instances_s << std::endl; }
             virtual ~Functor() { --instances_s; COUT(0) << "functor --: " << instances_s << std::endl; }
 
@@ -124,10 +124,4 @@
 
         private:
-            inline void incrementReferenceCount()
-                { ++this->references_; }
-            inline void decrementReferenceCount()
-                { --this->references_; if (this->references_ == 0) delete this; }
-
-            int references_;
             static int instances_s;
     };
@@ -212,19 +206,4 @@
             T* object_;
             const T* constObject_;
-    };
-
-
-
-    typedef SharedPtr<Functor> FunctorPtr;
-
-    typedef SharedChildPtr<FunctorStatic, Functor> FunctorStaticPtr;
-
-    template <class T>
-    class FunctorMemberPtr : public SharedChildPtr<FunctorMember<T>, Functor>
-    {
-        public:
-            inline FunctorMemberPtr() : SharedChildPtr<FunctorMember<T>, Functor>() {}
-            inline FunctorMemberPtr(FunctorMember<T>* pointer) : SharedChildPtr<FunctorMember<T>, Functor>(pointer) {}
-//            inline FunctorMemberPtr(const FunctorMemberPtr& other) : SharedChildPtr<FunctorMember<T>, Functor>(other) {}
     };
 
Index: code/branches/consolecommands3/src/libraries/core/FunctorPtr.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/FunctorPtr.h	(revision 7196)
+++ code/branches/consolecommands3/src/libraries/core/FunctorPtr.h	(revision 7196)
@@ -0,0 +1,71 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _FunctorPtr_H__
+#define _FunctorPtr_H__
+
+#include "CorePrereqs.h"
+#include "SharedPtr.h"
+
+namespace orxonox
+{
+    typedef SharedPtr<Functor> FunctorPtr;
+
+    typedef SharedPtr<FunctorStatic> FunctorStaticPtr;
+
+    template <class T>
+    class FunctorMemberPtr : public SharedPtr<FunctorMember<T> >
+    {
+        public:
+            inline FunctorMemberPtr() : SharedPtr<FunctorMember<T> >() {}
+            inline FunctorMemberPtr(FunctorMember<T>* pointer) : SharedPtr<FunctorMember<T> >(pointer) {}
+//            inline FunctorMemberPtr(const FunctorMemberPtr& other) : SharedPtr<FunctorMember<T> >(other) {}
+            template <class O>
+            inline FunctorMemberPtr(const SharedPtr<O>& other) : SharedPtr<FunctorMember<T> >(other) {}
+/*
+            inline const FunctorMemberPtr& operator=(const FunctorMemberPtr& other) { this->SharedPtr<FunctorMember<T> >::operator=(other); return *this; }
+            template <class O>
+            inline const FunctorMemberPtr& operator=(const SharedPtr<O>& other) { this->SharedPtr<FunctorMember<T> >::operator=(other); return *this; }
+*/
+        private:
+//            inline FunctorMemberPtr(FunctorMember<T>* pointer, int* counter) : SharedPtr<FunctorMember<T> >(pointer, counter) {}
+    };
+/*
+    typedef SharedChildPtr<FunctorStatic, Functor> FunctorStaticPtr;
+
+    template <class T>
+    class FunctorMemberPtr : public SharedChildPtr<FunctorMember<T>, Functor>
+    {
+        public:
+            inline FunctorMemberPtr() : SharedChildPtr<FunctorMember<T>, Functor>() {}
+            inline FunctorMemberPtr(FunctorMember<T>* pointer) : SharedChildPtr<FunctorMember<T>, Functor>(pointer) {}
+    };
+*/
+}
+
+#endif /* _FunctorPtr_H__ */
Index: code/branches/consolecommands3/src/libraries/core/SharedPtr.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/SharedPtr.h	(revision 7195)
+++ code/branches/consolecommands3/src/libraries/core/SharedPtr.h	(revision 7196)
@@ -31,28 +31,65 @@
 
 #include "CorePrereqs.h"
+#include <algorithm>
 
 namespace orxonox
 {
+    class SharedPtrDestroyer
+    {
+        public:
+            virtual void destroy() = 0;
+    };
+
+    template <class T>
+    class SharedPtrDestroyerImpl : public SharedPtrDestroyer
+    {
+        public:
+            SharedPtrDestroyerImpl(T* pointer) : pointer_(pointer) {}
+
+            void destroy()
+            {
+//                COUT(0) << "delete " << this->pointer_ << std::endl;
+                delete this->pointer_;
+            }
+
+        private:
+            T* pointer_;
+    };
+
     template <class T>
     class SharedPtr
     {
+        template <class O>
+        friend class SharedPtr;
+
         public:
-            inline SharedPtr() : pointer_(0)
+            inline SharedPtr() : pointer_(0), counter_(0), destroyer_(0)
             {
 //                COUT(0) << "SharedPtr (1): " << this->pointer_ << std::endl;
             }
 
-            inline SharedPtr(T* pointer) : pointer_(pointer)
+            inline SharedPtr(T* pointer) : pointer_(pointer), counter_(0), destroyer_(0)
             {
 //                COUT(0) << "SharedPtr (2): " << this->pointer_ << std::endl;
                 if (this->pointer_)
-                    this->pointer_->incrementReferenceCount();
+                {
+                    this->counter_ = new int(1);
+                    this->destroyer_ = new SharedPtrDestroyerImpl<T>(this->pointer_);
+                }
             }
 
-            inline SharedPtr(const SharedPtr& other) : pointer_(other.pointer_)
+            inline SharedPtr(const SharedPtr& other) : pointer_(other.pointer_), counter_(other.counter_), destroyer_(other.destroyer_)
             {
 //                COUT(0) << "SharedPtr (3): " << this->pointer_ << std::endl;
                 if (this->pointer_)
-                    this->pointer_->incrementReferenceCount();
+                    ++(*this->counter_);
+            }
+
+            template <class O>
+            inline SharedPtr(const SharedPtr<O>& other) : pointer_(other.pointer_), counter_(other.counter_), destroyer_(other.destroyer_)
+            {
+//                COUT(0) << "SharedPtr (4): " << this->pointer_ << std::endl;
+                if (this->pointer_)
+                    ++(*this->counter_);
             }
 
@@ -61,18 +98,36 @@
 //                COUT(0) << "~SharedPtr: " << this->pointer_ << std::endl;
                 if (this->pointer_)
-                    this->pointer_->decrementReferenceCount();
+                {
+                    --(*this->counter_);
+
+                    if (*this->counter_ == 0)
+                    {
+                        this->destroyer_->destroy();
+                        delete this->destroyer_;
+                        delete this->counter_;
+                    }
+                }
             }
 
             inline const SharedPtr& operator=(const SharedPtr& other)
             {
-//                COUT(0) << "SharedPtr=" << std::endl;
+//                COUT(0) << "SharedPtr= (1)" << std::endl;
                 SharedPtr(other).swap(*this);
                 return *this;
             }
 
-            inline void cast(const SharedPtr& other)
+            template <class O>
+            inline const SharedPtr& operator=(const SharedPtr<O>& other)
             {
-//                COUT(0) << "SharedPtr cast" << std::endl;
+//                COUT(0) << "SharedPtr= (2)" << std::endl;
                 SharedPtr(other).swap(*this);
+                return *this;
+            }
+
+            template <class O>
+            inline SharedPtr<O> cast() const
+            {
+                O* temp = static_cast<O*>(this->pointer_); // temp value for prettier compiler error in case of an invalid static_cast
+                return SharedPtr<O>(temp, this->counter_, this->destroyer_);
             }
 
@@ -96,13 +151,22 @@
             inline void swap(SharedPtr& other)
             {
-                T* temp = this->pointer_;
-                this->pointer_ = other.pointer_;
-                other.pointer_ = temp;
+                std::swap(this->pointer_, other.pointer_);
+                std::swap(this->counter_, other.counter_);
+                std::swap(this->destroyer_, other.destroyer_);
             }
 
         private:
+            inline SharedPtr(T* pointer, int* counter, SharedPtrDestroyer* destroyer) : pointer_(pointer), counter_(counter), destroyer_(destroyer)
+            {
+//                COUT(0) << "SharedPtr (5): " << this->pointer_ << std::endl;
+                if (this->pointer_)
+                    ++(*this->counter_);
+            }
+
             T* pointer_;
+            int* counter_;
+            SharedPtrDestroyer* destroyer_;
     };
-
+/*
     template <class T, class Parent>
     class SharedChildPtr : public SharedPtr<Parent>
@@ -116,4 +180,5 @@
             inline T& operator*() const { return *static_cast<T*>(SharedPtr<Parent>::operator->()); }
     };
+*/
 }
 
