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/StrongPtr.h

    r10624 r11071  
    4343    orxonox::StrongPtr is an implementation of a smart pointer - it wraps a pointer to an
    4444    object  and keeps this object alive until no StrongPtr points to this object anymore.
    45     In contrast to orxonox::SharedPtr, StrongPtr works only with classes that are derived
     45    In contrast to std::shared_ptr, StrongPtr works only with classes that are derived
    4646    from orxonox::Destroyable, because it's an intrusive implementation, meaning the
    4747    reference counter is stored in the object itself.
     
    5151    at any time and also convert it back to a normal pointer if you like. This is possible
    5252    because the reference counter is stored in the object itself and not in StrongPtr (in
    53     contrast to SharedPtr).
     53    contrast to std::shared_ptr).
    5454
    5555    @b Important: If you want to delete an object, you must not use @c delete @c object but
     
    138138        public:
    139139            /// Constructor: Initializes the strong pointer with a null pointer.
    140             inline StrongPtr() : pointer_(0), base_(0)
     140            inline StrongPtr() : pointer_(nullptr), base_(nullptr)
    141141            {
    142142            }
     
    158158            /// Copy-constructor for strong pointers to objects of another class.
    159159            template <class O>
    160             inline StrongPtr(const StrongPtr<O>& other) : pointer_(other.get()), base_(other.base_)
     160            inline StrongPtr(const StrongPtr<O>& other) : pointer_(other.get()), base_(other.getBase())
    161161            {
    162162                if (this->base_)
     
    172172            }
    173173
     174            /// Move-constructor
     175            inline StrongPtr(StrongPtr&& other) : pointer_(other.pointer_), base_(other.base_)
     176            {
     177                other.pointer_ = nullptr;
     178                other.base_ = nullptr;
     179            }
     180
    174181            /// Destructor: Decrements the reference counter.
    175182            inline ~StrongPtr()
     
    187194
    188195            /// Assigns the wrapped pointer of another StrongPtr.
    189             inline StrongPtr& operator=(const StrongPtr& other)
    190             {
    191                 StrongPtr(other).swap(*this);
     196            inline StrongPtr& operator=(StrongPtr other)
     197            {
     198                other.swap(*this);
    192199                return *this;
    193200            }
     
    230237            inline T* operator->() const
    231238            {
    232                 assert(this->pointer_ != 0);
     239                assert(this->pointer_ != nullptr);
    233240                return this->pointer_;
    234241            }
     
    237244            inline T& operator*() const
    238245            {
    239                 assert(this->pointer_ != 0);
     246                assert(this->pointer_ != nullptr);
    240247                return *this->pointer_;
    241248            }
    242249
    243             /// Returns true if the wrapped pointer is NULL.
    244             inline bool operator!() const
    245             {
    246                 return (this->pointer_ == 0);
     250            /// Returns true if the pointer is not nullptr.
     251            inline explicit operator bool() const
     252            {
     253                return (this->pointer_ != nullptr);
    247254            }
    248255
     
    262269            }
    263270
    264             /// Resets the strong pointer (equivalent to assigning a NULL pointer).
     271            /// Resets the strong pointer (equivalent to assigning a nullptr).
    265272            inline void reset()
    266273            {
Note: See TracChangeset for help on using the changeset viewer.