File: | /tmp/asd-nat/home/nat/Work/ns-3-dev-git/build/../src/core/model/object-base.cc |
Location: | line 123, column 19 |
Description: | Value stored to 'found' is never read |
1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 | /* |
3 | * Copyright (c) 2008 INRIA |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License version 2 as |
7 | * published by the Free Software Foundation; |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | * |
18 | * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
19 | */ |
20 | #include "object-base.h" |
21 | #include "log.h" |
22 | #include "trace-source-accessor.h" |
23 | #include "attribute-construction-list.h" |
24 | #include "string.h" |
25 | #include "ns3/core-config.h" |
26 | #ifdef HAVE_STDLIB_H1 |
27 | #include <cstdlib> |
28 | #endif |
29 | |
30 | /** |
31 | * \file |
32 | * \ingroup object |
33 | * ns3::ObjectBase class implementation. |
34 | */ |
35 | |
36 | namespace ns3 { |
37 | |
38 | NS_LOG_COMPONENT_DEFINE ("ObjectBase")static ns3::LogComponent g_log = ns3::LogComponent ("ObjectBase" , "../src/core/model/object-base.cc"); |
39 | |
40 | NS_OBJECT_ENSURE_REGISTERED (ObjectBase)static struct ObjectObjectBaseRegistrationClass { ObjectObjectBaseRegistrationClass () { ns3::TypeId tid = ObjectBase::GetTypeId (); tid.SetSize (sizeof (ObjectBase)); tid.GetParent (); } } ObjectObjectBaseRegistrationVariable; |
41 | |
42 | /** |
43 | * Ensure the TypeId for ObjectBase gets fully configured |
44 | * to anchor the inheritance tree properly. |
45 | * |
46 | * \relates ns3::ObjectBase |
47 | * |
48 | * \return The TypeId for ObjectBase. |
49 | */ |
50 | static TypeId |
51 | GetObjectIid (void) |
52 | { |
53 | NS_LOG_FUNCTION_NOARGS ()do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "()" << std::endl; } } while (false ); |
54 | TypeId tid = TypeId ("ns3::ObjectBase"); |
55 | tid.SetParent (tid); |
56 | tid.SetGroupName ("Core"); |
57 | return tid; |
58 | } |
59 | |
60 | TypeId |
61 | ObjectBase::GetTypeId (void) |
62 | { |
63 | NS_LOG_FUNCTION_NOARGS ()do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "()" << std::endl; } } while (false ); |
64 | static TypeId tid = GetObjectIid (); |
65 | return tid; |
66 | } |
67 | |
68 | ObjectBase::~ObjectBase () |
69 | { |
70 | NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this; std::clog << ")" << std::endl; } } while ( false); |
71 | } |
72 | |
73 | void |
74 | ObjectBase::NotifyConstructionCompleted (void) |
75 | { |
76 | NS_LOG_FUNCTION (this)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this; std::clog << ")" << std::endl; } } while ( false); |
77 | } |
78 | |
79 | void |
80 | ObjectBase::ConstructSelf (const AttributeConstructionList &attributes) |
81 | { |
82 | // loop over the inheritance tree back to the Object base class. |
83 | NS_LOG_FUNCTION (this << &attributes)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << &attributes; std::clog << ")" << std::endl; } } while (false); |
84 | TypeId tid = GetInstanceTypeId (); |
85 | do { |
86 | // loop over all attributes in object type |
87 | NS_LOG_DEBUG ("construct tid="<<tid.GetName ()<<", params="<<tid.GetAttributeN ())do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "construct tid=" <<tid.GetName ()<<", params="<<tid.GetAttributeN () << std::endl; } } while (false); |
88 | for (uint32_t i = 0; i < tid.GetAttributeN (); i++) |
89 | { |
90 | struct TypeId::AttributeInformation info = tid.GetAttribute(i); |
91 | NS_LOG_DEBUG ("try to construct \""<< tid.GetName ()<<"::"<<do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "try to construct \"" << tid.GetName ()<<"::"<< info.name << "\"" << std::endl; } } while (false) |
92 | info.name <<"\"")do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "try to construct \"" << tid.GetName ()<<"::"<< info.name << "\"" << std::endl; } } while (false); |
93 | // is this attribute stored in this AttributeConstructionList instance ? |
94 | Ptr<AttributeValue> value = attributes.Find(info.checker); |
95 | // See if this attribute should not be set here in the |
96 | // constructor. |
97 | if (!(info.flags & TypeId::ATTR_CONSTRUCT)) |
98 | { |
99 | // Handle this attribute if it should not be |
100 | // set here. |
101 | if (value == 0) |
102 | { |
103 | // Skip this attribute if it's not in the |
104 | // AttributeConstructionList. |
105 | continue; |
106 | } |
107 | else |
108 | { |
109 | // This is an error because this attribute is not |
110 | // settable in its constructor but is present in |
111 | // the AttributeConstructionList. |
112 | NS_FATAL_ERROR ("Attribute name="<<info.name<<" tid="<<tid.GetName () << ": initial value cannot be set using attributes")do { std::cerr << "msg=\"" << "Attribute name="<< info.name<<" tid="<<tid.GetName () << ": initial value cannot be set using attributes" << "\", "; do { std::cerr << "file=" << "../src/core/model/object-base.cc" << ", line=" << 112 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } while (false); |
113 | } |
114 | } |
115 | bool found = false; |
116 | if (value != 0) |
117 | { |
118 | // We have a matching attribute value. |
119 | if (DoSet (info.accessor, info.checker, *value)) |
120 | { |
121 | NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "construct \"" << tid.GetName ()<<"::"<< info.name<< "\"" << std::endl; } } while (false) |
122 | info.name<<"\"")do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "construct \"" << tid.GetName ()<<"::"<< info.name<< "\"" << std::endl; } } while (false); |
123 | found = true; |
Value stored to 'found' is never read | |
124 | continue; |
125 | } |
126 | } |
127 | if (!found) |
128 | { |
129 | // No matching attribute value so we try to look at the env var. |
130 | #ifdef HAVE_GETENV1 |
131 | char *envVar = getenv ("NS_ATTRIBUTE_DEFAULT"); |
132 | if (envVar != 0) |
133 | { |
134 | std::string env = std::string (envVar); |
135 | std::string::size_type cur = 0; |
136 | std::string::size_type next = 0; |
137 | while (next != std::string::npos) |
138 | { |
139 | next = env.find (";", cur); |
140 | std::string tmp = std::string (env, cur, next-cur); |
141 | std::string::size_type equal = tmp.find ("="); |
142 | if (equal != std::string::npos) |
143 | { |
144 | std::string name = tmp.substr (0, equal); |
145 | std::string value = tmp.substr (equal+1, tmp.size () - equal - 1); |
146 | if (name == tid.GetAttributeFullName (i)) |
147 | { |
148 | if (DoSet (info.accessor, info.checker, StringValue (value))) |
149 | { |
150 | NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "construct \"" << tid.GetName ()<<"::"<< info.name << "\" from env var" << std::endl; } } while (false) |
151 | info.name <<"\" from env var")do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "construct \"" << tid.GetName ()<<"::"<< info.name << "\" from env var" << std::endl; } } while (false); |
152 | found = true; |
153 | break; |
154 | } |
155 | } |
156 | } |
157 | cur = next + 1; |
158 | } |
159 | } |
160 | #endif /* HAVE_GETENV */ |
161 | } |
162 | if (!found) |
163 | { |
164 | // No matching attribute value so we try to set the default value. |
165 | DoSet (info.accessor, info.checker, *info.initialValue); |
166 | NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "construct \"" << tid.GetName ()<<"::"<< info.name << "\" from initial value." << std::endl; } } while (false ) |
167 | info.name <<"\" from initial value.")do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "construct \"" << tid.GetName ()<<"::"<< info.name << "\" from initial value." << std::endl; } } while (false ); |
168 | } |
169 | } |
170 | tid = tid.GetParent (); |
171 | } while (tid != ObjectBase::GetTypeId ()); |
172 | NotifyConstructionCompleted (); |
173 | } |
174 | |
175 | bool |
176 | ObjectBase::DoSet (Ptr<const AttributeAccessor> accessor, |
177 | Ptr<const AttributeChecker> checker, |
178 | const AttributeValue &value) |
179 | { |
180 | NS_LOG_FUNCTION (this << accessor << checker << &value)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << accessor << checker << &value; std::clog << ")" << std::endl; } } while (false); |
181 | Ptr<AttributeValue> v = checker->CreateValidValue (value); |
182 | if (v == 0) |
183 | { |
184 | return false; |
185 | } |
186 | bool ok = accessor->Set (this, *v); |
187 | return ok; |
188 | } |
189 | |
190 | void |
191 | ObjectBase::SetAttribute (std::string name, const AttributeValue &value) |
192 | { |
193 | NS_LOG_FUNCTION (this << name << &value)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << name << &value; std::clog << ")" << std::endl; } } while (false); |
194 | struct TypeId::AttributeInformation info; |
195 | TypeId tid = GetInstanceTypeId (); |
196 | if (!tid.LookupAttributeByName (name, &info)) |
197 | { |
198 | NS_FATAL_ERROR ("Attribute name="<<name<<" does not exist for this object: tid="<<tid.GetName ())do { std::cerr << "msg=\"" << "Attribute name="<< name<<" does not exist for this object: tid="<<tid .GetName () << "\", "; do { std::cerr << "file=" << "../src/core/model/object-base.cc" << ", line=" << 198 << std::endl; ::ns3::FatalImpl::FlushStreams (); if (true) std::terminate (); } while (false); } while (false); |
199 | } |
200 | if (!(info.flags & TypeId::ATTR_SET) || |
201 | !info.accessor->HasSetter ()) |
202 | { |
203 | NS_FATAL_ERROR ("Attribute name="<<name<<" is not settable for this object: tid="<<tid.GetName ())do { std::cerr << "msg=\"" << "Attribute name="<< name<<" is not settable for this object: tid="<<tid .GetName () << "\", "; do { std::cerr << "file=" << "../src/core/model/object-base.cc" << ", line=" << 203 << std::endl; ::ns3::FatalImpl::FlushStreams (); if (true) std::terminate (); } while (false); } while (false); |
204 | } |
205 | if (!DoSet (info.accessor, info.checker, value)) |
206 | { |
207 | NS_FATAL_ERROR ("Attribute name="<<name<<" could not be set for this object: tid="<<tid.GetName ())do { std::cerr << "msg=\"" << "Attribute name="<< name<<" could not be set for this object: tid="<< tid.GetName () << "\", "; do { std::cerr << "file=" << "../src/core/model/object-base.cc" << ", line=" << 207 << std::endl; ::ns3::FatalImpl::FlushStreams (); if (true) std::terminate (); } while (false); } while (false ); |
208 | } |
209 | } |
210 | bool |
211 | ObjectBase::SetAttributeFailSafe (std::string name, const AttributeValue &value) |
212 | { |
213 | NS_LOG_FUNCTION (this << name << &value)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << name << &value; std::clog << ")" << std::endl; } } while (false); |
214 | struct TypeId::AttributeInformation info; |
215 | TypeId tid = GetInstanceTypeId (); |
216 | if (!tid.LookupAttributeByName (name, &info)) |
217 | { |
218 | return false; |
219 | } |
220 | if (!(info.flags & TypeId::ATTR_SET) || |
221 | !info.accessor->HasSetter ()) |
222 | { |
223 | return false; |
224 | } |
225 | return DoSet (info.accessor, info.checker, value); |
226 | } |
227 | |
228 | void |
229 | ObjectBase::GetAttribute (std::string name, AttributeValue &value) const |
230 | { |
231 | NS_LOG_FUNCTION (this << name << &value)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << name << &value; std::clog << ")" << std::endl; } } while (false); |
232 | struct TypeId::AttributeInformation info; |
233 | TypeId tid = GetInstanceTypeId (); |
234 | if (!tid.LookupAttributeByName (name, &info)) |
235 | { |
236 | NS_FATAL_ERROR ("Attribute name="<<name<<" does not exist for this object: tid="<<tid.GetName ())do { std::cerr << "msg=\"" << "Attribute name="<< name<<" does not exist for this object: tid="<<tid .GetName () << "\", "; do { std::cerr << "file=" << "../src/core/model/object-base.cc" << ", line=" << 236 << std::endl; ::ns3::FatalImpl::FlushStreams (); if (true) std::terminate (); } while (false); } while (false); |
237 | } |
238 | if (!(info.flags & TypeId::ATTR_GET) || |
239 | !info.accessor->HasGetter ()) |
240 | { |
241 | NS_FATAL_ERROR ("Attribute name="<<name<<" is not gettable for this object: tid="<<tid.GetName ())do { std::cerr << "msg=\"" << "Attribute name="<< name<<" is not gettable for this object: tid="<<tid .GetName () << "\", "; do { std::cerr << "file=" << "../src/core/model/object-base.cc" << ", line=" << 241 << std::endl; ::ns3::FatalImpl::FlushStreams (); if (true) std::terminate (); } while (false); } while (false); |
242 | } |
243 | bool ok = info.accessor->Get (this, value); |
244 | if (ok) |
245 | { |
246 | return; |
247 | } |
248 | StringValue *str = dynamic_cast<StringValue *> (&value); |
249 | if (str == 0) |
250 | { |
251 | NS_FATAL_ERROR ("Attribute name="<<name<<" tid="<<tid.GetName () << ": input value is not a string")do { std::cerr << "msg=\"" << "Attribute name="<< name<<" tid="<<tid.GetName () << ": input value is not a string" << "\", "; do { std::cerr << "file=" << "../src/core/model/object-base.cc" << ", line=" << 251 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } while (false); |
252 | } |
253 | Ptr<AttributeValue> v = info.checker->Create (); |
254 | ok = info.accessor->Get (this, *PeekPointer (v)); |
255 | if (!ok) |
256 | { |
257 | NS_FATAL_ERROR ("Attribute name="<<name<<" tid="<<tid.GetName () << ": could not get value")do { std::cerr << "msg=\"" << "Attribute name="<< name<<" tid="<<tid.GetName () << ": could not get value" << "\", "; do { std::cerr << "file=" << "../src/core/model/object-base.cc" << ", line=" << 257 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } while (false); |
258 | } |
259 | str->Set (v->SerializeToString (info.checker)); |
260 | } |
261 | |
262 | |
263 | bool |
264 | ObjectBase::GetAttributeFailSafe (std::string name, AttributeValue &value) const |
265 | { |
266 | NS_LOG_FUNCTION (this << name << &value)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << name << &value; std::clog << ")" << std::endl; } } while (false); |
267 | struct TypeId::AttributeInformation info; |
268 | TypeId tid = GetInstanceTypeId (); |
269 | if (!tid.LookupAttributeByName (name, &info)) |
270 | { |
271 | return false; |
272 | } |
273 | if (!(info.flags & TypeId::ATTR_GET) || |
274 | !info.accessor->HasGetter ()) |
275 | { |
276 | return false; |
277 | } |
278 | bool ok = info.accessor->Get (this, value); |
279 | if (ok) |
280 | { |
281 | return true; |
282 | } |
283 | StringValue *str = dynamic_cast<StringValue *> (&value); |
284 | if (str == 0) |
285 | { |
286 | return false; |
287 | } |
288 | Ptr<AttributeValue> v = info.checker->Create (); |
289 | ok = info.accessor->Get (this, *PeekPointer (v)); |
290 | if (!ok) |
291 | { |
292 | return false; |
293 | } |
294 | str->Set (v->SerializeToString (info.checker)); |
295 | return true; |
296 | } |
297 | |
298 | bool |
299 | ObjectBase::TraceConnectWithoutContext (std::string name, const CallbackBase &cb) |
300 | { |
301 | NS_LOG_FUNCTION (this << name << &cb)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << name << &cb; std::clog << ")" << std::endl; } } while (false); |
302 | TypeId tid = GetInstanceTypeId (); |
303 | Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name); |
304 | if (accessor == 0) |
305 | { |
306 | return false; |
307 | } |
308 | bool ok = accessor->ConnectWithoutContext (this, cb); |
309 | return ok; |
310 | } |
311 | bool |
312 | ObjectBase::TraceConnect (std::string name, std::string context, const CallbackBase &cb) |
313 | { |
314 | NS_LOG_FUNCTION (this << name << context << &cb)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << name << context << &cb; std::clog << ")" << std::endl; } } while (false); |
315 | TypeId tid = GetInstanceTypeId (); |
316 | Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name); |
317 | if (accessor == 0) |
318 | { |
319 | return false; |
320 | } |
321 | bool ok = accessor->Connect (this, context, cb); |
322 | return ok; |
323 | } |
324 | bool |
325 | ObjectBase::TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb) |
326 | { |
327 | NS_LOG_FUNCTION (this << name << &cb)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << name << &cb; std::clog << ")" << std::endl; } } while (false); |
328 | TypeId tid = GetInstanceTypeId (); |
329 | Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name); |
330 | if (accessor == 0) |
331 | { |
332 | return false; |
333 | } |
334 | bool ok = accessor->DisconnectWithoutContext (this, cb); |
335 | return ok; |
336 | } |
337 | bool |
338 | ObjectBase::TraceDisconnect (std::string name, std::string context, const CallbackBase &cb) |
339 | { |
340 | NS_LOG_FUNCTION (this << name << context << &cb)do { if (g_log.IsEnabled (ns3::LOG_FUNCTION)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; std::clog << g_log.Name () << ":" << __FUNCTION__ << "("; ns3::ParameterLogger (std::clog) << this << name << context << &cb; std::clog << ")" << std::endl; } } while (false); |
341 | TypeId tid = GetInstanceTypeId (); |
342 | Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name); |
343 | if (accessor == 0) |
344 | { |
345 | return false; |
346 | } |
347 | bool ok = accessor->Disconnect (this, context, cb); |
348 | return ok; |
349 | } |
350 | |
351 | |
352 | |
353 | } // namespace ns3 |