A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
Smart Pointer

Heap memory management. More...

Collaboration diagram for Smart Pointer:

Files

file  default-deleter.h
 ns3::DefaultDeleter declaration and template implementation, for reference-counted smart pointers.
file  ptr-test-suite.cc
 Smart pointer test suite.
file  ptr.h
 ns3::Ptr smart pointer declaration and implementation.
file  simple-ref-count.h
 ns3::SimpleRefCount declaration and template implementation.

Classes

struct  ns3::DefaultDeleter< T >
 A template used to delete objects by the ns3::SimpleRefCount templates when the last reference to an object they manage disappears. More...
class  ns3::Empty
 Empty class, used as a default parent class for SimpleRefCount. More...
struct  std::hash< ns3::Ptr< T > >
 Hashing functor taking a Ptr and returning a std::size_t. More...
struct  ns3::ObjectDeleter
 Standard Object deleter, used by SimpleRefCount to delete an Object when the reference count drops to zero. More...
class  ns3::Ptr< T >
 Smart pointer class similar to boost::intrusive_ptr. More...
class  ns3::SimpleRefCount< T, PARENT, DELETER >
 A template-based reference counting class. More...

Functions

template<typename T, typename... Ts>
Ptr< T > ns3::Create (Ts &&... args)
 Create class instances by constructors with varying numbers of arguments and return them by Ptr.
template<typename T1, typename T2>
std::enable_if_t< std::is_same_v< T2, std::nullptr_t >, bool > ns3::operator!= (const Ptr< T1 > &lhs, T2 rhs)
 Specialization for comparison to nullptr.
template<typename T>
std::ostream & ns3::operator<< (std::ostream &os, const Ptr< T > &p)
 Output streamer.
template<typename T1, typename T2>
std::enable_if_t< std::is_same_v< T2, std::nullptr_t >, bool > ns3::operator== (const Ptr< T1 > &lhs, T2 rhs)
 Specialization for comparison to nullptr.
template<typename T1, typename T2>
bool ns3::operator== (const Ptr< T1 > &lhs, T2 const *rhs)
 Equality operator.
template<typename T1, typename T2>
bool ns3::operator== (T1 const *lhs, Ptr< T2 > &rhs)
 Equality operator.
template<typename T1, typename T2>
bool ns3::operator== (const Ptr< T1 > &lhs, const Ptr< T2 > &rhs)
 Equality operator.
template<typename T1, typename T2>
bool ns3::operator!= (const Ptr< T1 > &lhs, T2 const *rhs)
 Inequality operator.
template<typename T1, typename T2>
bool ns3::operator!= (T1 const *lhs, Ptr< T2 > &rhs)
 Inequality operator.
template<typename T1, typename T2>
bool ns3::operator!= (const Ptr< T1 > &lhs, const Ptr< T2 > &rhs)
 Inequality operator.
