Instantiate subclasses of ns3::Object. More...
#include "object-factory.h"
Public Member Functions | |
ObjectFactory () | |
Default constructor. | |
template<typename... Args> | |
ObjectFactory (const std::string &typeId, Args &&... args) | |
Construct a factory for a specific TypeId by name. | |
Ptr< Object > | Create () const |
Create an Object instance of the configured TypeId. | |
template<typename T> | |
Ptr< T > | Create () const |
Create an Object instance of the requested type. | |
TypeId | GetTypeId () const |
Get the TypeId which will be created by this ObjectFactory. | |
bool | IsTypeIdSet () const |
Check if the ObjectFactory has been configured with a TypeId. | |
void | Set () |
Base case to stop the recursion performed by the templated version of this method. | |
template<typename... Args> | |
void | Set (const std::string &name, const AttributeValue &value, Args &&... args) |
Set an attribute to be set during construction. | |
void | SetTypeId (TypeId tid) |
Set the TypeId of the Objects to be created by this factory. | |
void | SetTypeId (std::string tid) |
Set the TypeId of the Objects to be created by this factory. | |
Private Member Functions | |
void | DoSet (const std::string &name, const AttributeValue &value) |
Set an attribute to be set during construction. | |
Private Attributes | |
AttributeConstructionList | m_parameters |
The list of attributes and values to be used in constructing objects by this factory. | |
TypeId | m_tid |
The TypeId this factory will create. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const ObjectFactory &factory) |
Print the factory configuration on an output stream. | |
std::istream & | operator>> (std::istream &is, ObjectFactory &factory) |
Read a factory configuration from an input stream. | |
Instantiate subclasses of ns3::Object.
This class can also hold a set of attributes to set automatically during the object construction.
Definition at line 36 of file object-factory.h.
ns3::ObjectFactory::ObjectFactory | ( | ) |
Default constructor.
This factory is not capable of constructing a real Object until it has at least a TypeId.
Definition at line 25 of file object-factory.cc.
References NS_LOG_FUNCTION.
Referenced by operator<<, and operator>>.
ns3::ObjectFactory::ObjectFactory | ( | const std::string & | typeId, |
Args &&... | args ) |
Construct a factory for a specific TypeId by name.
Args | [deduced] Template type parameter pack for the sequence of name-value pairs |
[in] | typeId | The name of the TypeId this factory should create. |
[in] | args | A sequence of name-value pairs of additional attributes to set. |
The args sequence can be made of any number of pairs, each consisting of a name (of std::string type) followed by a value (of const AttributeValue & type).
Definition at line 205 of file object-factory.h.
References Set(), and SetTypeId().
Create an Object instance of the configured TypeId.
Definition at line 82 of file object-factory.cc.
References m_parameters, m_tid, NS_ASSERT, NS_ASSERT_MSG, and NS_LOG_FUNCTION.
Referenced by ns3::SpectrumChannelHelper::AddPropagationLoss(), ns3::SpectrumChannelHelper::AddSpectrumPropagationLoss(), ns3::LteUeRrc::ApplyRadioResourceConfigDedicated(), BuildSimpleTopology(), ns3::PfifoFastQueueDisc::CheckConfig(), ns3::PrioQueueDisc::CheckConfig(), ns3::TbfQueueDisc::CheckConfig(), Create(), ns3::WifiMacHelper::Create(), ns3::ClickInternetStackHelper::CreateAndAggregateObjectFromTypeId(), ns3::InternetStackHelper::CreateAndAggregateObjectFromTypeId(), ns3::MeshHelper::CreateInterface(), ns3::CreateObjectWithAttributes(), ns3::TcpOption::CreateOption(), ns3::TcpGeneralTest::CreateSocket(), ns3::TcpL4Protocol::CreateSocket(), ns3::PointerValue::DeserializeFromString(), Bug2831TestCase::DoRun(), BuildingsPenetrationLossesTestCase::DoRun(), ns3::tests::ObjectFactoryTestCase::DoRun(), PointerAttributeTestCase::DoRun(), SteadyStateRandomWaypointTest::DoRun(), ThreeGppChannelConditionModelTestCase::DoRun(), ThreeGppV2vBuildingsChCondModelTestCase::DoRun(), ThreeGppV2vHighwayLosNlosvChCondModelTestCase::DoRun(), ThreeGppV2vUrbanLosNlosvChCondModelTestCase::DoRun(), V2vHighwayProbChCondModelTestCase::DoRun(), V2vUrbanProbChCondModelTestCase::DoRun(), WaypointMobilityModelAddWaypointTest::DoRun(), WaypointMobilityModelNotifyTest::DoRun(), AmpduAggregationTest::DoSetup(), ns3::GetImpl(), ns3::EnergyHarvesterHelper::Install(), ns3::EnergySourceHelper::Install(), RoutingExperiment::Run(), FifoQueueDiscTestCase::RunFifoTest(), ThreeGppShadowingTestCase::RunTest(), ns3::GroupMobilityHelper::SetMemberPositionAllocator(), ns3::MobilityHelper::SetPositionAllocator(), ns3::GroupMobilityHelper::SetReferenceMobilityModel(), ns3::GroupMobilityHelper::SetReferencePositionAllocator(), ns3::DefaultSimulatorImpl::SetScheduler(), ns3::DistributedSimulatorImpl::SetScheduler(), ns3::NullMessageSimulatorImpl::SetScheduler(), ns3::RealtimeSimulatorImpl::SetScheduler(), ns3::UeManager::SetupDataRadioBearer(), and DsdvManetExample::SetupMobility().
Ptr< T > ns3::ObjectFactory::Create | ( | ) | const |
Create an Object instance of the requested type.
This method performs an extra call to ns3::Object::GetObject before returning a pointer of the requested type to the user. This method is really syntactical sugar.
T | [explicit] The requested Object type. |
Definition at line 194 of file object-factory.h.
References Create(), and NS_ASSERT_MSG.
|
private |
Set an attribute to be set during construction.
[in] | name | The name of the attribute to set. |
[in] | value | The value of the attribute to set. |
Definition at line 51 of file object-factory.cc.
References ns3::TypeId::AttributeInformation::checker, m_parameters, m_tid, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
Referenced by Set().
TypeId ns3::ObjectFactory::GetTypeId | ( | ) | const |
Get the TypeId which will be created by this ObjectFactory.
Definition at line 75 of file object-factory.cc.
References m_tid, and NS_LOG_FUNCTION.
Referenced by BenchSuite::BenchSuite().
bool ns3::ObjectFactory::IsTypeIdSet | ( | ) | const |
Check if the ObjectFactory has been configured with a TypeId.
Definition at line 45 of file object-factory.cc.
References m_tid.
|
inline |
Base case to stop the recursion performed by the templated version of this method.
Definition at line 94 of file object-factory.h.
Referenced by ObjectFactory(), and Set().
void ns3::ObjectFactory::Set | ( | const std::string & | name, |
const AttributeValue & | value, | ||
Args &&... | args ) |
Set an attribute to be set during construction.
Args | [deduced] Template type parameter pack for the sequence of name-value pairs |
[in] | name | The name of the attribute to set. |
[in] | value | The value of the attribute to set. |
[in] | args | A sequence of name-value pairs of additional attributes to set. |
The args sequence can be made of any number of pairs, each consisting of a name (of std::string type) followed by a value (of const AttributeValue & type).
Definition at line 213 of file object-factory.h.
References DoSet(), and Set().
Referenced by BuildSimpleTopology(), ns3::PfifoFastQueueDisc::CheckConfig(), ns3::WifiMacHelper::Create(), ns3::MeshHelper::CreateInterface(), ns3::CreateObjectWithAttributes(), PointerAttributeTestCase::DoRun(), SteadyStateRandomWaypointTest::DoRun(), WaypointMobilityModelAddWaypointTest::DoRun(), WaypointMobilityModelNotifyTest::DoRun(), RoutingExperiment::Run(), FifoQueueDiscTestCase::RunFifoTest(), ns3::lorawan::LoraRadioEnergyModelHelper::SetTxCurrentModel(), and DsdvManetExample::SetupMobility().
void ns3::ObjectFactory::SetTypeId | ( | std::string | tid | ) |
Set the TypeId of the Objects to be created by this factory.
[in] | tid | The TypeId of the object to instantiate. |
Definition at line 38 of file object-factory.cc.
References ns3::TypeId::LookupByName(), m_tid, and NS_LOG_FUNCTION.
void ns3::ObjectFactory::SetTypeId | ( | TypeId | tid | ) |
Set the TypeId of the Objects to be created by this factory.
[in] | tid | The TypeId of the object to instantiate. |
Definition at line 31 of file object-factory.cc.
References ns3::TypeId::GetName(), m_tid, and NS_LOG_FUNCTION.
Referenced by ObjectFactory(), SimulatorTestSuite::SimulatorTestSuite(), ThreadedSimulatorTestSuite::ThreadedSimulatorTestSuite(), ns3::LteUeRrc::ApplyRadioResourceConfigDedicated(), BuildSimpleTopology(), ns3::PfifoFastQueueDisc::CheckConfig(), ns3::PrioQueueDisc::CheckConfig(), ns3::TbfQueueDisc::CheckConfig(), ns3::ClickInternetStackHelper::CreateAndAggregateObjectFromTypeId(), ns3::InternetStackHelper::CreateAndAggregateObjectFromTypeId(), ns3::MeshHelper::CreateInterface(), ns3::CreateObjectWithAttributes(), ns3::TcpOption::CreateOption(), ns3::TcpGeneralTest::CreateSocket(), ns3::TcpL4Protocol::CreateSocket(), Bug2831TestCase::DoRun(), BuildingsPenetrationLossesTestCase::DoRun(), ns3::tests::ObjectFactoryTestCase::DoRun(), PointerAttributeTestCase::DoRun(), SteadyStateRandomWaypointTest::DoRun(), ThreeGppChannelConditionModelTestCase::DoRun(), ThreeGppV2vBuildingsChCondModelTestCase::DoRun(), ThreeGppV2vHighwayLosNlosvChCondModelTestCase::DoRun(), ThreeGppV2vUrbanLosNlosvChCondModelTestCase::DoRun(), V2vHighwayProbChCondModelTestCase::DoRun(), V2vUrbanProbChCondModelTestCase::DoRun(), WaypointMobilityModelAddWaypointTest::DoRun(), WaypointMobilityModelNotifyTest::DoRun(), AmpduAggregationTest::DoSetup(), ns3::anonymous_namespace{visual-simulator-impl.cc}::GetDefaultSimulatorImplFactory(), ns3::GetImpl(), ns3::EnergyHarvesterHelper::Install(), ns3::EnergySourceHelper::Install(), operator>>, RoutingExperiment::Run(), FifoQueueDiscTestCase::RunFifoTest(), ns3::Simulator::SetImplementation(), ns3::lorawan::LoraRadioEnergyModelHelper::SetTxCurrentModel(), ns3::UeManager::SetupDataRadioBearer(), and DsdvManetExample::SetupMobility().
|
friend |
Print the factory configuration on an output stream.
The configuration will be printed as a string with the form "<TypeId-name>[<attribute-name>=<attribute-value>|...]"
[in,out] | os | The stream. |
[in] | factory | The ObjectFactory. |
Definition at line 98 of file object-factory.cc.
References ObjectFactory(), ns3::AttributeConstructionList::Begin(), ns3::AttributeConstructionList::End(), ns3::TypeId::GetName(), m_parameters, and m_tid.
|
friend |
Read a factory configuration from an input stream.
The configuration should be in the form "<TypeId-name>[<attribute-name>=<attribute-value>|...]"
[in,out] | is | The input stream. |
[out] | factory | The factory to configure as described by the stream. |
Definition at line 116 of file object-factory.cc.
References ObjectFactory(), ns3::AttributeConstructionList::Add(), ns3::TypeId::AttributeInformation::checker, ns3::TypeId::LookupAttributeByName(), m_parameters, m_tid, NS_ABORT_MSG_IF, NS_ASSERT, and SetTypeId().
|
private |
The list of attributes and values to be used in constructing objects by this factory.
Definition at line 160 of file object-factory.h.
Referenced by Create(), DoSet(), operator<<, and operator>>.
|
private |
The TypeId this factory will create.
Definition at line 155 of file object-factory.h.
Referenced by Create(), DoSet(), GetTypeId(), IsTypeIdSet(), operator<<, operator>>, SetTypeId(), and SetTypeId().