Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 20, 2010, 2:59:20 AM (14 years ago)
Author:
landauf
Message:

Added a small SharedPtr template for use in Functor and Executor. It's an intrusive approach that requires the object to implement a reference counter. The SharedPtr is extensible to reflect the hierarchy of Functor, FunctorStatic, FunctorMember<T>, and all subclasses (same for Executor).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/Functor.h

    r7189 r7192  
    3838#include "util/Debug.h"
    3939#include "util/MultiType.h"
     40#include "SharedPtr.h"
    4041
    4142namespace orxonox
     
    8889    class _CoreExport Functor
    8990    {
     91        friend class SharedPtr<Functor>;
     92
    9093        public:
    9194            struct Type
     
    101104
    102105        public:
    103             Functor() {}
    104             virtual ~Functor() {}
     106            Functor() : references_(0) { ++instances_s; COUT(0) << "functor ++: " << instances_s << std::endl; }
     107            virtual ~Functor() { --instances_s; COUT(0) << "functor --: " << instances_s << std::endl; }
    105108
    106109            virtual MultiType operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null) = 0;
     
    119122
    120123            virtual const std::type_info& getHeaderIdentifier() const = 0;
     124
     125        private:
     126            inline void incrementReferenceCount()
     127                { ++this->references_; }
     128            inline void decrementReferenceCount()
     129                { --this->references_; if (this->references_ == 0) delete this; }
     130
     131            int references_;
     132            static int instances_s;
    121133    };
    122134
     
    200212            T* object_;
    201213            const T* constObject_;
     214    };
     215
     216
     217
     218    typedef SharedPtr<Functor> FunctorPtr;
     219
     220    typedef SharedChildPtr<FunctorStatic, Functor> FunctorStaticPtr;
     221
     222    template <class T>
     223    class FunctorMemberPtr : public SharedChildPtr<FunctorMember<T>, Functor>
     224    {
     225        public:
     226            inline FunctorMemberPtr() : SharedChildPtr<FunctorMember<T>, Functor>() {}
     227            inline FunctorMemberPtr(FunctorMember<T>* pointer) : SharedChildPtr<FunctorMember<T>, Functor>(pointer) {}
     228//            inline FunctorMemberPtr(const FunctorMemberPtr& other) : SharedChildPtr<FunctorMember<T>, Functor>(other) {}
    202229    };
    203230
Note: See TracChangeset for help on using the changeset viewer.