template<typename T>
bool ns3::operator< (const Ptr< T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers.
template<typename T>
bool ns3::operator< (const Ptr< T > &lhs, const Ptr< const T > &rhs)
 Comparison operator applied to the underlying pointers.
template<typename T>
bool ns3::operator< (const Ptr< const T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers.
template<typename T>
bool ns3::operator<= (const Ptr< T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers.
template<typename T>
bool ns3::operator> (const Ptr< T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers.
template<typename T>
bool ns3::operator>= (const Ptr< T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers.

Detailed Description

Heap memory management.

See ns3::Ptr for implementation details.

See main-ptr.cc for example usage.

Function Documentation

◆ Create()

template<typename T, typename... Ts>
Ptr< T > ns3::Create ( Ts &&... args)

Create class instances by constructors with varying numbers of arguments and return them by Ptr.

This template work for any class T derived from ns3::SimpleRefCount

See also
CreateObject for methods to create derivatives of ns3::Object
Template Parameters
T[explicit] The type of class object to create.
Ts[deduced] Types of the constructor arguments.
Parameters
[in]argsConstructor arguments.
Returns
A Ptr to the newly created T. Caller graph was not generated because of its size.

Definition at line 454 of file ptr.h.

◆ operator!=() [1/4]

template<typename T1, typename T2>
bool ns3::operator!= ( const Ptr< T1 > & lhs,
const Ptr< T2 > & rhs )

Inequality operator.

This enables code such as

Ptr<...> p = ...;
Ptr<...> q = ...;
if (p != q) ...
uint32_t q
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70

Note that either p or q could also be ordinary pointers to the underlying object.

Template Parameters
T1[deduced] Type of the object on the lhs.
T2[deduced] Type of the object on the rhs.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
true if the operands point to the same underlying object.

Definition at line 521 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator!=() [2/4]

template<typename T1, typename T2>
bool ns3::operator!= ( const Ptr< T1 > & lhs,
T2 const * rhs )

Inequality operator.

This enables code such as

Ptr<...> p = ...;
Ptr<...> q = ...;
if (p != q) ...

Note that either p or q could also be ordinary pointers to the underlying object.

Template Parameters
T1[deduced] Type of the object on the lhs.
T2[deduced] Type of the object on the rhs.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
true if the operands point to the same underlying object.

Definition at line 500 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator!=() [3/4]

template<typename T1, typename T2>
std::enable_if_t< std::is_same_v< T2, std::nullptr_t >, bool > ns3::operator!= ( const Ptr< T1 > & lhs,
T2 rhs )

Specialization for comparison to nullptr.

Equality operator.

This enables code such as

Ptr<...> p = ...;
Ptr<...> q = ...;
if (p == q) ...

Note that either p or q could also be ordinary pointers to the underlying object.

Template Parameters
T1[deduced] Type of the object on the lhs.
T2[deduced] Type of the object on the rhs.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
true if the operands point to the same underlying object.

Definition at line 535 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator!=() [4/4]

template<typename T1, typename T2>
bool ns3::operator!= ( T1 const * lhs,
Ptr< T2 > & rhs )

Inequality operator.

This enables code such as

Ptr<...> p = ...;
Ptr<...> q = ...;
if (p != q) ...

Note that either p or q could also be ordinary pointers to the underlying object.

Template Parameters
T1[deduced] Type of the object on the lhs.
T2[deduced] Type of the object on the rhs.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
true if the operands point to the same underlying object.

Definition at line 507 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator<() [1/3]

template<typename T>
bool ns3::operator< ( const Ptr< const T > & lhs,
const Ptr< T > & rhs )

Comparison operator applied to the underlying pointers.

Template Parameters
T[deduced] The type of the operands.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 555 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator<() [2/3]

template<typename T>
bool ns3::operator< ( const Ptr< T > & lhs,
const Ptr< const T > & rhs )

Comparison operator applied to the underlying pointers.

Template Parameters
T[deduced] The type of the operands.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 548 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator<() [3/3]

template<typename T>
bool ns3::operator< ( const Ptr< T > & lhs,
const Ptr< T > & rhs )

Comparison operator applied to the underlying pointers.

Template Parameters
T[deduced] The type of the operands.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 541 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator<<()

template<typename T>
std::ostream & ns3::operator<< ( std::ostream & os,
const Ptr< T > & p )

Output streamer.

Template Parameters
T[deduced] The type of the underlying Object.
Parameters
[in,out]osThe output stream.
[in]pThe Ptr.
Returns
The stream.

Definition at line 477 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator<=()

template<typename T>
bool ns3::operator<= ( const Ptr< T > & lhs,
const Ptr< T > & rhs )

Comparison operator applied to the underlying pointers.

Template Parameters
T[deduced] The type of the operands.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 562 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator==() [1/4]

template<typename T1, typename T2>
bool ns3::operator== ( const Ptr< T1 > & lhs,
const Ptr< T2 > & rhs )

Equality operator.

This enables code such as

Ptr<...> p = ...;
Ptr<...> q = ...;
if (p == q) ...

Note that either p or q could also be ordinary pointers to the underlying object.

Template Parameters
T1[deduced] Type of the object on the lhs.
T2[deduced] Type of the object on the rhs.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
true if the operands point to the same underlying object.

Definition at line 514 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator==() [2/4]

template<typename T1, typename T2>
bool ns3::operator== ( const Ptr< T1 > & lhs,
T2 const * rhs )

Equality operator.

This enables code such as

Ptr<...> p = ...;
Ptr<...> q = ...;
if (p == q) ...

Note that either p or q could also be ordinary pointers to the underlying object.

Template Parameters
T1[deduced] Type of the object on the lhs.
T2[deduced] Type of the object on the rhs.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
true if the operands point to the same underlying object.

Definition at line 486 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator==() [3/4]

template<typename T1, typename T2>
std::enable_if_t< std::is_same_v< T2, std::nullptr_t >, bool > ns3::operator== ( const Ptr< T1 > & lhs,
T2 rhs )

Specialization for comparison to nullptr.

Equality operator.

This enables code such as

Ptr<...> p = ...;
Ptr<...> q = ...;
if (p == q) ...

Note that either p or q could also be ordinary pointers to the underlying object.

Template Parameters
T1[deduced] Type of the object on the lhs.
T2[deduced] Type of the object on the rhs.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
true if the operands point to the same underlying object.

Definition at line 528 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator==() [4/4]

template<typename T1, typename T2>
bool ns3::operator== ( T1 const * lhs,
Ptr< T2 > & rhs )

Equality operator.

This enables code such as

Ptr<...> p = ...;
Ptr<...> q = ...;
if (p == q) ...

Note that either p or q could also be ordinary pointers to the underlying object.

Template Parameters
T1[deduced] Type of the object on the lhs.
T2[deduced] Type of the object on the rhs.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
true if the operands point to the same underlying object.

Definition at line 493 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator>()

template<typename T>
bool ns3::operator> ( const Ptr< T > & lhs,
const Ptr< T > & rhs )

Comparison operator applied to the underlying pointers.

Template Parameters
T[deduced] The type of the operands.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 570 of file ptr.h.

References PeekPointer().

Here is the call graph for this function:

◆ operator>=()

template<typename T>
bool ns3::operator>= ( const Ptr< T > & lhs,
const Ptr< T > & rhs )

Comparison operator applied to the underlying pointers.

Template Parameters
T[deduced] The type of the operands.
Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 577 of file ptr.h.

References PeekPointer().

Here is the call graph for this function: