72 for (Items::const_iterator i = cmd.
m_items.begin ();
85 for (Items::const_iterator i =
m_items.begin (); i !=
m_items.end (); ++i)
119 for (argc--, argv++; argc > 0; argc--, argv++)
122 std::string param = *argv;
123 std::string::size_type cur = param.find (
"--");
126 param = param.substr (2, param.size () - 2);
130 cur = param.find (
"-");
133 param = param.substr (1, param.size () - 1);
141 cur = param.find (
"=");
142 std::string name, value;
143 if (cur == std::string::npos)
150 name = param.substr (0, cur);
151 value = param.substr (cur + 1, param.size () - (cur+1));
162 os <<
m_name <<
" [Program Arguments] [General Arguments]"
174 for (Items::const_iterator i =
m_items.begin (); i !=
m_items.end (); ++i)
176 width = std::max (width, (*i)->m_name.size ());
181 os <<
"Program Arguments:" << std::endl;
182 for (Items::const_iterator i =
m_items.begin (); i !=
m_items.end (); ++i)
185 << std::left << std::setw (width) << ( (*i)->m_name +
":")
189 if ( (*i)->HasDefault ())
191 os <<
" [" << (*i)->GetDefault () <<
"]";
199 <<
"General Arguments:\n"
200 <<
" --PrintGlobals: Print the list of globals.\n"
201 <<
" --PrintGroups: Print the list of groups.\n"
202 <<
" --PrintGroup=[group]: Print all TypeIds of group.\n"
203 <<
" --PrintTypeIds: Print all TypeIds.\n"
204 <<
" --PrintAttributes=[typeid]: Print all attributes of typeid.\n"
205 <<
" --PrintHelp: Print this help message.\n"
214 os <<
"Global values:" << std::endl;
217 std::vector<std::string> globals;
223 std::stringstream ss;
224 ss <<
" --" << (*i)->GetName () <<
"=[";
228 ss << v.
Get () <<
"]" << std::endl;
229 ss <<
" " << (*i)->GetHelp () << std::endl;
230 globals.push_back (ss.str ());
232 std::sort (globals.begin (), globals.end ());
233 for (std::vector<std::string>::const_iterator it = globals.begin ();
249 NS_FATAL_ERROR (
"Unknown type=" << type <<
" in --PrintAttributes");
252 os <<
"Attributes for TypeId " << tid.
GetName () << std::endl;
255 std::vector<std::string> attributes;
259 std::stringstream ss;
264 ss <<
" " << info.
help << std::endl;
265 attributes.push_back (ss.str ());
267 std::sort (attributes.begin (), attributes.end ());
268 for (std::vector<std::string>::const_iterator it = attributes.begin ();
269 it < attributes.end ();
282 os <<
"TypeIds in group " << group <<
":" << std::endl;
285 std::vector<std::string> groupTypes;
289 std::stringstream ss;
293 ss <<
" " <<tid.
GetName () << std::endl;
295 groupTypes.push_back (ss.str ());
297 std::sort (groupTypes.begin (), groupTypes.end ());
298 for (std::vector<std::string>::const_iterator it = groupTypes.begin ();
299 it < groupTypes.end ();
310 os <<
"Registered TypeIds:" << std::endl;
313 std::vector<std::string> types;
317 std::stringstream ss;
319 ss <<
" " << tid.
GetName () << std::endl;
320 types.push_back (ss.str ());
322 std::sort (types.begin (), types.end ());
323 for (std::vector<std::string>::const_iterator it = types.begin ();
336 std::set<std::string> groups;
343 os <<
"Registered TypeId groups:" << std::endl;
345 for (std::set<std::string>::const_iterator k = groups.begin ();
349 os <<
" " << *k << std::endl;
358 NS_LOG_DEBUG (
"Handle arg name=" << name <<
" value=" << value);
359 if (name ==
"PrintHelp" || name ==
"help")
365 else if (name ==
"PrintGroups")
371 else if (name ==
"PrintTypeIds")
377 else if (name ==
"PrintGlobals")
383 else if (name ==
"PrintGroup")
389 else if (name ==
"PrintAttributes")
397 for (Items::const_iterator i =
m_items.begin (); i !=
m_items.end (); ++i)
399 if ((*i)->m_name == name)
401 if (!(*i)->Parse (value))
403 std::cerr <<
"Invalid argument value: "
404 << name <<
"=" << value << std::endl;
417 std::cerr <<
"Invalid command-line arguments: --"
418 << name <<
"=" << value << std::endl;
428 NS_LOG_DEBUG (
"CommandLine::CallbackItem::Parse \"" << value <<
"\"");
429 return m_callback (value);
434 const std::string &help,
447 const std::string &attributePath)
451 size_t colon = attributePath.rfind (
"::");
452 const std::string typeName = attributePath.substr (0, colon);
453 NS_LOG_DEBUG (
"typeName: '" << typeName <<
"', colon: " << colon);
461 const std::string attrName = attributePath.substr (colon + 2);
468 std::stringstream ss;
470 <<
" (" << attributePath <<
") ["
481 const std::string value)
509 std::ostringstream oss;
510 oss << std::boolalpha << val;
518 std::string src = value;
519 std::transform(src.begin(), src.end(), src.begin(), ::tolower);
521 if (src.length () == 0)
526 else if ( (src ==
"true") || (src ==
"t") )
531 else if ( (src ==
"false") || (src ==
"f"))
538 std::istringstream iss;
541 return !iss.bad () && !iss.fail ();
~CommandLine()
Destructor.
uint32_t GetAttributeN(void) const
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
bool SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
std::string Get(void) const
Items m_items
The list of arguments.
Hold variables of type string.
String attribute value declarations.
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
void PrintGlobals(std::ostream &os) const
Handler for --PrintGlobals: print all global variables and values.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Vector::const_iterator Iterator
#define NS_FATAL_ERROR(msg)
Fatal error handling.
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
std::string GetDefault< bool >(const bool &val)
Helper to specialize CommandLine::UserItem::GetDefault() on bool.
Declaration of the various ns3::Config functions and classes.
std::list< std::string > Split(std::string path)
Split a file system path into directories according to the local path separator.
std::string GetName() const
Get the program name.
void Usage(const std::string usage)
Supply the program usage and documentation.
System-independent file and directory function declarations.
void Clear(void)
Remove all arguments, Usage(), name.
void PrintAttributes(std::ostream &os, const std::string &type) const
Handler for --PrintAttributes: print the attributes for a given type.
An argument Item using a Callback to parse the input.
void PrintHelp(std::ostream &os) const
Print program usage to the desired output stream.
static bool HandleAttribute(const std::string name, const std::string value)
Callback function to handle attributes.
std::string m_usage
The Usage string.
static uint32_t GetRegisteredN(void)
virtual std::string GetDefault() const
static Iterator Begin(void)
static TypeId GetRegistered(uint32_t i)
std::string m_name
The program name.
Parse command-line arguments.
virtual bool Parse(const std::string value)
Parse from a string.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
void PrintGroups(std::ostream &os) const
Handler for --PrintGroups: print all TypeId group names.
CommandLine class declaration.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
CommandLine & operator=(const CommandLine &cmd)
Assignment.
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
ns3::TypeId declaration; inline and template implementations.
std::string m_name
Argument label: ---m_name=...
bool UserItemParse< bool >(const std::string value, bool &val)
Helpers to specialize CommandLine::UserItem::Parse() on bool.
Callback< bool, std::string > m_callback
The Callback.
std::string GetName(void) const
ns3::GlobalValue declaration.
virtual bool HasDefault() const
virtual ~Item()
Destructor.
std::string m_help
Argument help string.
CommandLine()
Constructor.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static Iterator End(void)
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void PrintTypeIds(std::ostream &os) const
Handler for --PrintTypeIds: print all TypeId names.
void Copy(const CommandLine &cmd)
Copy constructor.
void PrintGroup(std::ostream &os, const std::string &group) const
Handler for --PrintGroup: print all types belonging to a given group.
std::string GetAttributeFullName(uint32_t i) const
void Parse(int argc, char *argv[])
Parse the program arguments.
std::string GetGroupName(void) const
struct TypeId::AttributeInformation GetAttribute(uint32_t i) const
a unique identifier for an interface.
void HandleArgument(const std::string &name, const std::string &value) const
Match name against the program or general arguments, and dispatch to the appropriate handler...