OpenThread  1.05.03.02
Public Member Functions | Private Member Functions
OwnedPtr< Type > Class Template Reference

#include <owned_ptr.hpp>

+ Inheritance diagram for OwnedPtr< Type >:
+ Collaboration diagram for OwnedPtr< Type >:

Public Member Functions

void Free (void)
 
OwnedPtroperator= (OwnedPtr &&aOther)
 
OwnedPtroperator= (const OwnedPtr &)=delete
 
 OwnedPtr (void)=default
 
 OwnedPtr (Type *aPointer)
 
 OwnedPtr (OwnedPtr &&aOther)
 
 OwnedPtr (const OwnedPtr &)=delete
 
 OwnedPtr (OwnedPtr &)=delete
 
OwnedPtr && PassOwnership (void)
 
Type * Release (void)
 
void Reset (Type *aPointer=nullptr)
 
 ~OwnedPtr (void)
 
- Public Member Functions inherited from Ptr< Type >
Type * Get (void)
 
const Type * Get (void) const
 
bool IsNull (void) const
 
bool operator!= (const Type *aPointer) const
 
bool operator!= (const Ptr &aOther) const
 
Type & operator* (void)
 
const Type & operator* (void) const
 
Type * operator-> (void)
 
const Type * operator-> (void) const
 
bool operator== (const Type *aPointer) const
 
bool operator== (const Ptr &aOther) const
 
 Ptr (void)
 
 Ptr (Type *aPointer)
 

Private Member Functions

void Delete (void)
 

Additional Inherited Members

- Protected Attributes inherited from Ptr< Type >
Type * mPointer
 

Detailed Description

template<class Type>
class ot::OwnedPtr< Type >

This template class represents an owned smart pointer.

OwnedPtr acts as sole owner of the object it manages. An OwnedPtr is non-copyable (copy constructor is deleted) but the ownership can be transferred from one OwnedPtr to another using move semantics.

The Type class MUST provide Free() method which frees the instance.

Template Parameters
TypeThe pointer type.

Constructor & Destructor Documentation

§ OwnedPtr() [1/5]

OwnedPtr ( void  )
default

This is the default constructor for OwnedPtr initializing it as null.

Referenced by OwnedPtr< Type >::operator=().

§ OwnedPtr() [2/5]

OwnedPtr ( Type *  aPointer)
inlineexplicit

This constructor initializes the OwnedPtr with a given pointer.

The OwnedPtr takes the ownership of the object at aPointer.

Parameters
[in]aPointerA pointer to object to initialize with.

§ OwnedPtr() [3/5]

OwnedPtr ( OwnedPtr< Type > &&  aOther)
inline

This constructor initializes the OwnedPtr from another OwnedPtr using move semantics.

The OwnedPtr takes over the ownership of the object from aOther. After this call, aOther will be null.

Parameters
[in]aOtherAn rvalue reference to another OwnedPtr.

References Ptr< Type >::mPointer.

§ ~OwnedPtr()

~OwnedPtr ( void  )
inline

This is the destructor for OwnedPtr.

Upon destruction, the OwnedPtr invokes Free() method on its managed object (if any).

References OwnedPtr< Type >::Delete().

§ OwnedPtr() [4/5]

OwnedPtr ( const OwnedPtr< Type > &  )
delete

§ OwnedPtr() [5/5]

OwnedPtr ( OwnedPtr< Type > &  )
delete

Member Function Documentation

§ Free()

void Free ( void  )
inline

This method frees the owned object (if any).

This method invokes Free() method on the Type object owned by OwnedPtr (if any). It will also set the OwnedPtr to null.

References OwnedPtr< Type >::Delete(), and Ptr< Type >::mPointer.

§ Reset()

void Reset ( Type *  aPointer = nullptr)
inline

This method frees the current object owned by OwnedPtr (if any) and replaces it with a new one.

The method will Free() the current object managed by OwnedPtr (if different from aPointer) before taking the ownership of the object at aPointer. The method correctly handles a self Reset() (i.e., aPointer being the same pointer as the one currently managed by OwnedPtr).

Parameters
[in]aPointerA pointer to the new object to replace with.

References OwnedPtr< Type >::Delete(), and Ptr< Type >::mPointer.

Referenced by OwnedPtr< Type >::operator=().

§ Release()

Type* Release ( void  )
inline

This method releases the ownership of the current object in OwnedPtr (if any).

After this call, the OwnedPtr will be null.

Returns
The pointer to the object owned by OwnedPtr or nullptr if OwnedPtr was null.

References Ptr< Type >::mPointer.

§ PassOwnership()

OwnedPtr&& PassOwnership ( void  )
inline

This method allows passing of the ownership to another OwnedPtr using move semantics.

Returns
An rvalue reference of the pointer to move from.

§ operator=() [1/2]

OwnedPtr& operator= ( OwnedPtr< Type > &&  aOther)
inline

This method overload the assignment operator = to replace the object owned by the OwnedPtr with another one using move semantics.

The OwnedPtr first frees its current owned object (if there is any and it is different from aOther) before taking over the ownership of the object from aOther. This method correctly handles a self assignment (i.e., assigning the pointer to itself).

Parameters
[in]aOtherAn rvalue reference to an OwnedPtr to move from.
Returns
A reference to this OwnedPtr.

References OwnedPtr< Type >::OwnedPtr(), and OwnedPtr< Type >::Reset().

§ operator=() [2/2]

OwnedPtr& operator= ( const OwnedPtr< Type > &  )
delete

§ Delete()

void Delete ( void  )
inlineprivate

The documentation for this class was generated from the following file:
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale