Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 17, 2016, 10:29:21 PM (8 years ago)
Author:
landauf
Message:

merged branch cpp11_v3 back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/object/WeakPtr.h

    r10624 r11071  
    3737
    3838    A WeakPtr wraps a pointer to an object. If the object gets deleted, the WeakPtr becomes
    39     NULL. This can be used to store pointers to objects without knowing when they will be
     39    nullptr. This can be used to store pointers to objects without knowing when they will be
    4040    destroyed.
    4141
     
    5050    WeakPtr<MyClass> pointer = object;                  // create a WeakPtr and assign the object
    5151
    52     if (pointer)                                        // checks if pointer is not NULL (which is true)
     52    if (pointer)                                        // checks if pointer is not nullptr (which is true)
    5353        pointer->someFunction();                        // calls MyClass::someFunction()
    5454
    5555    object->destroy();                                  // calls destroy() which deletes the object
    5656
    57     if (pointer)                                        // checks if pointer is not NULL (which is now false)
     57    if (pointer)                                        // checks if pointer is not nullptr (which is now false)
    5858        pointer->someFunction();                        // this will not be executed
    5959    @endcode
     
    9191{
    9292    /**
    93         @brief WeakPtr wraps a pointer to an object, which becomes NULL if the object is deleted.
     93        @brief WeakPtr wraps a pointer to an object, which becomes nullptr if the object is deleted.
    9494
    9595        @see See @ref WeakPtrExample "this description" for more information and an example.
     
    100100        public:
    101101            /// Constructor: Initializes the weak pointer with a null pointer.
    102             inline WeakPtr() : pointer_(0), base_(0), callback_(0)
     102            inline WeakPtr() : pointer_(nullptr), base_(nullptr), callback_(nullptr)
    103103            {
    104104            }
    105105
    106106            /// Constructor: Initializes the weak pointer with a pointer to an object.
    107             inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0)
     107            inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(nullptr)
    108108            {
    109109                this->registerAsDestructionListener(this->base_);
     
    111111
    112112            /// Copy-constructor
    113             inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_), callback_(0)
     113            inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_), callback_(nullptr)
    114114            {
    115115                this->registerAsDestructionListener(this->base_);
     
    118118            /// Copy-constructor for weak pointers to objects of another class.
    119119            template <class O>
    120             inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.base_), callback_(0)
     120            inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.getBase()), callback_(nullptr)
    121121            {
    122122                this->registerAsDestructionListener(this->base_);
     
    124124
    125125            /// Destructor
    126             inline virtual ~WeakPtr()
     126            virtual inline ~WeakPtr()
    127127            {
    128128                this->unregisterAsDestructionListener(this->base_);
     
    137137
    138138            /// Assigns the wrapped pointer of another WeakPtr.
    139             inline WeakPtr& operator=(const WeakPtr& other)
    140             {
    141                 WeakPtr(other).swap(*this);
     139            inline WeakPtr& operator=(WeakPtr other)
     140            {
     141                other.swap(*this);
    142142                return *this;
    143143            }
     
    172172            inline T* operator->() const
    173173            {
    174                 assert(this->pointer_ != 0);
     174                assert(this->pointer_ != nullptr);
    175175                return this->pointer_;
    176176            }
     
    179179            inline T& operator*() const
    180180            {
    181                 assert(this->pointer_ != 0);
     181                assert(this->pointer_ != nullptr);
    182182                return *this->pointer_;
    183183            }
    184184
    185             /// Returns true if the wrapped pointer is NULL.
    186             inline bool operator!() const
    187             {
    188                 return (this->pointer_ == 0);
     185            /// Returns true if the pointer is not nullptr.
     186            inline explicit operator bool() const
     187            {
     188                return (this->pointer_ != nullptr);
    189189            }
    190190
     
    210210            }
    211211
    212             /// Resets the weak pointer (equivalent to assigning a NULL pointer).
     212            /// Resets the weak pointer (equivalent to assigning a nullptr).
    213213            inline void reset()
    214214            {
     
    230230        private:
    231231            /// Will be called by Destroyable::~Destroyable() if the stored object is deleted. Resets the wrapped pointer and executes the callback.
    232             inline void objectDeleted()
    233             {
    234                 this->base_ = 0;
    235                 this->pointer_ = 0;
     232            virtual inline void objectDeleted() override
     233            {
     234                this->base_ = nullptr;
     235                this->pointer_ = nullptr;
    236236                if (this->callback_)
    237237                    (*this->callback_)();
Note: See TracChangeset for help on using the changeset viewer.