ns3::Object Class Reference
[Object]

a base class which provides memory management and object aggregation More...

#include <object.h>

Inheritance diagram for ns3::Object:
Inheritance graph
[legend]
Collaboration diagram for ns3::Object:
Collaboration graph
[legend]

List of all members.

Classes

class  AggregateIterator
 Iterate over the objects aggregated to an ns3::Object. More...

Public Member Functions

 Object ()
virtual ~Object ()
virtual TypeId GetInstanceTypeId (void) const
void Ref (void) const
void Unref (void) const
uint32_t GetReferenceCount (void) const
template<typename T >
Ptr< T > GetObject (void) const
template<typename T >
Ptr< T > GetObject (TypeId tid) const
void Dispose (void)
void AggregateObject (Ptr< Object > other)
AggregateIterator GetAggregateIterator (void) const

Static Public Member Functions

static TypeId GetTypeId (void)
 This method returns the TypeId associated to ns3::Object.

Protected Member Functions

virtual void DoDispose (void)
 Object (const Object &o)

Private Member Functions

Ptr< ObjectDoGetObject (TypeId tid) const
bool Check (void) const
bool CheckLoose (void) const
void MaybeDelete (void) const
void SetTypeId (TypeId tid)
void Construct (const AttributeList &attributes)

Private Attributes

uint32_t m_count
TypeId m_tid
bool m_disposed
Objectm_next

Friends

class ObjectFactory
class AggregateIterator
template<typename T >
Ptr< T > CreateObject (const AttributeList &attributes)
template<typename T >
Ptr< T > CopyObject (Ptr< T > object)
template<typename T >
Ptr< T > CopyObject (Ptr< const T > object)
void PythonCompleteConstruct (Ptr< Object > object, TypeId typeId, const AttributeList &attributes)

Detailed Description

a base class which provides memory management and object aggregation

The memory management scheme is based on reference-counting with dispose-like functionality to break the reference cycles. The reference count is increamented and decremented with the methods Object::Ref and Object::Unref. If a reference cycle is present, the user is responsible for breaking it by calling Object::Dispose in a single location. This will eventually trigger the invocation of Object::DoDispose on itself and all its aggregates. The Object::DoDispose method is always automatically invoked from the Object::Unref method before destroying the object, even if the user did not call Object::Dispose directly.

Definition at line 58 of file object.h.


Constructor & Destructor Documentation

ns3::Object::Object (  ) 

Definition at line 82 of file object.cc.

ns3::Object::~Object (  )  [virtual]

Definition at line 88 of file object.cc.

References m_next.

ns3::Object::Object ( const Object o  )  [protected]
Parameters:
o the object to copy.

Allow subclasses to implement a copy constructor. While it is technically possible to implement a copy constructor in a subclass, we strongly discourage you to do so. If you really want to do it anyway, you have to understand that this copy constructor will _not_ copy aggregated objects. i.e., if your object instance is already aggregated to another object and if you invoke this copy constructor, the new object instance will be a pristine standlone object instance not aggregated to any other object. It is thus _your_ responsability as a caller of this method to do what needs to be done (if it is needed) to ensure that the object stays in a valid state.

Definition at line 92 of file object.cc.


Member Function Documentation

void ns3::Object::AggregateObject ( Ptr< Object other  ) 
Parameters:
other another object pointer

This method aggregates the two objects together: after this method returns, it becomes possible to call GetObject on one to get the other, and vice-versa.

Definition at line 143 of file object.cc.

References CheckLoose(), DoGetObject(), m_disposed, m_next, NS_ASSERT, NS_FATAL_ERROR, and ns3::PeekPointer().

bool ns3::Object::Check ( void   )  const [private]

Definition at line 186 of file object.cc.

References m_count.

Referenced by SetTypeId(), and Unref().

bool ns3::Object::CheckLoose ( void   )  const [private]

Definition at line 199 of file object.cc.

References m_count, and m_next.

Referenced by AggregateObject(), and DoGetObject().

void ns3::Object::Construct ( const AttributeList attributes  )  [private]
Parameters:
attributes the attribute values used to initialize the member variables of this object's instance.

Invoked from ns3::ObjectFactory::Create and ns3::CreateObject only. Initialize all the member variables which were registered with the associated TypeId.

Definition at line 104 of file object.cc.

References ns3::ObjectBase::ConstructSelf().

Referenced by ns3::ObjectFactory::Create().

void ns3::Object::Dispose ( void   ) 

Run the DoDispose methods of this object and all the objects aggregated to it. After calling this method, the object is expected to be totally unusable except for the Ref and Unref methods. It is an error to call Dispose twice on the same object instance.

This method is typically used to break reference cycles.

Reimplemented in anonymous_namespace{object.cc}::BaseA, anonymous_namespace{object.cc}::DerivedA, anonymous_namespace{object.cc}::BaseB, and anonymous_namespace{object.cc}::DerivedB.

Definition at line 131 of file object.cc.

References DoDispose(), m_disposed, m_next, and NS_ASSERT.

void ns3::Object::DoDispose ( void   )  [protected, virtual]

This method is called by Object::Dispose or by the object's destructor, whichever comes first.

Subclasses are expected to implement their real destruction code in an overriden version of this method and chain up to their parent's implementation once they are done. i.e., for simplicity, the destructor of every subclass should be empty and its content should be moved to the associated DoDispose method.

Reimplemented in ns3::OnOffApplication, ns3::PacketSink, ns3::UdpEchoClient, ns3::UdpEchoServer, ns3::V4Ping, ns3::MinMaxAvgTotalCalculator< T >, ns3::CounterCalculator< T >, ns3::DataCalculator, ns3::DataCollector, ns3::DataOutputInterface, ns3::OmnetDataOutput, ns3::PacketCounterCalculator, ns3::PacketSizeMinMaxAvgTotalCalculator, ns3::SqliteDataOutput, ns3::TimeMinMaxAvgTotalCalculator, ns3::BridgeNetDevice, ns3::CsmaNetDevice, ns3::EmuNetDevice, ns3::PointToPointNetDevice, ns3::AdhocWifiMac, ns3::DcaTxop, ns3::MacLow, ns3::NqapWifiMac, ns3::NqstaWifiMac, ns3::Ns2ExtWifiPhy, ns3::WifiNetDevice, ns3::WifiRemoteStationManager, ns3::YansWifiPhy, ns3::ArpCache, ns3::ArpIpv4Interface, ns3::ArpL3Protocol, ns3::Icmpv4L4Protocol, ns3::Ipv4GlobalRouting, ns3::Ipv4Impl, ns3::Ipv4Interface, ns3::Ipv4L3Protocol, ns3::Ipv4RawSocketImpl, ns3::Ipv4StaticRouting, ns3::NscTcpL4Protocol, ns3::NscTcpSocketFactoryImpl, ns3::TcpL4Protocol, ns3::TcpSocketFactoryImpl, ns3::UdpL4Protocol, ns3::UdpSocketFactoryImpl, ns3::RandomDirection2dMobilityModel, ns3::RandomWalk2dMobilityModel, ns3::Application, ns3::Node, ns3::PacketSocket, ns3::SimpleNetDevice, ns3::GlobalRouter, ns3::olsr::AgentImpl, ns3::olsr::RoutingTable, ns3::MinMaxAvgTotalCalculator< uint32_t >, and ns3::CounterCalculator< uint32_t >.

Definition at line 179 of file object.cc.

References m_disposed, and NS_ASSERT.

Referenced by Dispose(), and MaybeDelete().

Ptr< Object > ns3::Object::DoGetObject ( TypeId  tid  )  const [private]
Object::AggregateIterator ns3::Object::GetAggregateIterator ( void   )  const
Returns:
an iterator to the first object aggregated to this object.

If no objects are aggregated to this object, then, the returned iterator will be empty and AggregateIterator::HasNext will always return false.

Definition at line 166 of file object.cc.

References AggregateIterator.

TypeId ns3::Object::GetInstanceTypeId ( void   )  const [virtual]
Returns:
the TypeId associated to the most-derived type of this instance.

This method is typically implemented by ns3::Object::GetInstanceTypeId but some classes which derive from ns3::ObjectBase directly have to implement it themselves.

Implements ns3::ObjectBase.

Reimplemented in ns3::Ns3NscStack.

Definition at line 67 of file object.cc.

References m_tid.

Referenced by DoGetObject().

template<typename T >
Ptr< T > ns3::Object::GetObject ( TypeId  tid  )  const [inline]
Parameters:
tid the interface id of the requested interface
Returns:
a pointer to the requested interface or zero if it could not be found.

Definition at line 364 of file object.h.

References DoGetObject(), and ns3::PeekPointer().

template<typename T >
Ptr< T > ns3::Object::GetObject ( void   )  const [inline]
Returns:
a pointer to the requested interface or zero if it could not be found.

Definition at line 352 of file object.h.

References DoGetObject(), and ns3::PeekPointer().

uint32_t ns3::Object::GetReferenceCount ( void   )  const

Get the reference count of the object. Normally not needed; for language bindings.

Definition at line 99 of file object.cc.

References m_count.

TypeId ns3::Object::GetTypeId ( void   )  [static]

This method returns the TypeId associated to ns3::Object.

No Attributes defined for this type.
No TraceSources defined for this type.

Reimplemented from ns3::ObjectBase.

Reimplemented in ns3::OnOffApplication, ns3::PacketSink, ns3::UdpEchoClient, ns3::UdpEchoServer, ns3::V4Ping, ns3::ErrorModel, ns3::RateErrorModel, ns3::ListErrorModel, ns3::Derived, ns3::AttributeObjectTest, ns3::MyNode, anonymous_namespace{object.cc}::BaseA, anonymous_namespace{object.cc}::DerivedA, anonymous_namespace{object.cc}::BaseB, anonymous_namespace{object.cc}::DerivedB, ns3::BridgeChannel, ns3::BridgeNetDevice, ns3::CsmaChannel, ns3::CsmaNetDevice, ns3::EmuNetDevice, ns3::PointToPointChannel, ns3::PointToPointNetDevice, ns3::AarfWifiManager, ns3::AdhocWifiMac, ns3::AmrrWifiManager, ns3::ArfWifiManager, ns3::ConstantRateWifiManager, ns3::DcaTxop, ns3::ErrorRateModel, ns3::IdealWifiManager, ns3::JakesPropagationLossModel, ns3::NqapWifiMac, ns3::NqstaWifiMac, ns3::Ns2ExtWifiChannel, ns3::Ns2ExtWifiPhyStateHelper, ns3::Ns2ExtWifiPhy, ns3::OnoeWifiManager, ns3::PropagationDelayModel, ns3::RandomPropagationDelayModel, ns3::ConstantSpeedPropagationDelayModel, ns3::PropagationLossModel, ns3::RandomPropagationLossModel, ns3::FriisPropagationLossModel, ns3::LogDistancePropagationLossModel, ns3::ThreeLogDistancePropagationLossModel, ns3::NakagamiPropagationLossModel, ns3::RraaWifiManager, ns3::WifiChannel, ns3::WifiMacQueue, ns3::WifiMac, ns3::WifiNetDevice, ns3::WifiPhy, ns3::WifiRemoteStationManager, ns3::YansErrorRateModel, ns3::YansWifiChannel, ns3::YansWifiPhyStateHelper, ns3::YansWifiPhy, ns3::ArpCache, ns3::ArpIpv4Interface, ns3::ArpL3Protocol, ns3::Icmpv4L4Protocol, ns3::Ipv4GlobalRouting, ns3::Ipv4Interface, ns3::Ipv4L3Protocol, ns3::Ipv4L4Protocol, ns3::Ipv4LoopbackInterface, ns3::Ipv4RawSocketImpl, ns3::Ns3NscStack, ns3::NscTcpL4Protocol, ns3::NscTcpSocketImpl, ns3::RttEstimator, ns3::RttMeanDeviation, ns3::TcpL4Protocol, ns3::TcpSocketImpl, ns3::UdpL4Protocol, ns3::UdpSocketImpl, ns3::HierarchicalMobilityModel, ns3::MobilityModel, ns3::PositionAllocator, ns3::ListPositionAllocator, ns3::GridPositionAllocator, ns3::RandomRectanglePositionAllocator, ns3::RandomDiscPositionAllocator, ns3::RandomDirection2dMobilityModel, ns3::RandomWalk2dMobilityModel, ns3::RandomWaypointMobilityModel, ns3::StaticMobilityModel, ns3::StaticSpeedMobilityModel, ns3::Application, ns3::Channel, ns3::DropTailQueue, ns3::Ipv4RawSocketFactory, ns3::Ipv4, ns3::NetDevice, ns3::NodeListPriv, ns3::Node, ns3::PacketSocketFactory, ns3::PacketSocket, ns3::Queue, ns3::SimpleChannel, ns3::SimpleNetDevice, ns3::SocketFactory, ns3::TcpSocketFactory, ns3::TcpSocket, ns3::UdpSocketFactory, ns3::UdpSocket, ns3::GlobalRouter, ns3::olsr::AgentImpl, ns3::olsr::Agent, ns3::CalendarScheduler, ns3::DefaultSimulatorImpl, ns3::HeapScheduler, ns3::ListScheduler, ns3::MapScheduler, ns3::RealtimeSimulatorImpl, ns3::Scheduler, and ns3::Synchronizer.

Definition at line 73 of file object.cc.

References ns3::TypeId::SetParent().

Referenced by DoGetObject().

void ns3::Object::MaybeDelete ( void   )  const [private]

Attempt to delete this object. This method iterates over all aggregated objects to check if they all have a zero refcount. If yes, the object and all its aggregates are deleted. If not, nothing is done.

Definition at line 214 of file object.cc.

References DoDispose(), m_count, m_disposed, m_next, and NS_ASSERT.

Referenced by Unref().

void ns3::Object::Ref ( void   )  const [inline]

Increment the reference count. This method should not be called by user code. Object instances are expected to be used in conjunction of the Ptr template which would make calling Ref unecessary and dangerous.

Definition at line 335 of file object.h.

References m_count.

void ns3::Object::SetTypeId ( TypeId  tid  )  [private]
Parameters:
tid an TypeId

Invoked from ns3::CreateObject only. Initialize the m_tid member variable to keep track of the type of this object instance.

Definition at line 172 of file object.cc.

References Check(), m_tid, and NS_ASSERT.

Referenced by ns3::ObjectFactory::Create().

void ns3::Object::Unref ( void   )  const [inline]

Decrement the reference count. This method should not be called by user code. Object instances are expected to be used in conjunction of the Ptr template which would make calling Ref unecessary and dangerous.

Definition at line 340 of file object.h.

References Check(), m_count, MaybeDelete(), and NS_ASSERT.


Friends And Related Function Documentation

friend class AggregateIterator [friend]

Definition at line 207 of file object.h.

Referenced by GetAggregateIterator().

template<typename T >
Ptr<T> CopyObject ( Ptr< const T >  object  )  [friend]
Parameters:
object a pointer to the object to copy.
Returns:
a copy of the input object.

This method invoke the copy constructor of the input object and returns the new instance.

Definition at line 387 of file object.h.

template<typename T >
Ptr<T> CopyObject ( Ptr< T >  object  )  [friend]
Parameters:
object a pointer to the object to copy.
Returns:
a copy of the input object.

This method invoke the copy constructor of the input object and returns the new instance.

Definition at line 387 of file object.h.

template<typename T >
Ptr<T> CreateObject ( const AttributeList attributes  )  [friend]
Parameters:
attributes a list of attributes to set on the object during construction.
Returns:
a pointer to a newly allocated object.

This allocates an object on the heap and initializes it with a set of attributes.

Definition at line 396 of file object.h.

friend class ObjectFactory [friend]

Definition at line 206 of file object.h.

void PythonCompleteConstruct ( Ptr< Object object,
TypeId  typeId,
const AttributeList attributes 
) [friend]

Member Data Documentation

uint32_t ns3::Object::m_count [mutable, private]

The reference count for this object. Each aggregate has an individual reference count. When the global reference count (the sum of all reference counts) reaches zero, the object and all its aggregates is deleted.

Reimplemented in ns3::UdpEchoClient, ns3::MinMaxAvgTotalCalculator< T >, ns3::CounterCalculator< T >, ns3::TimeMinMaxAvgTotalCalculator, ns3::MinMaxAvgTotalCalculator< uint32_t >, and ns3::CounterCalculator< uint32_t >.

Definition at line 244 of file object.h.

Referenced by Check(), CheckLoose(), GetReferenceCount(), MaybeDelete(), Ref(), and Unref().

bool ns3::Object::m_disposed [private]

Set to true when the DoDispose method of the object has run, false otherwise.

Definition at line 253 of file object.h.

Referenced by AggregateObject(), Dispose(), DoDispose(), and MaybeDelete().

A pointer to the next aggregate object. This is a circular linked list of aggregated objects: the last one points back to the first one. If an object is not aggregated to any other object, the value of this field is equal to the value of the 'this' pointer.

Reimplemented in ns3::PropagationLossModel.

Definition at line 261 of file object.h.

Referenced by AggregateObject(), CheckLoose(), Dispose(), DoGetObject(), MaybeDelete(), and ~Object().

Identifies the type of this object instance.

Reimplemented in ns3::OnOffApplication, and ns3::PacketSink.

Definition at line 248 of file object.h.

Referenced by GetInstanceTypeId(), and SetTypeId().


The documentation for this class was generated from the following files:
Generated on Thu Dec 3 14:10:24 2009 for NS-3 by  doxygen 1.6.3