20 #ifndef COMMAND_LINE_H
21 #define COMMAND_LINE_H
264 void Usage (
const std::string usage);
275 template <
typename T>
276 void AddValue (
const std::string &name,
277 const std::string &help,
286 typedef bool (*
Callback) (
const std::string value);
300 void AddValue (
const std::string &name,
301 const std::string &help,
303 const std::string defaultValue =
"");
312 void AddValue (
const std::string &name,
313 const std::string &attributePath);
324 template <
typename T>
325 void AddNonOption (
const std::string name,
const std::string help, T & value);
364 void Parse (
int argc,
char *argv[]);
375 void Parse (std::vector<std::string> args);
436 virtual bool Parse (
const std::string value) = 0;
451 template <
typename T>
456 virtual bool Parse (
const std::string value);
472 bool Parse (
const std::string value);
496 virtual bool Parse (
const std::string value);
525 void HandleArgument (
const std::string &name,
const std::string &value)
const;
533 static bool HandleAttribute (
const std::string name,
const std::string value);
546 void PrintAttributes (std::ostream &os,
const std::string &type)
const;
553 void PrintGroup (std::ostream &os,
const std::string &group)
const;
598 namespace CommandLineHelper {
609 template <
typename T>
640 template <
typename T> std::string
GetDefault (
const T & val);
657 template <
typename T>
660 const std::string &help,
668 std::stringstream ss;
675 template <
typename T>
678 const std::string help,
686 std::stringstream ss;
694 template <
typename T>
701 template <
typename T>
705 return CommandLineHelper::GetDefault<T> (*m_valuePtr);
708 template <
typename T>
712 std::ostringstream oss;
717 template <
typename T>
721 return CommandLineHelper::UserItemParse<T> (value, *m_valuePtr);
724 template <
typename T>
728 std::istringstream iss;
731 return !iss.bad () && !iss.fail ();
Declaration of the various callback functions.
An argument Item using a Callback to parse the input.
std::string GetDefault(void) const
ns3::Callback< bool, std::string > m_callback
The Callback.
virtual bool Parse(const std::string value)
Parse from a string.
std::string m_default
The default value, as a string, if it exists.
bool HasDefault(void) const
The argument abstract base class.
virtual ~Item()
Destructor.
virtual bool Parse(const std::string value)=0
Parse from a string.
virtual bool HasDefault() const
virtual std::string GetDefault() const =0
std::string m_name
Argument label: --m_name=...
std::string m_help
Argument help string.
Extension of Item for strings.
bool Parse(const std::string value)
Parse from a string.
bool HasDefault(void) const
std::string m_value
The argument value.
std::string GetDefault(void) const
An argument Item assigning to POD.
std::string m_default
String representation of default value.
virtual bool Parse(const std::string value)
Parse from a string.
std::string GetDefault() const
T * m_valuePtr
Pointer to the POD location.
Parse command-line arguments.
void PrintGroups(std::ostream &os) const
Handler for --PrintGroups: print all TypeId group names.
void PrintTypeIds(std::ostream &os) const
Handler for --PrintTypeIds: print all TypeId names.
std::string GetExtraNonOption(std::size_t i) const
Get extra non-option arguments by index.
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.
~CommandLine()
Destructor.
std::string GetName() const
Get the program name.
Items m_options
The list of option arguments.
bool HandleNonOption(const std::string &value)
Handle a non-option.
void AddNonOption(const std::string name, const std::string help, T &value)
Add a non-option argument, assigning to POD.
std::vector< Item * > Items
Argument list container.
void Parse(int argc, char *argv[])
Parse the program arguments.
void PrintGroup(std::ostream &os, const std::string &group) const
Handler for --PrintGroup: print all types belonging to a given group.
void Copy(const CommandLine &cmd)
Copy constructor.
std::size_t m_NNonOptions
The expected number of non-option arguments.
void Clear(void)
Remove all arguments, Usage(), name.
void PrintGlobals(std::ostream &os) const
Handler for --PrintGlobals: print all global variables and values.
Items m_nonOptions
The list of non-option arguments.
void PrintVersion(std::ostream &os) const
Print ns-3 version to the desired output stream.
std::string m_shortName
The source file name (without .cc), as would be given to waf --run
void Usage(const std::string usage)
Supply the program usage and documentation.
bool HandleOption(const std::string ¶m) const
Handle an option in the form param=value.
std::string m_usage
The Usage string.
void PrintAttributes(std::ostream &os, const std::string &type) const
Handler for --PrintAttributes: print the attributes for a given type.
CommandLine(void)
Constructor.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
std::size_t GetNExtraNonOptions(void) const
Get the total number of non-option arguments found, including those configured with AddNonOption() an...
void PrintHelp(std::ostream &os) const
Print program usage to the desired output stream.
std::string GetVersion() const
Get the program version.
CommandLine & operator=(const CommandLine &cmd)
Assignment.
static bool HandleAttribute(const std::string name, const std::string value)
Callback function to handle attributes.
void PrintDoxygenUsage(void) const
Append usage message in Doxygen format to the file indicated by the NS_COMMANDLINE_INTROSPECTION envi...
Simulation virtual time values and global simulation resolution.
std::string GetDefault< Time >(const Time &val)
Helper to specialize CommandLine::UserItem::GetDefault() on types needing special handling.
bool UserItemParse(const std::string value, T &val)
Helpers to specialize CommandLine::UserItem::Parse()
std::string GetDefault(const T &val)
Helper to specialize CommandLine::UserItem::GetDefault() on types needing special handling.
std::string GetDefault< bool >(const bool &val)
Helper to specialize CommandLine::UserItem::GetDefault() on types needing special handling.
bool UserItemParse< bool >(const std::string value, bool &val)
Specialization of CommandLine::UserItem to bool.
bool UserItemParse< uint8_t >(const std::string value, uint8_t &val)
Specialization of CommandLine::UserItem to uint8_t to distinguish from char.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.