20 #ifndef COMMAND_LINE_H 21 #define COMMAND_LINE_H 239 void Usage (
const std::string usage);
250 template <
typename T>
251 void AddValue (
const std::string &name,
252 const std::string &help,
266 void AddValue (
const std::string &name,
267 const std::string &help,
276 void AddValue (
const std::string &name,
277 const std::string &attributePath);
288 template <
typename T>
289 void AddNonOption (
const std::string name,
const std::string help, T & value);
328 void Parse (
int argc,
char *argv[]);
339 void Parse (std::vector<std::string> args);
384 virtual bool Parse (
const std::string value) = 0;
399 template <
typename T>
404 virtual bool Parse (
const std::string value);
416 bool Parse (
const std::string value);
436 virtual bool Parse (
const std::string value);
464 void HandleArgument (
const std::string &name,
const std::string &value)
const;
472 static bool HandleAttribute (
const std::string name,
const std::string value);
485 void PrintAttributes (std::ostream &os,
const std::string &type)
const;
492 void PrintGroup (std::ostream &os,
const std::string &group)
const;
532 namespace CommandLineHelper {
543 template <
typename T>
557 template <
typename T>
576 template <
typename T>
579 const std::string &help,
587 std::stringstream ss;
594 template <
typename T>
597 const std::string help,
605 std::stringstream ss;
613 template <
typename T>
620 template <
typename T>
624 return CommandLineHelper::GetDefault<T> (*m_valuePtr);
627 template <
typename T>
631 std::ostringstream oss;
637 template <
typename T>
641 return CommandLineHelper::UserItemParse<T> (value, *m_valuePtr);
644 template <
typename T>
648 std::istringstream iss;
651 return !iss.bad () && !iss.fail ();
~CommandLine()
Destructor.
void PrintHelp(std::ostream &os) const
Print program usage to the desired output stream.
void PrintGroups(std::ostream &os) const
Handler for --PrintGroups: print all TypeId group names.
T * m_valuePtr
Pointer to the POD location.
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.
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_usage
The Usage string.
std::string GetDefault(void) const
std::string GetDefault() const
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
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=...
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.
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.
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() on bool.
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