A Discrete-Event Network Simulator
API
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  ref-count-base.cc
 ns3::RefCountBase implementation.
 
file  ref-count-base.h
 ns3::RefCountBase declaration.
 
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...
 
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 >
Ptr< T > ns3::Create (void)
 Create class instances by constructors with varying numbers of arguments and return them by Ptr. More...
 
template<typename T , typename T1 >
Ptr< T > ns3::Create (T1 a1)
 
template<typename T , typename T1 , typename T2 >
Ptr< T > ns3::Create (T1 a1, T2 a2)
 
template<typename T , typename T1 , typename T2 , typename T3 >
Ptr< T > ns3::Create (T1 a1, T2 a2, T3 a3)
 
template<typename T , typename T1 , typename T2 , typename T3 , typename T4 >
Ptr< T > ns3::Create (T1 a1, T2 a2, T3 a3, T4 a4)
 
template<typename T , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
Ptr< T > ns3::Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
 
template<typename T , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 >
Ptr< T > ns3::Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
 
template<typename T , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 >
Ptr< T > ns3::Create (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
 
template<typename T >
std::ostream & ns3::operator<< (std::ostream &os, const Ptr< T > &p)
 Output streamer. More...
 
template<typename T1 , typename T2 >
bool ns3::operator== (Ptr< T1 > const &lhs, T2 const *rhs)
 Equality operator. More...
 
template<typename T1 , typename T2 >
bool ns3::operator== (T1 const *lhs, Ptr< T2 > &rhs)
 Equality operator. More...
 
template<typename T1 , typename T2 >
bool ns3::operator== (Ptr< T1 > const &lhs, Ptr< T2 > const &rhs)
 Equality operator. More...
 
template<typename T1 , typename T2 >
bool ns3::operator!= (Ptr< T1 > const &lhs, T2 const *rhs)
 Inequality operator. More...
 
template<typename T1 , typename T2 >
bool ns3::operator!= (T1 const *lhs, Ptr< T2 > &rhs)
 Inequality operator. More...
 
template<typename T1 , typename T2 >
bool ns3::operator!= (Ptr< T1 > const &lhs, Ptr< T2 > const &rhs)
 Inequality operator. More...
 
template<typename T >
bool ns3::operator< (const Ptr< T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers. More...
 
template<typename T >
bool ns3::operator<= (const Ptr< T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers. More...
 
template<typename T >
bool ns3::operator> (const Ptr< T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers. More...
 
template<typename T >
bool ns3::operator>= (const Ptr< T > &lhs, const Ptr< T > &rhs)
 Comparison operator applied to the underlying pointers. More...
 

Detailed Description

Heap memory management.

See ns3::Ptr for implementation details.

See main-ptr.cc for example usage.

Function Documentation

◆ Create() [1/8]

template<typename T >
Ptr< T > ns3::Create ( void  )

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

These methods work for any class T.

See also
CreateObject for methods to create derivatives of ns3::Object
Template Parameters
T[explicit] The type of class object to create.
Returns
A Ptr to the newly created T.

Definition at line 516 of file ptr.h.

Referenced by ns3::internal::MakeDoubleChecker(), ns3::internal::MakeIntegerChecker(), ns3::MakeSimpleAttributeChecker(), ns3::MakeTimeChecker(), and ns3::internal::MakeUintegerChecker().

+ Here is the caller graph for this function:

◆ Create() [2/8]

template<typename T , typename T1 >
Ptr< T > ns3::Create ( T1  a1)
Template Parameters
T[explicit] The type of class object to create.
T1[deduced] The type of the first constructor argument.
Parameters
[in]a1The first constructor argument.
Returns
A Ptr to the newly created T.

Definition at line 522 of file ptr.h.

◆ Create() [3/8]

template<typename T , typename T1 , typename T2 >
Ptr< T > ns3::Create ( T1  a1,
T2  a2 
)
Template Parameters
T[explicit] The type of class object to create.
T1[deduced] The type of the first constructor argument.
T2[deduced] The type of the second constructor argument.
Parameters
[in]a1The first constructor argument.
[in]a2The second constructor argument.
Returns
A Ptr to the newly created T.

Definition at line 528 of file ptr.h.

◆ Create() [4/8]

template<typename T , typename T1 , typename T2 , typename T3 >
Ptr< T > ns3::Create ( T1  a1,
T2  a2,
T3  a3 
)
Template Parameters
T[explicit] The type of class object to create.
T1[deduced] The type of the first constructor argument.
T2[deduced] The type of the second constructor argument.
T3[deduced] The type of the third constructor argument.
Parameters
[in]a1The first constructor argument.
[in]a2The second constructor argument.
[in]a3The third constructor argument.
Returns
A Ptr to the newly created T.

Definition at line 534 of file ptr.h.

◆ Create() [5/8]

template<typename T , typename T1 , typename T2 , typename T3 , typename T4 >
Ptr< T > ns3::Create ( T1  a1,
T2  a2,
T3  a3,
T4  a4 
)
Template Parameters
T[explicit] The type of class object to create.
T1[deduced] The type of the first constructor argument.
T2[deduced] The type of the second constructor argument.
T3[deduced] The type of the third constructor argument.
T4[deduced] The type of the fourth constructor argument.
Parameters
[in]a1The first constructor argument.
[in]a2The second constructor argument.
[in]a3The third constructor argument.
[in]a4The fourth constructor argument.
Returns
A Ptr to the newly created T.

Definition at line 540 of file ptr.h.

◆ Create() [6/8]

template<typename T , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 >
Ptr< T > ns3::Create ( T1  a1,
T2  a2,
T3  a3,
T4  a4,
T5  a5 
)
Template Parameters
T[explicit] The type of class object to create.
T1[deduced] The type of the first constructor argument.
T2[deduced] The type of the second constructor argument.
T3[deduced] The type of the third constructor argument.
T4[deduced] The type of the fourth constructor argument.
T5[deduced] The type of the fifth constructor argument.
Parameters
[in]a1The first constructor argument.
[in]a2The second constructor argument.
[in]a3The third constructor argument.
[in]a4The fourth constructor argument.
[in]a5The fifth constructor argument.
Returns
A Ptr to the newly created T.

Definition at line 546 of file ptr.h.

◆ Create() [7/8]

template<typename T , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 >
Ptr< T > ns3::Create ( T1  a1,
T2  a2,
T3  a3,
T4  a4,
T5  a5,
T6  a6 
)
Template Parameters
T[explicit] The type of class object to create.
T1[deduced] The type of the first constructor argument.
T2[deduced] The type of the second constructor argument.
T3[deduced] The type of the third constructor argument.
T4[deduced] The type of the fourth constructor argument.
T5[deduced] The type of the fifth constructor argument.
T6[deduced] The type of the sixth constructor argument.
Parameters
[in]a1The first constructor argument.
[in]a2The second constructor argument.
[in]a3The third constructor argument.
[in]a4The fourth constructor argument.
[in]a5The fifth constructor argument.
[in]a6The sixth constructor argument.
Returns
A Ptr to the newly created T.

Definition at line 552 of file ptr.h.

◆ Create() [8/8]

template<typename T , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 >
Ptr< T > ns3::Create ( T1  a1,
T2  a2,
T3  a3,
T4  a4,
T5  a5,
T6  a6,
T7  a7 
)
Template Parameters
T[explicit] The type of class object to create.
T1[deduced] The type of the first constructor argument.
T2[deduced] The type of the second constructor argument.
T3[deduced] The type of the third constructor argument.
T4[deduced] The type of the fourth constructor argument.
T5[deduced] The type of the fifth constructor argument.
T6[deduced] The type of the sixth constructor argument.
T7[deduced] The type of the seventh constructor argument.
Parameters
[in]a1The first constructor argument.
[in]a2The second constructor argument.
[in]a3The third constructor argument.
[in]a4The fourth constructor argument.
[in]a5The fifth constructor argument.
[in]a6The sixth constructor argument.
[in]a7The seventh constructor argument.
Returns
A Ptr to the newly created T.

Definition at line 558 of file ptr.h.

◆ operator!=() [1/3]

template<typename T1 , typename T2 >
bool ns3::operator!= ( Ptr< T1 > const &  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 599 of file ptr.h.

References ns3::PeekPointer().

+ Here is the call graph for this function:

◆ operator!=() [2/3]

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 606 of file ptr.h.

References ns3::PeekPointer().

+ Here is the call graph for this function:

◆ operator!=() [3/3]

template<typename T1 , typename T2 >
bool ns3::operator!= ( Ptr< T1 > const &  lhs,
Ptr< 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 620 of file ptr.h.

References ns3::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.

Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 626 of file ptr.h.

◆ operator<<()

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

Output streamer.

Parameters
[in,out]osThe output stream.
[in]pThe Ptr.
Returns
The stream.

Definition at line 577 of file ptr.h.

References ns3::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.

Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 632 of file ptr.h.

◆ operator==() [1/3]

template<typename T1 , typename T2 >
bool ns3::operator== ( Ptr< T1 > const &  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 585 of file ptr.h.

References ns3::PeekPointer().

+ Here is the call graph for this function:

◆ operator==() [2/3]

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 592 of file ptr.h.

References ns3::PeekPointer().

+ Here is the call graph for this function:

◆ operator==() [3/3]

template<typename T1 , typename T2 >
bool ns3::operator== ( Ptr< T1 > const &  lhs,
Ptr< 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 613 of file ptr.h.

References ns3::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.

Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 638 of file ptr.h.

◆ operator>=()

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

Comparison operator applied to the underlying pointers.

Parameters
[in]lhsThe left operand.
[in]rhsThe right operand.
Returns
The comparison on the underlying pointers.

Definition at line 644 of file ptr.h.