1 #include "type-id-default-value.h" |
|
2 |
|
3 namespace ns3 { |
|
4 |
|
5 TypeIdDefaultValue::TypeIdDefaultValue (std::string name, |
|
6 std::string help, |
|
7 TypeId tid, |
|
8 std::string defaultValue) |
|
9 : DefaultValueBase (name, help), |
|
10 m_defaultName (defaultValue), |
|
11 m_name (defaultValue), |
|
12 m_interfaceId (tid) |
|
13 { |
|
14 DefaultValueList::Add (this); |
|
15 } |
|
16 TypeId |
|
17 TypeIdDefaultValue::GetValue (void) const |
|
18 { |
|
19 return TypeId::LookupByName (m_name); |
|
20 } |
|
21 void |
|
22 TypeIdDefaultValue::SetValue (TypeId interfaceId) |
|
23 { |
|
24 m_name = interfaceId.GetName (); |
|
25 } |
|
26 void |
|
27 TypeIdDefaultValue::SetValue (std::string name) |
|
28 { |
|
29 m_name = name; |
|
30 } |
|
31 bool |
|
32 TypeIdDefaultValue::DoParseValue (const std::string &value) |
|
33 { |
|
34 for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++) |
|
35 { |
|
36 TypeId tid = TypeId::GetRegistered (i); |
|
37 do { |
|
38 if (tid.GetName () == value && |
|
39 tid.HasConstructor ()) |
|
40 { |
|
41 // check that it really supports the requested interface. |
|
42 TypeId tmp = tid; |
|
43 do { |
|
44 if (tmp == m_interfaceId) |
|
45 { |
|
46 m_name = value; |
|
47 return true; |
|
48 } |
|
49 tmp = tmp.GetParent (); |
|
50 } while (tmp != Object::GetTypeId ()); |
|
51 } |
|
52 tid = tid.GetParent (); |
|
53 } while (tid != Object::GetTypeId ()); |
|
54 } |
|
55 return false; |
|
56 } |
|
57 |
|
58 std::string |
|
59 TypeIdDefaultValue::DoGetType (void) const |
|
60 { |
|
61 std::ostringstream oss; |
|
62 oss << "("; |
|
63 bool first = true; |
|
64 for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++) |
|
65 { |
|
66 TypeId tid = TypeId::GetRegistered (i); |
|
67 // can this interface id be used to create objects ? |
|
68 if (tid.HasConstructor ()) |
|
69 { |
|
70 TypeId tmp = tid; |
|
71 // does this interface id supports the requested interface id ? |
|
72 do { |
|
73 if (tmp == m_interfaceId) |
|
74 { |
|
75 if (!first) |
|
76 { |
|
77 oss << "|"; |
|
78 first = false; |
|
79 } |
|
80 oss << tid.GetName (); |
|
81 } |
|
82 tmp = tmp.GetParent (); |
|
83 } while (tmp != Object::GetTypeId ()); |
|
84 } |
|
85 } |
|
86 oss << ")"; |
|
87 return oss.str (); |
|
88 } |
|
89 |
|
90 std::string |
|
91 TypeIdDefaultValue::DoGetDefaultValue (void) const |
|
92 { |
|
93 return m_name; |
|
94 } |
|
95 |
|
96 } // namespace ns3 |
|