257 void Usage(
const std::string& usage);
268 template <
typename T>
269 void AddValue(
const std::string& name,
const std::string& help, T& value);
291 void AddValue(
const std::string& name,
const std::string& help,
char* value, std::size_t num);
298 typedef bool (*
Callback)(
const std::string& value);
312 void AddValue(
const std::string& name,
313 const std::string& help,
315 const std::string& defaultValue =
"");
323 void AddValue(
const std::string& name,
const std::string& attributePath);
334 template <
typename T>
335 void AddNonOption(
const std::string& name,
const std::string& help, T& value);
374 void Parse(
int argc,
char* argv[]);
385 void Parse(std::vector<std::string> args);
445 virtual bool Parse(
const std::string& value)
const = 0;
460 template <
typename T>
465 bool Parse(
const std::string& value)
const override;
481 bool Parse(
const std::string& value)
const override;
501 bool Parse(
const std::string& value)
const override;
521 bool Parse(
const std::string& value)
const override;
580 bool HandleArgument(
const std::string& name,
const std::string& value)
const;
588 static bool HandleAttribute(
const std::string& name,
const std::string& value);
617 void PrintGroup(std::ostream& os,
const std::string& group)
const;
646 using Items = std::vector<std::shared_ptr<Item>>;
672namespace CommandLineHelper
716std::string
GetDefault(
const std::string& defaultValue);
738 auto item = std::make_shared<UserItem<T>>();
741 item->m_valuePtr = &value;
743 std::stringstream ss;
745 ss >> item->m_default;
754 auto item = std::make_shared<UserItem<T>>();
757 item->m_valuePtr = &value;
759 std::stringstream ss;
761 ss >> item->m_default;
770 return !m_default.empty();
798 std::istringstream iss;
801 return !iss.bad() && !iss.fail();
Declaration of the various callback functions.
An argument Item using a Callback to parse the input.
bool HasDefault() const override
std::string GetDefault() const override
bool Parse(const std::string &value) const override
Parse from a string.
std::string m_default
The default value, as a string, if it exists.
ns3::Callback< bool, const std::string & > m_callback
The Callback.
Extension of Item for char*.
char * m_buffer
The buffer to write in to.
std::string m_default
The default value.
bool Parse(const std::string &value) const override
Parse from a string.
std::string GetDefault() const override
std::size_t m_size
The size of the buffer, including terminating null.
bool HasDefault() const override
The argument abstract base class.
virtual bool Parse(const std::string &value) const =0
Parse from a string.
virtual ~Item()
Destructor.
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 extra non-options, stored as strings.
bool Parse(const std::string &value) const override
Parse from a string.
std::string GetDefault() const override
std::string m_value
The argument value.
bool HasDefault() const override
An argument Item assigning to POD.
bool HasDefault() const override
std::string m_default
String representation of default value.
std::string GetDefault() const override
T * m_valuePtr
Pointer to the POD location.
bool Parse(const std::string &value) const override
Parse from a string.
Parse command-line arguments.
void PrintAttributeList(std::ostream &os, const TypeId tid, std::stringstream &header) const
Print the Attributes for a single type.
HasOptionName GetOptionName(const std::string ¶m) const
Strip leading -- or - from options.
std::tuple< bool, std::string, std::string > HasOptionName
Tuple type returned by GetOptionName().
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.
std::size_t m_nonOptionCount
The number of actual non-option arguments seen so far.
std::size_t GetNExtraNonOptions() const
Get the total number of non-option arguments found, including those configured with AddNonOption() an...
std::vector< std::shared_ptr< Item > > Items
Argument list container.
void PrintDoxygenUsage() const
Append usage message in Doxygen format to the file indicated by the NS_COMMANDLINE_INTROSPECTION envi...
~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 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 implementation.
std::size_t m_NNonOptions
The expected number of non-option arguments.
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.
void HandleHardOptions(const std::vector< std::string > &args) const
Handle hard-coded options.
std::string m_shortName
The source file name (without .cc), as would be given to ns3 run
bool HandleOption(const std::string ¶m) const
Handle an option in the form param=value.
std::string m_usage
The Usage string.
void Clear()
Remove all arguments, Usage(), name.
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.
bool HandleArgument(const std::string &name, const std::string &value) const
Match name against the program or general arguments, and dispatch to the appropriate handler.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
static bool HandleAttribute(const std::string &name, const std::string &value)
Callback function to handle attributes.
CommandLine()
Constructor.
void PrintHelp(std::ostream &os) const
Print program usage to the desired output stream.
std::string GetVersion() const
Get the program version.
void AddNonOption(const std::string &name, const std::string &help, T &value)
Add a non-option argument, assigning to POD.
CommandLine & operator=(const CommandLine &cmd)
Assignment.
void Usage(const std::string &usage)
Supply the program usage and documentation.
a unique identifier for an interface.
std::string GetDefault< Time >(const std::string &defaultValue)
Helper to specialize CommandLine::UserItem::GetDefault() on types needing special handling.
bool UserItemParse(const std::string &value, T &dest)
Helpers to specialize CommandLine::UserItem::Parse()
std::string GetDefault< bool >(const std::string &defaultValue)
Helper to specialize CommandLine::UserItem::GetDefault() on types needing special handling.
std::string GetDefault(const std::string &defaultValue)
Helper to specialize CommandLine::UserItem::GetDefault() on types needing special handling.
bool UserItemParse< bool >(const std::string &value, bool &dest)
Specialization of CommandLine::UserItem::Parse() to bool.
bool UserItemParse< uint8_t >(const std::string &value, uint8_t &dest)
Specialization of CommandLine::UserItem::Parse() 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.