NS3的ObjectFactory類

一個經常使用的創建對象的方法是:調用CreateObject(),在ns3中,也可以使用ObjectFactory類。在helper類中經常使用。

ObjectFactory類可以實例化對象,也可以設置屬性,例如:

void SetTypeId (TypeId tid);
void Set (std::string name, const AttributeValue &value);
Ptr<T> Create (void) const;

第一個方法:創建對象。
第二個方法:設置屬性。
第三個方法:創建對象本身。

例如:

ObjectFactory factory;
// Make this factory create objects of type FriisPropagationLossModel
factory.SetTypeId ("ns3::FriisPropagationLossModel")
// Make this factory object change a default value of an attribute, for
// subsequently created objects
factory.Set ("SystemLoss", DoubleValue (2.0));
// Create one such object
Ptr<Object> object = factory.Create ();
factory.Set ("SystemLoss", DoubleValue (3.0));
// Create another object with a different SystemLoss
Ptr<Object> object = factory.Create ();

這個類常用的public函數:
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章