Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 27, 2009, 2:33:48 AM (15 years ago)
Author:
landauf
Message:
  • Enhanced SmartPtr: a) It stores now two pointers, one OrxonoxClass* (for reference counting) and one T* (for normal use). b) Incrementing the reference is now optional in the constructor for raw pointers. This is needed because Scene has a selfreference but should still be destroyable.
  • Changed BaseObject to store a SmartPtr to it's Scene instead of a normal pointer.
  • Changed setScene and getScene to deal directly with SmartPtr instead of a Scene* pointer to avoid casting-to-OrxonoxClass issues.
  • Fixed two problems with lost SceneManagers in CameraManger: a) added a SmartPtr to the Scene for the fallback camera b) added a call to GUIManager in the destructor to release the scene manager
  • Enabled unloading in GSLevel again (after years). Works if playing without bots.
File:
1 edited

Legend:

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

    r5804 r5805  
    4242    {
    4343        public:
    44             inline SmartPtr() : pointer_(0)
    45             {
    46             }
    47 
    48             inline SmartPtr(T* pointer) : pointer_(pointer)
    49             {
    50                 if (this->pointer_)
    51                     this->pointer_->incrementReferenceCount();
    52             }
    53 
    54             inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_)
    55             {
    56                 if (this->pointer_)
    57                     this->pointer_->incrementReferenceCount();
     44            inline SmartPtr() : pointer_(0), base_(0)
     45            {
     46            }
     47
     48            inline SmartPtr(int) : pointer_(0), base_(0)
     49            {
     50            }
     51
     52            inline SmartPtr(T* pointer, bool bAddRef = true) : pointer_(pointer), base_(pointer)
     53            {
     54                if (this->base_ && bAddRef)
     55                    this->base_->incrementReferenceCount();
     56            }
     57
     58            inline SmartPtr(const SmartPtr& other) : pointer_(other.pointer_), base_(other.base_)
     59            {
     60                if (this->base_)
     61                    this->base_->incrementReferenceCount();
    5862            }
    5963
    6064            template <class O>
    61             inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get())
    62             {
    63                 if (this->pointer_)
    64                     this->pointer_->incrementReferenceCount();
     65            inline SmartPtr(const SmartPtr<O>& other) : pointer_(other.get()), base_(other.base_)
     66            {
     67                if (this->base_)
     68                    this->base_->incrementReferenceCount();
    6569            }
    6670
    6771            inline ~SmartPtr()
    6872            {
    69                 if (this->pointer_)
    70                     this->pointer_->decrementReferenceCount();
     73                if (this->base_)
     74                    this->base_->decrementReferenceCount();
     75            }
     76           
     77            inline const SmartPtr& operator=(int)
     78            {
     79                SmartPtr(0).swap(*this);
     80                return *this;
    7181            }
    7282
     
    96106
    97107            inline operator T*() const
    98             {std::cout << "(implizit)";
     108            {
    99109                return this->pointer_;
    100110            }
     
    117127            inline void swap(SmartPtr& other)
    118128            {
    119                 T* temp = this->pointer_;
    120                 this->pointer_ = other.pointer_;
    121                 other.pointer_ = temp;
     129                {
     130                    T* temp = this->pointer_;
     131                    this->pointer_ = other.pointer_;
     132                    other.pointer_ = temp;
     133                }
     134                {
     135                    OrxonoxClass* temp = this->base_;
     136                    this->base_ = other.base_;
     137                    other.base_ = temp;
     138                }
    122139            }
    123140
     
    129146        private:
    130147            T* pointer_;
     148            OrxonoxClass* base_;
    131149    };
    132150
Note: See TracChangeset for help on using the changeset viewer.