75 std::copy (
cmd.m_options.begin (),
cmd.m_options.end (),
m_options.end ());
127 if (args.size () > 0)
130 args.erase (args.begin ());
132 for (
auto param : args)
139 "unexpected error parsing command line parameter: '" 145 #ifdef ENABLE_DES_METRICS 155 std::string arg = param;
156 std::string::size_type cur = arg.find (
"--");
159 arg = arg.substr (2, arg.size () - 2);
163 cur = arg.find (
"-");
166 arg = arg.substr (1, arg.size () - 1);
175 cur = arg.find (
"=");
176 std::string name, value;
177 if (cur == std::string::npos)
184 name = arg.substr (0, cur);
185 value = arg.substr (cur + 1, arg.size () - (cur+1));
203 item->
m_name =
"extra-non-option-argument";
204 item->m_help =
"Extra non-option argument encountered.";
205 item->m_value = value;
210 if (!i->Parse (value))
212 std::cerr <<
"Invalid non-option argument value " 213 << value <<
" for " << i->m_name
227 std::vector<std::string> args (argv, argv + argc);
240 << (
m_options.size () ?
" [Program Options]" :
"")
241 << (nonOptions.size () ?
" [Program Arguments]" :
"")
242 <<
" [General Arguments]" 251 std::size_t width = 0;
254 width =
std::max (width, it->m_name.size ());
256 for (
auto it : nonOptions)
258 width =
std::max (width, it->m_name.size ());
265 os <<
"Program Options:" << std::endl;
269 << std::left << std::setw (width) << ( i->m_name +
":")
273 if ( i->HasDefault ())
275 os <<
" [" << i->GetDefault () <<
"]";
281 if (!nonOptions.empty ())
285 os <<
"Program Arguments:" << std::endl;
286 for (
auto i : nonOptions)
289 << std::left << std::setw (width) << ( i->m_name +
":")
293 if ( i->HasDefault ())
295 os <<
" [" << i->GetDefault () <<
"]";
303 <<
"General Arguments:\n" 304 <<
" --PrintGlobals: Print the list of globals.\n" 305 <<
" --PrintGroups: Print the list of groups.\n" 306 <<
" --PrintGroup=[group]: Print all TypeIds of group.\n" 307 <<
" --PrintTypeIds: Print all TypeIds.\n" 308 <<
" --PrintAttributes=[typeid]: Print all attributes of typeid.\n" 309 <<
" --PrintHelp: Print this help message.\n" 318 os <<
"Global values:" << std::endl;
321 std::vector<std::string> globals;
327 std::stringstream ss;
328 ss <<
" --" << (*i)->GetName () <<
"=[";
332 ss << v.
Get () <<
"]" << std::endl;
333 ss <<
" " << (*i)->GetHelp () << std::endl;
334 globals.push_back (ss.str ());
336 std::sort (globals.begin (), globals.end ());
337 for (std::vector<std::string>::const_iterator it = globals.begin ();
353 NS_FATAL_ERROR (
"Unknown type=" << type <<
" in --PrintAttributes");
356 os <<
"Attributes for TypeId " << tid.
GetName () << std::endl;
359 std::vector<std::string> attributes;
363 std::stringstream ss;
368 ss <<
" " << info.
help << std::endl;
369 attributes.push_back (ss.str ());
371 std::sort (attributes.begin (), attributes.end ());
372 for (std::vector<std::string>::const_iterator it = attributes.begin ();
373 it < attributes.end ();
386 os <<
"TypeIds in group " << group <<
":" << std::endl;
389 std::vector<std::string> groupTypes;
393 std::stringstream ss;
397 ss <<
" " <<tid.
GetName () << std::endl;
399 groupTypes.push_back (ss.str ());
401 std::sort (groupTypes.begin (), groupTypes.end ());
402 for (std::vector<std::string>::const_iterator it = groupTypes.begin ();
403 it < groupTypes.end ();
414 os <<
"Registered TypeIds:" << std::endl;
417 std::vector<std::string> types;
421 std::stringstream ss;
423 ss <<
" " << tid.
GetName () << std::endl;
424 types.push_back (ss.str ());
426 std::sort (types.begin (), types.end ());
427 for (std::vector<std::string>::const_iterator it = types.begin ();
440 std::set<std::string> groups;
447 os <<
"Registered TypeId groups:" << std::endl;
449 for (std::set<std::string>::const_iterator k = groups.begin ();
453 os <<
" " << *k << std::endl;
462 NS_LOG_DEBUG (
"Handle arg name=" << name <<
" value=" << value);
465 if (name ==
"PrintHelp" || name ==
"help")
471 else if (name ==
"PrintGroups")
477 else if (name ==
"PrintTypeIds")
483 else if (name ==
"PrintGlobals")
489 else if (name ==
"PrintGroup")
495 else if (name ==
"PrintAttributes")
505 if (i->m_name == name)
507 if (! i->Parse (value))
509 std::cerr <<
"Invalid argument value: " 510 << name <<
"=" << value << std::endl;
524 std::cerr <<
"Invalid command-line arguments: --" 525 << name <<
"=" << value << std::endl;
535 NS_LOG_DEBUG (
"CommandLine::CallbackItem::Parse \"" << value <<
"\"");
536 return m_callback (value);
541 const std::string &help,
554 const std::string &attributePath)
558 std::size_t colon = attributePath.rfind (
"::");
559 const std::string typeName = attributePath.substr (0, colon);
560 NS_LOG_DEBUG (
"typeName: '" << typeName <<
"', colon: " << colon);
568 const std::string attrName = attributePath.substr (colon + 2);
575 std::stringstream ss;
577 <<
" (" << attributePath <<
") [" 617 const std::string value)
664 std::ostringstream oss;
665 oss << std::boolalpha << val;
673 std::string src = value;
674 std::transform(src.begin(), src.end(), src.begin(),
675 [](
char c) {
return static_cast<char>(std::tolower(c)); });
676 if (src.length () == 0)
681 else if ( (src ==
"true") || (src ==
"t") )
686 else if ( (src ==
"false") || (src ==
"f"))
693 std::istringstream iss;
696 return !iss.bad () && !iss.fail ();
~CommandLine()
Destructor.
void PrintHelp(std::ostream &os) const
Print program usage to the desired output stream.
std::string GetName(void) const
Get the name.
void PrintGroups(std::ostream &os) const
Handler for --PrintGroups: print all TypeId group names.
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)
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Hold variables of type string.
std::vector< Item * > Items
Argument list container.
ns3::StringValue attribute value declarations.
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
std::string m_value
The argument value.
std::string GetName() const
Get the program name.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Items m_nonOptions
The list of non-option arguments.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Vector::const_iterator Iterator
Iterator type for the list of all global values.
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
std::string GetDefault< bool >(const bool &val)
Helper to specialize CommandLine::UserItem::GetDefault() on bool.
void PrintGlobals(std::ostream &os) const
Handler for --PrintGlobals: print all global variables and values.
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Declaration of the various ns3::Config functions and classes.
static DesMetrics * Get(void)
Get a pointer to the singleton instance.
ns3::DesMetrics declaration.
void PrintAttributes(std::ostream &os, const std::string &type) const
Handler for --PrintAttributes: print the attributes for a given type.
std::list< std::string > Split(std::string path)
Split a file system path into directories according to the local path separator.
void Usage(const std::string usage)
Supply the program usage and documentation.
bool HandleNonOption(const std::string &value)
Handle a non-option.
ns3::SystemPath declarations.
void Clear(void)
Remove all arguments, Usage(), name.
An argument Item using a Callback to parse the input.
void Initialize(std::vector< std::string > args, std::string outDir="")
Open the DesMetrics trace file and print the header.
static bool HandleAttribute(const std::string name, const std::string value)
Callback function to handle attributes.
virtual std::string GetDefault() const
Items m_options
The list of option arguments.
bool HandleOption(const std::string ¶m) const
Handle an option in the form param=value.
std::string Get(void) const
std::string m_usage
The Usage string.
std::string GetDefault(void) const
static Iterator Begin(void)
The Begin iterator.
std::size_t GetNExtraNonOptions(void) const
Get the total number of non-option arguments found, including those configured with AddNonOption() an...
bool Parse(const std::string value)
Parse from a string.
std::string GetExtraNonOption(std::size_t i) const
Get extra non-option arguments by index.
std::string m_name
The program name.
Parse command-line arguments.
bool HasDefault(void) const
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...
std::size_t m_nonOptionCount
The number of actual non-option arguments seen so far.
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
ns3::CommandLine declaration.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
CommandLine & operator=(const CommandLine &cmd)
Assignment.
std::string GetGroupName(void) const
Get the group name.
ns3::TypeId declaration; inline and template implementations.
std::string GetAttributeFullName(std::size_t i) const
Get the Attribute name by index.
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.
void PrintGroup(std::ostream &os, const std::string &group) const
Handler for --PrintGroup: print all types belonging to a given group.
Callback< bool, std::string > m_callback
The Callback.
ns3::GlobalValue declaration.
virtual ~Item()
Destructor.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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.
std::size_t GetAttributeN(void) const
Get the number of attributes.
static Iterator End(void)
The End iterator.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
void Copy(const CommandLine &cmd)
Copy constructor.
void Parse(int argc, char *argv[])
Parse the program arguments.
std::size_t m_NNonOptions
The expected number of non-option arguments.
static uint16_t GetRegisteredN(void)
Get the number of registered TypeIds.
a unique identifier for an interface.
void PrintTypeIds(std::ostream &os) const
Handler for --PrintTypeIds: print all TypeId names.
virtual bool HasDefault() const