20 #ifndef COMMAND_LINE_H 21 #define COMMAND_LINE_H 258 void Usage (
const std::string usage);
269 template <
typename T>
270 void AddValue (
const std::string &name,
271 const std::string &help,
280 typedef bool (*
Callback) (
const std::string value);
294 void AddValue (
const std::string &name,
295 const std::string &help,
297 const std::string defaultValue =
"");
306 void AddValue (
const std::string &name,
307 const std::string &attributePath);
318 template <
typename T>
319 void AddNonOption (
const std::string name,
const std::string help, T & value);
358 void Parse (
int argc,
char *argv[]);
369 void Parse (std::vector<std::string> args);
414 virtual bool Parse (
const std::string value) = 0;
429 template <
typename T>
434 virtual bool Parse (
const std::string value);
450 bool Parse (
const std::string value);
474 virtual bool Parse (
const std::string value);
503 void HandleArgument (
const std::string &name,
const std::string &value)
const;
511 static bool HandleAttribute (
const std::string name,
const std::string value);
524 void PrintAttributes (std::ostream &os,
const std::string &type)
const;
531 void PrintGroup (std::ostream &os,
const std::string &group)
const;
576 namespace CommandLineHelper {
587 template <
typename T>
617 template <
typename T>
635 template <
typename T>
638 const std::string &help,
646 std::stringstream ss;
653 template <
typename T>
656 const std::string help,
664 std::stringstream ss;
672 template <
typename T>
679 template <
typename T>
683 return CommandLineHelper::GetDefault<T> (*m_valuePtr);
686 template <
typename T>
690 std::ostringstream oss;
696 template <
typename T>
700 return CommandLineHelper::UserItemParse<T> (value, *m_valuePtr);
703 template <
typename T>
707 std::istringstream iss;
710 return !iss.bad () && !iss.fail ();
~CommandLine()
Destructor.
void PrintHelp(std::ostream &os) const
Print program usage to the desired output stream.
bool UserItemParse< bool >(const std::string value, bool &val)
Specialization of CommandLine::UserItem to bool.
void PrintGroups(std::ostream &os) const
Handler for --PrintGroups: print all TypeId group names.
T * m_valuePtr
Pointer to the POD location.
void PrintDoxygenUsage(void) const
Append usage message in Doxygen format to the file indicated by the NS_COMMANDLINE_INTROSPECTION envi...
std::vector< Item * > Items
Argument list container.
std::string m_value
The argument value.
std::string m_default
String representation of default value.
std::string GetName() const
Get the program name.
Items m_nonOptions
The list of non-option arguments.
virtual bool Parse(const std::string value)
Parse from a string.
The argument abstract base class.
An argument Item assigning to POD.
virtual bool Parse(const std::string value)=0
Parse from a string.
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.
void PrintAttributes(std::ostream &os, const std::string &type) const
Handler for --PrintAttributes: print the attributes for a given type.
void Usage(const std::string usage)
Supply the program usage and documentation.
bool HandleNonOption(const std::string &value)
Handle a non-option.
Declaration of the various callback functions.
void Clear(void)
Remove all arguments, Usage(), name.
void AddNonOption(const std::string name, const std::string help, T &value)
Add a non-option argument, assigning to POD.
An argument Item using a Callback to parse the input.
bool UserItemParse< uint8_t >(const std::string value, uint8_t &val)
Specialization of CommandLine::UserItem to uint8_t to distinguish from char.
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 m_shortName
The source file name (without .cc), as would be given to waf --run
std::string m_usage
The Usage string.
std::string GetDefault(void) const
ns3::Callback< bool, std::string > m_callback
The Callback.
bool HasDefault(void) const
std::string GetDefault() const
std::string m_default
The default value, as a string, if it exists.
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 GetDefault(void) const
std::string GetExtraNonOption(std::size_t i) const
Get extra non-option arguments by index.
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string GetDefault(const T &val)
Helper to specialize CommandLine::UserItem::GetDefault() on bool.
CommandLine & operator=(const CommandLine &cmd)
Assignment.
std::string m_name
Argument label: ---m_name=...
void PrintGroup(std::ostream &os, const std::string &group) const
Handler for --PrintGroup: print all types belonging to a given group.
CommandLine(void)
Constructor.
virtual ~Item()
Destructor.
std::string m_help
Argument help string.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
void Copy(const CommandLine &cmd)
Copy constructor.
void Parse(int argc, char *argv[])
Parse the program arguments.
bool UserItemParse(const std::string value, T &val)
Helpers to specialize CommandLine::UserItem::Parse()
std::size_t m_NNonOptions
The expected number of non-option arguments.
void PrintTypeIds(std::ostream &os) const
Handler for --PrintTypeIds: print all TypeId names.
virtual bool HasDefault() const
Extension of Item for strings.