21 #include "singleton.h"
22 #include "trace-source-accessor.h"
39 uint16_t AllocateUid (std::string name);
40 void SetParent (uint16_t uid, uint16_t parent);
41 void SetGroupName (uint16_t uid, std::string groupName);
43 void HideFromDocumentation (uint16_t uid);
44 uint16_t GetUid (std::string name)
const;
45 std::string GetName (uint16_t uid)
const;
46 uint16_t GetParent (uint16_t uid)
const;
47 std::string GetGroupName (uint16_t uid)
const;
49 bool HasConstructor (uint16_t uid)
const;
50 uint32_t GetRegisteredN (
void)
const;
51 uint16_t GetRegistered (uint32_t i)
const;
52 void AddAttribute (uint16_t uid,
59 void SetAttributeInitialValue(uint16_t uid,
62 uint32_t GetAttributeN (uint16_t uid)
const;
73 bool HasTraceSource (uint16_t uid, std::string name);
74 bool HasAttribute (uint16_t uid, std::string name);
79 std::string groupName;
82 bool mustHideFromDocumentation;
83 std::vector<struct ns3::TypeId::AttributeInformation> attributes;
84 std::vector<struct ns3::TypeId::TraceSourceInformation> traceSources;
86 typedef std::vector<struct IidInformation>::const_iterator Iterator;
90 std::vector<struct IidInformation> m_information;
93 IidManager::IidManager ()
99 IidManager::AllocateUid (std::string name)
103 for (Iterator i = m_information.begin (); i != m_information.end (); i++)
107 NS_FATAL_ERROR (
"Trying to allocate twice the same uid: " << name);
112 struct IidInformation information;
113 information.name = name;
114 information.parent = 0;
115 information.groupName =
"";
116 information.hasConstructor =
false;
117 information.mustHideFromDocumentation =
false;
118 m_information.push_back (information);
119 uint32_t uid = m_information.size ();
124 struct IidManager::IidInformation *
125 IidManager::LookupInformation (uint16_t uid)
const
128 NS_ASSERT (uid <= m_information.size () && uid != 0);
129 return const_cast<struct IidInformation *
> (&m_information[uid-1]);
133 IidManager::SetParent (uint16_t uid, uint16_t parent)
136 NS_ASSERT (parent <= m_information.size ());
137 struct IidInformation *information = LookupInformation (uid);
138 information->parent = parent;
141 IidManager::SetGroupName (uint16_t uid, std::string groupName)
144 struct IidInformation *information = LookupInformation (uid);
145 information->groupName = groupName;
148 IidManager::HideFromDocumentation (uint16_t uid)
151 struct IidInformation *information = LookupInformation (uid);
152 information->mustHideFromDocumentation =
true;
159 struct IidInformation *information = LookupInformation (uid);
160 if (information->hasConstructor)
162 NS_FATAL_ERROR (information->name<<
" already has a constructor.");
164 information->hasConstructor =
true;
165 information->constructor = callback;
169 IidManager::GetUid (std::string name)
const
173 for (Iterator i = m_information.begin (); i != m_information.end (); i++)
185 IidManager::GetName (uint16_t uid)
const
188 struct IidInformation *information = LookupInformation (uid);
189 return information->name;
192 IidManager::GetParent (uint16_t uid)
const
195 struct IidInformation *information = LookupInformation (uid);
196 return information->parent;
199 IidManager::GetGroupName (uint16_t uid)
const
202 struct IidInformation *information = LookupInformation (uid);
203 return information->groupName;
207 IidManager::GetConstructor (uint16_t uid)
const
210 struct IidInformation *information = LookupInformation (uid);
211 if (!information->hasConstructor)
213 NS_FATAL_ERROR (
"Requested constructor for "<<information->name<<
" but it does not have one.");
215 return information->constructor;
219 IidManager::HasConstructor (uint16_t uid)
const
222 struct IidInformation *information = LookupInformation (uid);
223 return information->hasConstructor;
227 IidManager::GetRegisteredN (
void)
const
230 return m_information.size ();
233 IidManager::GetRegistered (uint32_t i)
const
240 IidManager::HasAttribute (uint16_t uid,
244 struct IidInformation *information = LookupInformation (uid);
247 for (std::vector<struct ns3::TypeId::AttributeInformation>::const_iterator i = information->attributes.begin ();
248 i != information->attributes.end (); ++i)
255 struct IidInformation *parent = LookupInformation (information->parent);
256 if (parent == information)
262 information = parent;
268 IidManager::AddAttribute (uint16_t uid,
276 NS_LOG_FUNCTION (
this << uid << name << help << flags << initialValue << accessor << checker);
277 struct IidInformation *information = LookupInformation (uid);
278 if (HasAttribute (uid, name))
280 NS_FATAL_ERROR (
"Attribute \"" << name <<
"\" already registered on tid=\"" <<
281 information->name <<
"\"");
287 info.initialValue = initialValue;
288 info.originalInitialValue = initialValue;
289 info.accessor = accessor;
290 info.checker = checker;
291 information->attributes.push_back (info);
294 IidManager::SetAttributeInitialValue(uint16_t uid,
299 struct IidInformation *information = LookupInformation (uid);
300 NS_ASSERT (i < information->attributes.size ());
301 information->attributes[i].initialValue = initialValue;
307 IidManager::GetAttributeN (uint16_t uid)
const
310 struct IidInformation *information = LookupInformation (uid);
311 return information->attributes.size ();
314 IidManager::
GetAttribute(uint16_t uid, uint32_t i) const
317 struct IidInformation *information = LookupInformation (uid);
318 NS_ASSERT (i < information->attributes.size ());
319 return information->attributes[i];
323 IidManager::HasTraceSource (uint16_t uid,
327 struct IidInformation *information = LookupInformation (uid);
330 for (std::vector<struct ns3::TypeId::TraceSourceInformation>::const_iterator i = information->traceSources.begin ();
331 i != information->traceSources.end (); ++i)
338 struct IidInformation *parent = LookupInformation (information->parent);
339 if (parent == information)
345 information = parent;
351 IidManager::AddTraceSource (uint16_t uid,
357 struct IidInformation *information = LookupInformation (uid);
358 if (HasTraceSource (uid, name))
360 NS_FATAL_ERROR (
"Trace source \"" << name <<
"\" already registered on tid=\"" <<
361 information->name <<
"\"");
366 source.accessor = accessor;
367 information->traceSources.push_back (source);
370 IidManager::GetTraceSourceN (uint16_t uid)
const
373 struct IidInformation *information = LookupInformation (uid);
374 return information->traceSources.size ();
380 struct IidInformation *information = LookupInformation (uid);
381 NS_ASSERT (i < information->traceSources.size ());
382 return information->traceSources[i];
385 IidManager::MustHideFromDocumentation (uint16_t uid)
const
388 struct IidInformation *information = LookupInformation (uid);
389 return information->mustHideFromDocumentation;
400 TypeId::TypeId (
const char *name)
409 TypeId::TypeId (uint16_t tid)
419 NS_ASSERT_MSG (uid != 0,
"Assert in TypeId::LookupByName: " << name <<
" not found");
459 if (tmp.name == name)
466 }
while (nextTid != tid);
492 TypeId::HasParent (
void)
const
496 return parent != m_tid;
503 while (tmp != other && tmp != tmp.
GetParent ())
507 return tmp == other && *
this != other;
530 return hasConstructor;
547 NS_LOG_FUNCTION (
this << name << help << &initialValue << accessor << checker);
560 NS_LOG_FUNCTION (
this << name << help << flags << &initialValue << accessor << checker);
609 return GetName () +
"::" + info.name;
636 TypeId::HideFromDocumentation (
void)
644 Ptr<const TraceSourceAccessor>
655 if (info.name == name)
657 return info.accessor;
661 }
while (nextTid != tid);
683 std::istream &
operator >> (std::istream &is, TypeId &tid)
685 std::string tidString;
690 is.setstate (std::ios_base::badbit);
698 bool operator < (TypeId a, TypeId b)
700 return a.m_tid < b.m_tid;
uint32_t GetAttributeN(void) const
std::istream & operator>>(std::istream &is, Angles &a)
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)
TypeId GetParent(void) const
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
#define NS_LOG_FUNCTION_NOARGS()
#define NS_FATAL_ERROR(msg)
fatal error handling
Callback< ObjectBase * > GetConstructor(void) const
bool HasConstructor(void) const
bool MustHideFromDocumentation(void) const
static uint32_t GetRegisteredN(void)
Ptr< const TraceSourceAccessor > LookupTraceSourceByName(std::string name) const
uint32_t GetTraceSourceN(void) const
static TypeId GetRegistered(uint32_t i)
TypeId SetGroupName(std::string groupName)
std::ostream & operator<<(std::ostream &os, const Angles &a)
TypeId AddAttribute(std::string name, std::string help, const AttributeValue &initialValue, Ptr< const AttributeAccessor > accessor, Ptr< const AttributeChecker > checker)
virtual Ptr< AttributeValue > Copy(void) const =0
void SetUid(uint16_t tid)
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
#define ATTRIBUTE_HELPER_CPP(type)
std::string GetName(void) const
uint16_t GetUid(void) const
#define NS_ASSERT_MSG(condition, message)
bool SetAttributeInitialValue(uint32_t i, Ptr< const AttributeValue > initialValue)
TypeId AddTraceSource(std::string name, std::string help, Ptr< const TraceSourceAccessor > accessor)
std::string GetAttributeFullName(uint32_t i) const
bool IsChildOf(TypeId other) const
struct TypeId::TraceSourceInformation GetTraceSource(uint32_t i) const
std::string GetGroupName(void) const
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
a unique identifier for an interface.
static TypeId LookupByName(std::string name)