20 #include "object-factory.h"
28 ObjectFactory::ObjectFactory ()
33 ObjectFactory::ObjectFactory (std::string typeId)
78 m_parameters.Add (name, info.checker, value.
Copy ());
103 os << factory.m_tid.
GetName () <<
"[";
105 for (AttributeConstructionList::CIterator i = factory.m_parameters.Begin (); i != factory.m_parameters.End (); ++i)
107 os << i->name <<
"=" << i->value->SerializeToString (i->checker);
116 std::istream &
operator >> (std::istream &is, ObjectFactory &factory)
120 std::string::size_type lbracket, rbracket;
121 lbracket = v.find (
"[");
122 rbracket = v.find (
"]");
123 if (lbracket == std::string::npos && rbracket == std::string::npos)
125 factory.SetTypeId (v);
128 if (lbracket == std::string::npos || rbracket == std::string::npos)
132 NS_ASSERT (lbracket != std::string::npos);
133 NS_ASSERT (rbracket != std::string::npos);
134 std::string tid = v.substr (0, lbracket);
135 std::string parameters = v.substr (lbracket+1,rbracket-(lbracket+1));
136 factory.SetTypeId (tid);
137 std::string::size_type cur;
139 while (cur != parameters.size ())
141 std::string::size_type equal = parameters.find (
"=", cur);
142 if (equal == std::string::npos)
144 is.setstate (std::ios_base::failbit);
149 std::string name = parameters.substr (cur, equal-cur);
150 struct TypeId::AttributeInformation info;
151 if (!factory.m_tid.LookupAttributeByName (name, &info))
153 is.setstate (std::ios_base::failbit);
158 std::string::size_type next = parameters.find (
"|", cur);
160 if (next == std::string::npos)
162 value = parameters.substr (equal+1, parameters.size () - (equal+1));
163 cur = parameters.size ();
167 value = parameters.substr (equal+1, next - (equal+1));
170 Ptr<AttributeValue> val = info.checker->Create ();
171 bool ok = val->DeserializeFromString (value, info.checker);
174 is.setstate (std::ios_base::failbit);
179 factory.m_parameters.Add (name, info.checker, val);
std::istream & operator>>(std::istream &is, Angles &a)
TypeId GetTypeId(void) const
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
Hold a value for an Attribute.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
void SetTypeId(TypeId tid)
implement the ns-3 type and attribute system
#define NS_FATAL_ERROR(msg)
fatal error handling
Callback< ObjectBase * > GetConstructor(void) const
void SetTypeId(TypeId tid)
Ptr< Object > Create(void) const
std::ostream & operator<<(std::ostream &os, const Angles &a)
virtual Ptr< AttributeValue > Copy(void) const =0
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
#define ATTRIBUTE_HELPER_CPP(type)
std::string GetName(void) const
void Set(std::string name, const AttributeValue &value)
instantiate subclasses of ns3::Object.
void Construct(const AttributeConstructionList &attributes)
a base class which provides memory management and object aggregation
a unique identifier for an interface.
static TypeId LookupByName(std::string name)