|
|
| 20 |
|
20 |
|
| 21 |
#include <algorithm> // for transform |
21 |
#include <algorithm> // for transform |
| 22 |
#include <cctype> // for tolower |
22 |
#include <cctype> // for tolower |
| 23 |
#include <cstdlib> // for exit |
23 |
#include <cstdlib> // for exit |
| 24 |
#include <iomanip> // for setw |
24 |
#include <iomanip> // for setw |
| 25 |
|
25 |
|
| 26 |
#include "command-line.h" |
26 |
#include "command-line.h" |
|
Lines 147-163
CommandLine::Parse (int iargc, char *argv[])
|
Link Here
|
|---|
|
| 147 |
} |
147 |
} |
| 148 |
|
148 |
|
| 149 |
void |
149 |
void |
| 150 |
CommandLine::PrintHelp (void) const |
150 |
CommandLine::PrintHelp (std::ostream &os) const |
| 151 |
{ |
151 |
{ |
| 152 |
NS_LOG_FUNCTION (this); |
152 |
NS_LOG_FUNCTION (this); |
| 153 |
|
153 |
|
| 154 |
std::cout << m_name << " [Program Arguments] [General Arguments]" |
154 |
os << m_name << " [Program Arguments] [General Arguments]" |
| 155 |
<< std::endl; |
155 |
<< std::endl; |
| 156 |
|
156 |
|
| 157 |
if (m_usage.length ()) |
157 |
if (m_usage.length ()) |
| 158 |
{ |
158 |
{ |
| 159 |
std::cout << std::endl; |
159 |
os << std::endl; |
| 160 |
std::cout << m_usage << std::endl; |
160 |
os << m_usage << std::endl; |
| 161 |
} |
161 |
} |
| 162 |
|
162 |
|
| 163 |
if (!m_items.empty ()) |
163 |
if (!m_items.empty ()) |
|
Lines 169-193
CommandLine::PrintHelp (void) const
|
Link Here
|
|---|
|
| 169 |
} |
169 |
} |
| 170 |
width += 3; |
170 |
width += 3; |
| 171 |
|
171 |
|
| 172 |
std::cout << std::endl; |
172 |
os << std::endl; |
| 173 |
std::cout << "Program Arguments:" << std::endl; |
173 |
os << "Program Arguments:" << std::endl; |
| 174 |
for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i) |
174 |
for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i) |
| 175 |
{ |
175 |
{ |
| 176 |
std::cout << " --" |
176 |
os << " --" |
| 177 |
<< std::left << std::setw (width) << ( (*i)->m_name + ":") |
177 |
<< std::left << std::setw (width) << ( (*i)->m_name + ":") |
| 178 |
<< std::right |
178 |
<< std::right |
| 179 |
<< (*i)->m_help; |
179 |
<< (*i)->m_help; |
| 180 |
|
180 |
|
| 181 |
if ( (*i)->HasDefault ()) |
181 |
if ( (*i)->HasDefault ()) |
| 182 |
{ |
182 |
{ |
| 183 |
std::cout << " [" << (*i)->GetDefault () << "]"; |
183 |
os << " [" << (*i)->GetDefault () << "]"; |
| 184 |
} |
184 |
} |
| 185 |
std::cout << std::endl; |
185 |
os << std::endl; |
| 186 |
} |
186 |
} |
| 187 |
} |
187 |
} |
| 188 |
|
188 |
|
| 189 |
std::cout << std::endl; |
189 |
os << std::endl; |
| 190 |
std::cout |
190 |
os |
| 191 |
<< "General Arguments:\n" |
191 |
<< "General Arguments:\n" |
| 192 |
<< " --PrintGlobals: Print the list of globals.\n" |
192 |
<< " --PrintGlobals: Print the list of globals.\n" |
| 193 |
<< " --PrintGroups: Print the list of groups.\n" |
193 |
<< " --PrintGroups: Print the list of groups.\n" |
|
Lines 199-278
CommandLine::PrintHelp (void) const
|
Link Here
|
|---|
|
| 199 |
} |
199 |
} |
| 200 |
|
200 |
|
| 201 |
void |
201 |
void |
| 202 |
CommandLine::PrintGlobals (void) const |
202 |
CommandLine::PrintGlobals (std::ostream &os) const |
| 203 |
{ |
203 |
{ |
| 204 |
NS_LOG_FUNCTION (this); |
204 |
NS_LOG_FUNCTION (this); |
| 205 |
|
205 |
|
| 206 |
std::cout << "Global values:" << std::endl; |
206 |
os << "Global values:" << std::endl; |
| 207 |
|
207 |
|
| 208 |
for (GlobalValue::Iterator i = GlobalValue::Begin (); |
208 |
for (GlobalValue::Iterator i = GlobalValue::Begin (); |
| 209 |
i != GlobalValue::End (); |
209 |
i != GlobalValue::End (); |
| 210 |
++i) |
210 |
++i) |
| 211 |
{ |
211 |
{ |
| 212 |
std::cout << " --" << (*i)->GetName () << "=["; |
212 |
os << " --" << (*i)->GetName () << "=["; |
| 213 |
Ptr<const AttributeChecker> checker = (*i)->GetChecker (); |
213 |
Ptr<const AttributeChecker> checker = (*i)->GetChecker (); |
| 214 |
StringValue v; |
214 |
StringValue v; |
| 215 |
(*i)->GetValue (v); |
215 |
(*i)->GetValue (v); |
| 216 |
std::cout << v.Get () << "]" << std::endl; |
216 |
os << v.Get () << "]" << std::endl; |
| 217 |
std::cout << " " << (*i)->GetHelp () << std::endl; |
217 |
os << " " << (*i)->GetHelp () << std::endl; |
| 218 |
} |
218 |
} |
| 219 |
} |
219 |
} |
| 220 |
|
220 |
|
| 221 |
void |
221 |
void |
| 222 |
CommandLine::PrintAttributes (std::string type) const |
222 |
CommandLine::PrintAttributes (std::ostream &os, const std::string &type) const |
| 223 |
{ |
223 |
{ |
| 224 |
NS_LOG_FUNCTION (this); |
224 |
NS_LOG_FUNCTION (this); |
| 225 |
|
225 |
|
| 226 |
TypeId tid; |
226 |
TypeId tid; |
| 227 |
if (!TypeId::LookupByNameFailSafe (type, &tid)) |
227 |
if (!TypeId::LookupByNameFailSafe (type, &tid)) |
| 228 |
{ |
228 |
{ |
| 229 |
NS_FATAL_ERROR ("Unknown type=" << type << " in --PrintAttributes"); |
229 |
NS_FATAL_ERROR ("Unknown type="<<type<<" in --PrintAttributes"); |
| 230 |
} |
230 |
} |
| 231 |
|
231 |
|
| 232 |
std::cout << "Attributes for TypeId " << tid.GetName () << std::endl; |
232 |
os << "Attributes for TypeId " << tid.GetName () << std::endl; |
| 233 |
|
233 |
|
| 234 |
for (uint32_t i = 0; i < tid.GetAttributeN (); ++i) |
234 |
for (uint32_t i = 0; i < tid.GetAttributeN (); ++i) |
| 235 |
{ |
235 |
{ |
| 236 |
std::cout << " --" << tid.GetAttributeFullName (i) << "=["; |
236 |
os << " --" << tid.GetAttributeFullName (i) << "=["; |
| 237 |
struct TypeId::AttributeInformation info = tid.GetAttribute (i); |
237 |
struct TypeId::AttributeInformation info = tid.GetAttribute (i); |
| 238 |
std::cout << info.initialValue->SerializeToString (info.checker) << "]" |
238 |
os << info.initialValue->SerializeToString (info.checker) << "]" |
| 239 |
<< std::endl; |
239 |
<< std::endl; |
| 240 |
std::cout << " " << info.help << std::endl; |
240 |
os << " " << info.help << std::endl; |
| 241 |
} |
241 |
} |
| 242 |
} |
242 |
} |
| 243 |
|
243 |
|
| 244 |
|
244 |
|
| 245 |
void |
245 |
void |
| 246 |
CommandLine::PrintGroup (std::string group) const |
246 |
CommandLine::PrintGroup (std::ostream &os, const std::string &group) const |
| 247 |
{ |
247 |
{ |
| 248 |
NS_LOG_FUNCTION (this); |
248 |
NS_LOG_FUNCTION (this); |
| 249 |
|
249 |
|
| 250 |
std::cout << "TypeIds in group " << group << ":" << std::endl; |
250 |
os << "TypeIds in group " << group << ":" << std::endl; |
| 251 |
|
251 |
|
| 252 |
for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i) |
252 |
for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i) |
| 253 |
{ |
253 |
{ |
| 254 |
TypeId tid = TypeId::GetRegistered (i); |
254 |
TypeId tid = TypeId::GetRegistered (i); |
| 255 |
if (tid.GetGroupName () == group) |
255 |
if (tid.GetGroupName () == group) |
| 256 |
{ |
256 |
{ |
| 257 |
std::cout << " " <<tid.GetName () << std::endl; |
257 |
os << " " <<tid.GetName () << std::endl; |
| 258 |
} |
258 |
} |
| 259 |
} |
259 |
} |
| 260 |
} |
260 |
} |
| 261 |
|
261 |
|
| 262 |
void |
262 |
void |
| 263 |
CommandLine::PrintTypeIds (void) const |
263 |
CommandLine::PrintTypeIds (std::ostream &os) const |
| 264 |
{ |
264 |
{ |
| 265 |
NS_LOG_FUNCTION (this); |
265 |
NS_LOG_FUNCTION (this); |
| 266 |
std::cout << "Registered TypeIds:" << std::endl; |
266 |
os << "Registered TypeIds:" << std::endl; |
| 267 |
for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i) |
267 |
for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i) |
| 268 |
{ |
268 |
{ |
| 269 |
TypeId tid = TypeId::GetRegistered (i); |
269 |
TypeId tid = TypeId::GetRegistered (i); |
| 270 |
std::cout << " " << tid.GetName () << std::endl; |
270 |
os << " " << tid.GetName () << std::endl; |
| 271 |
} |
271 |
} |
| 272 |
} |
272 |
} |
| 273 |
|
273 |
|
| 274 |
void |
274 |
void |
| 275 |
CommandLine::PrintGroups (void) const |
275 |
CommandLine::PrintGroups (std::ostream &os) const |
| 276 |
{ |
276 |
{ |
| 277 |
NS_LOG_FUNCTION (this); |
277 |
NS_LOG_FUNCTION (this); |
| 278 |
|
278 |
|
|
Lines 302-357
CommandLine::PrintGroups (void) const
|
Link Here
|
|---|
|
| 302 |
} |
302 |
} |
| 303 |
} |
303 |
} |
| 304 |
|
304 |
|
| 305 |
std::cout << "Registered TypeId groups:" << std::endl; |
305 |
os << "Registered TypeId groups:" << std::endl; |
| 306 |
|
306 |
|
| 307 |
for (std::list<std::string>::const_iterator k = groups.begin (); |
307 |
for (std::list<std::string>::const_iterator k = groups.begin (); |
| 308 |
k != groups.end (); |
308 |
k != groups.end (); |
| 309 |
++k) |
309 |
++k) |
| 310 |
{ |
310 |
{ |
| 311 |
std::cout << " " << *k << std::endl; |
311 |
os << " " << *k << std::endl; |
| 312 |
} |
312 |
} |
| 313 |
} |
313 |
} |
| 314 |
|
314 |
|
| 315 |
void |
315 |
void |
| 316 |
CommandLine::HandleArgument (std::string name, std::string value) const |
316 |
CommandLine::HandleArgument (const std::string &name, const std::string &value) const |
| 317 |
{ |
317 |
{ |
| 318 |
NS_LOG_FUNCTION (this << name << value); |
318 |
NS_LOG_FUNCTION (this << name << value); |
| 319 |
|
319 |
|
| 320 |
NS_LOG_DEBUG ("Handle arg name=" << name << " value=" << value); |
320 |
NS_LOG_DEBUG ("Handle arg name="<<name<<" value="<<value); |
| 321 |
if (name == "PrintHelp" || name == "help") |
321 |
if (name == "PrintHelp" || name == "help") |
| 322 |
{ |
322 |
{ |
| 323 |
// method below never returns. |
323 |
// method below never returns. |
| 324 |
PrintHelp (); |
324 |
PrintHelp (std::cout); |
| 325 |
std::exit (0); |
325 |
std::exit (0); |
| 326 |
} |
326 |
} |
| 327 |
else if (name == "PrintGroups") |
327 |
else if (name == "PrintGroups") |
| 328 |
{ |
328 |
{ |
| 329 |
// method below never returns. |
329 |
// method below never returns. |
| 330 |
PrintGroups (); |
330 |
PrintGroups (std::cout); |
| 331 |
std::exit (0); |
331 |
std::exit (0); |
| 332 |
} |
332 |
} |
| 333 |
else if (name == "PrintTypeIds") |
333 |
else if (name == "PrintTypeIds") |
| 334 |
{ |
334 |
{ |
| 335 |
// method below never returns. |
335 |
// method below never returns. |
| 336 |
PrintTypeIds (); |
336 |
PrintTypeIds (std::cout); |
| 337 |
std::exit (0); |
337 |
std::exit (0); |
| 338 |
} |
338 |
} |
| 339 |
else if (name == "PrintGlobals") |
339 |
else if (name == "PrintGlobals") |
| 340 |
{ |
340 |
{ |
| 341 |
// method below never returns. |
341 |
// method below never returns. |
| 342 |
PrintGlobals (); |
342 |
PrintGlobals (std::cout); |
| 343 |
std::exit (0); |
343 |
std::exit (0); |
| 344 |
} |
344 |
} |
| 345 |
else if (name == "PrintGroup") |
345 |
else if (name == "PrintGroup") |
| 346 |
{ |
346 |
{ |
| 347 |
// method below never returns. |
347 |
// method below never returns. |
| 348 |
PrintGroup (value); |
348 |
PrintGroup (std::cout, value); |
| 349 |
std::exit (0); |
349 |
std::exit (0); |
| 350 |
} |
350 |
} |
| 351 |
else if (name == "PrintAttributes") |
351 |
else if (name == "PrintAttributes") |
| 352 |
{ |
352 |
{ |
| 353 |
// method below never returns. |
353 |
// method below never returns. |
| 354 |
PrintAttributes (value); |
354 |
PrintAttributes (std::cout, value); |
| 355 |
std::exit (0); |
355 |
std::exit (0); |
| 356 |
} |
356 |
} |
| 357 |
else |
357 |
else |
|
Lines 378-384
CommandLine::HandleArgument (std::string name, std::string value) const
|
Link Here
|
|---|
|
| 378 |
{ |
378 |
{ |
| 379 |
std::cerr << "Invalid command-line arguments: --" |
379 |
std::cerr << "Invalid command-line arguments: --" |
| 380 |
<< name << "=" << value << std::endl; |
380 |
<< name << "=" << value << std::endl; |
| 381 |
PrintHelp (); |
381 |
PrintHelp (std::cerr); |
| 382 |
std::exit (1); |
382 |
std::exit (1); |
| 383 |
} |
383 |
} |
| 384 |
} |
384 |
} |