Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 28, 2009, 5:16:36 PM (15 years ago)
Author:
landauf
Message:

added WeakPtr (a pointer which becomes 0 if the target object is deleted)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/SmartPtr.h

    r5807 r5823  
    3535
    3636#include <cassert>
    37 #include <ostream>
     37
    3838#include "OrxonoxClass.h"
     39#include "WeakPtr.h"
    3940
    4041namespace orxonox
     
    7172            }
    7273
     74            template <class O>
     75            inline SmartPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.getBase())
     76            {
     77                if (this->base_)
     78                    this->base_->incrementReferenceCount();
     79            }
     80
    7381            inline ~SmartPtr()
    7482            {
     
    102110            }
    103111
     112            template <class O>
     113            inline const SmartPtr& operator=(const WeakPtr<O>& other)
     114            {
     115                SmartPtr(other).swap(*this);
     116                return *this;
     117            }
     118
    104119            inline T* get() const
    105120            {
    106121                return this->pointer_;
     122            }
     123
     124            inline OrxonoxClass* getBase() const
     125            {
     126                return this->base_;
    107127            }
    108128
     
    153173    };
    154174
    155     template <class A, class B>
    156     inline bool operator==(const SmartPtr<A>& a, const SmartPtr<B>& b)
    157     {
    158         return (a.get() == b.get());
    159     }
    160 
    161     template <class A, class B>
    162     inline bool operator!=(const SmartPtr<A>& a, const SmartPtr<B>& b)
    163     {
    164         return (a.get() != b.get());
    165     }
    166 
    167     template <class T>
    168     inline bool operator<(const SmartPtr<T>& a, const SmartPtr<T>& b)
    169     {
    170         return std::less<T*>()(a.get(), b.get());
    171     }
    172 
    173175    template <class T>
    174176    void swap(SmartPtr<T>& a, SmartPtr<T>& b)
     
    194196        return dynamic_cast<T*>(p.get());
    195197    }
    196 
    197     template <class T>
    198     std::ostream& operator<<(std::ostream& os, const SmartPtr<T>& p)
    199     {
    200         os << p.get();
    201         return os;
    202     }
    203198}
    204199
Note: See TracChangeset for help on using the changeset viewer.