268 void Usage(
const std::string& usage);
279 template <
typename T>
280 void AddValue(
const std::string& name,
const std::string& help, T& value);
302 void AddValue(
const std::string& name,
const std::string& help,
char* value, std::size_t num);
309 typedef bool (*
Callback)(
const std::string& value);
323 void AddValue(
const std::string& name,
324 const std::string& help,
326 const std::string& defaultValue =
"");
334 void AddValue(
const std::string& name,
const std::string& attributePath);
345 template <
typename T>
346 void AddNonOption(
const std::string& name,
const std::string& help, T& value);
385 void Parse(
int argc,
char* argv[]);
396 void Parse(std::vector<std::string> args);
456 virtual bool Parse(
const std::string& value)
const = 0;
471 template <
typename T>
476 bool Parse(
const std::string& value)
const override;
492 bool Parse(
const std::string& value)
const override;
512 bool Parse(
const std::string& value)
const override;
532 bool Parse(
const std::string& value)
const override;
591 bool HandleArgument(
const std::string& name,
const std::string& value)
const;
599 static bool HandleAttribute(
const std::string& name,
const std::string& value);
628 void PrintGroup(std::ostream& os,
const std::string& group)
const;
657 using Items = std::vector<std::shared_ptr<Item>>;
682namespace CommandLineHelper
726std::string
GetDefault(
const std::string& defaultValue);
748 auto item = std::make_shared<UserItem<T>>();
751 item->m_valuePtr = &value;
753 std::stringstream ss;
755 ss >> item->m_default;
764 auto item = std::make_shared<UserItem<T>>();
767 item->m_valuePtr = &value;
769 std::stringstream ss;
771 ss >> item->m_default;
780 return !m_default.empty();
787 return CommandLineHelper::GetDefault<T>(m_default);
801 return CommandLineHelper::UserItemParse<T>(value, *m_valuePtr);
808 std::istringstream iss;
811 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::vector< std::shared_ptr< Item > > Items
Argument list container.
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...
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.