20 #ifndef COMMAND_LINE_H
21 #define COMMAND_LINE_H
265 void Usage (
const std::string usage);
276 template <
typename T>
277 void AddValue (
const std::string &name,
278 const std::string &help,
287 typedef bool (*
Callback) (
const std::string value);
301 void AddValue (
const std::string &name,
302 const std::string &help,
304 const std::string defaultValue =
"");
313 void AddValue (
const std::string &name,
314 const std::string &attributePath);
325 template <
typename T>
326 void AddNonOption (
const std::string name,
const std::string help, T & value);
365 void Parse (
int argc,
char *argv[]);
376 void Parse (std::vector<std::string> args);
437 virtual bool Parse (
const std::string value) = 0;
452 template <
typename T>
457 virtual bool Parse (
const std::string value);
473 bool Parse (
const std::string value);
497 virtual bool Parse (
const std::string value);
526 void HandleArgument (
const std::string &name,
const std::string &value)
const;
534 static bool HandleAttribute (
const std::string name,
const std::string value);
548 void PrintAttributes (std::ostream &os,
const std::string &type)
const;
563 void PrintGroup (std::ostream &os,
const std::string &group)
const;
609 namespace CommandLineHelper {
620 template <
typename T>
651 template <
typename T> std::string
GetDefault (
const T & val);
668 template <
typename T>
671 const std::string &help,
679 std::stringstream ss;
686 template <
typename T>
689 const std::string help,
697 std::stringstream ss;
705 template <
typename T>
709 return (m_default.size () > 0);
712 template <
typename T>
716 return CommandLineHelper::GetDefault<T> (*m_valuePtr);
719 template <
typename T>
723 std::ostringstream oss;
728 template <
typename T>
732 return CommandLineHelper::UserItemParse<T> (value, *m_valuePtr);
735 template <
typename T>
739 std::istringstream iss;
742 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 PrintAttributeList(std::ostream &os, const TypeId tid, std::stringstream &header) const
Print the Attributes for a single type.
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 ns3 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 as well as its parents.
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.
a unique identifier for an interface.
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.
ns3::TypeId declaration; inline and template implementations.