A Discrete-Event Network Simulator
API
ns3::CommandLine Class Reference

Parse command-line arguments. More...

#include "command-line.h"

+ Collaboration diagram for ns3::CommandLine:

Classes

class  CallbackItem
 An argument Item using a Callback to parse the input. More...
 
class  CharStarItem
 Extension of Item for char*. More...
 
class  Item
 The argument abstract base class. More...
 
class  StringItem
 Extension of Item for extra non-options, stored as strings. More...
 
class  UserItem
 An argument Item assigning to POD. More...
 

Public Types

typedef bool(* Callback) (const std::string &value)
 Callback function signature for AddValue(const std::string&,const std::string&,Callback<bool,const std::string>). More...
 

Public Member Functions

 CommandLine ()
 Constructor. More...
 
 CommandLine (const CommandLine &cmd)
 Copy constructor. More...
 
 CommandLine (const std::string &filename)
 Construct and register the source file name. More...
 
 ~CommandLine ()
 Destructor. More...
 
template<typename T >
void AddNonOption (const std::string &name, const std::string &help, T &value)
 Add a non-option argument, assigning to POD. More...
 
void AddValue (const std::string &name, const std::string &attributePath)
 Add a program argument as a shorthand for an Attribute. More...
 
void AddValue (const std::string &name, const std::string &help, char *value, std::size_t num)
 Retrieve the char* in char* and add it as a program argument. More...
 
void AddValue (const std::string &name, const std::string &help, ns3::Callback< bool, const std::string & > callback, const std::string &defaultValue="")
 Add a program argument, using a Callback to parse the value. More...
 
template<typename T >
void AddValue (const std::string &name, const std::string &help, T &value)
 Add a program argument, assigning to POD. More...
 
std::string GetExtraNonOption (std::size_t i) const
 Get extra non-option arguments by index. More...
 
std::string GetName () const
 Get the program name. More...
 
std::size_t GetNExtraNonOptions () const
 Get the total number of non-option arguments found, including those configured with AddNonOption() and extra non-option arguments. More...
 
std::string GetVersion () const
 Get the program version. More...
 
CommandLineoperator= (const CommandLine &cmd)
 Assignment. More...
 
void Parse (int argc, char *argv[])
 Parse the program arguments. More...
 
void Parse (std::vector< std::string > args)
 Parse the program arguments. More...
 
void PrintHelp (std::ostream &os) const
 Print program usage to the desired output stream. More...
 
void PrintVersion (std::ostream &os) const
 Print ns-3 version to the desired output stream. More...
 
void Usage (const std::string &usage)
 Supply the program usage and documentation. More...
 

Private Types

using HasOptionName = std::tuple< bool, std::string, std::string >
 Tuple type returned by GetOptionName(). More...
 
using Items = std::vector< std::shared_ptr< Item > >
 Argument list container. More...
 

Private Member Functions

void Clear ()
 Remove all arguments, Usage(), name. More...
 
void Copy (const CommandLine &cmd)
 Copy constructor implementation. More...
 
HasOptionName GetOptionName (const std::string &param) const
 Strip leading -- or - from options. More...
 
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. More...
 
void HandleHardOptions (const std::vector< std::string > &args) const
 Handle hard-coded options. More...
 
bool HandleNonOption (const std::string &value)
 Handle a non-option. More...
 
bool HandleOption (const std::string &param) const
 Handle an option in the form param=value. More...
 
void PrintAttributeList (std::ostream &os, const TypeId tid, std::stringstream &header) const
 Print the Attributes for a single type. More...
 
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. More...
 
void PrintDoxygenUsage () const
 Append usage message in Doxygen format to the file indicated by the NS_COMMANDLINE_INTROSPECTION environment variable. More...
 
void PrintGlobals (std::ostream &os) const
 Handler for --PrintGlobals: print all global variables and values. More...
 
void PrintGroup (std::ostream &os, const std::string &group) const
 Handler for --PrintGroup: print all types belonging to a given group. More...
 
void PrintGroups (std::ostream &os) const
 Handler for --PrintGroups: print all TypeId group names. More...
 
void PrintTypeIds (std::ostream &os) const
 Handler for --PrintTypeIds: print all TypeId names. More...
 

Static Private Member Functions

static bool HandleAttribute (const std::string &name, const std::string &value)
 Callback function to handle attributes. More...
 

Private Attributes

std::size_t m_NNonOptions
 The expected number of non-option arguments. More...
 
std::size_t m_nonOptionCount
 The number of actual non-option arguments seen so far. More...
 
Items m_nonOptions
 The list of non-option arguments. More...
 
Items m_options
 The list of option arguments. More...
 
std::string m_shortName
 The source file name (without .cc), as would be given to ns3 run More...
 
std::string m_usage
 The Usage string. More...
 

Detailed Description

Parse command-line arguments.

Instances of this class can be used to parse command-line arguments. Programs can register a general usage message with CommandLine::Usage, and arguments with CommandLine::AddValue. Argument variable types with input streamers (operator>>) can be set directly; more complex argument parsing can be accomplished by providing a Callback.

CommandLine also provides handlers for these standard arguments:

  --PrintGlobals:              Print the list of globals.
  --PrintGroups:               Print the list of groups.
  --PrintGroup=[group]:        Print all TypeIds of group.
  --PrintTypeIds:              Print all TypeIds.
  --PrintAttributes=[typeid]:  Print all attributes of typeid.
  --PrintVersion:              Print the ns-3 version.
  --PrintHelp:                 Print this help message. 

The more common --version is a synonym for --PrintVersion.

The more common --help is a synonym for --PrintHelp; an example is given below.

CommandLine can also handle non-option arguments (often called simply "positional" parameters: arguments which don't begin with "-" or "--"). These can be parsed directly in to variables, by registering arguments with AddNonOption in the order expected. Additional non-option arguments encountered will be captured as strings.

Finally, CommandLine processes Attribute and GlobalValue arguments. Default values for specific attributes can be set using a shorthand argument name.

In use, arguments are given in the form

  --arg=value --toggle first-non-option

Most arguments expect a value, as in the first form, --arg=value. Toggles, corresponding to boolean arguments, can be given in any of the forms

  --toggle1 --toggle2=1 --toggle3=t --toggle4=true 

The first form changes the state of toggle1 from its default; all the rest set the corresponding boolean variable to true. 0, f and false are accepted to set the variable to false. Option arguments can appear in any order on the command line, even intermixed with non-option arguments. The order of non-option arguments is preserved.

Option arguments can be repeated on the command line; the last value given will be the final value used. For example,

  --arg=one --toggle=f --arg=another --toggle 

The variable set by --arg will end up with the value "another"; the boolean set by --toggle will end up as true.

Because arguments can be repeated it can be hard to decipher what value each variable ended up with, especially when using boolean toggles. Suggested best practice is for scripts to report the values of all items settable through CommandLine, as done by the example below.

CommandLine can set the initial value of every attribute in the system with the --TypeIdName::AttributeName=value syntax, for example

  --Application::StartTime=3s 

In some cases you may want to highlight the use of a particular attribute for a simulation script. For example, you might want to make it easy to set the Application::StartTime using the argument --start, and have its help string show as part of the help message. This can be done using the AddValue (name, attributePath) method.

CommandLine can also set the value of every GlobalValue in the system with the --GlobalValueName=value syntax, for example

  --SchedulerType=HeapScheduler 

A simple example of CommandLine is in src/core/example/command-line-example.cc See that file for an example of handling non-option arguments.

The heart of that example is this code:

int intArg = 1;
bool boolArg = false;
std::string strArg = "strArg default";
CommandLine cmd (__FILE__);
cmd.Usage ("CommandLine example program.\n"
"\n"
"This little program demonstrates how to use CommandLine.");
cmd.AddValue ("intArg", "an int argument", intArg);
cmd.AddValue ("boolArg", "a bool argument", boolArg);
cmd.AddValue ("strArg", "a string argument", strArg);
cmd.AddValue ("anti", "ns3::RandomVariableStream::Antithetic");
cmd.AddValue ("cbArg", "a string via callback", MakeCallback (SetCbArg));
cmd.Parse (argc, argv);
CommandLine()
Constructor.
bool SetCbArg(const std::string &val)
Function to illustrate command line arguments handled by a Callback function.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:704
cmd
Definition: second.py:40

after which it prints the values of each variable. (The SetCbArg function is not shown here; see src/core/example/command-line-example.cc)

Here is the output from a few runs of that program:

  $ ./ns3 run "command-line-example"
  intArg:   1
  boolArg:  false
  strArg:   "strArg default"
  cbArg:    "cbArg default"

  $ ./ns3 run "command-line-example --intArg=2 --boolArg --strArg=Hello --cbArg=World"
  intArg:   2
  boolArg:  true
  strArg:   "Hello"
  cbArg:    "World"

  $ ./ns3 run "command-line-example --help"
  ns3-dev-command-line-example-debug [Program Arguments] [General Arguments]

  CommandLine example program.

  This little program demonstrates how to use CommandLine.

  Program Arguments:
      --intArg:   an int argument [1]
      --boolArg:  a bool argument [false]
      --strArg:   a string argument [strArg default]
      --anti:     Set this RNG stream to generate antithetic values
(ns3::RandomVariableStream::Antithetic) [false]
      --cbArg:    a string via callback

  General Arguments:
      --PrintGlobals:              Print the list of globals.
      --PrintGroups:               Print the list of groups.
      --PrintGroup=[group]:        Print all TypeIds of group.
      --PrintTypeIds:              Print all TypeIds.
      --PrintAttributes=[typeid]:  Print all attributes of typeid.
      --PrintVersion:              Print the ns-3 version.
      --PrintHelp:                 Print this help message. 

Having parsed the arguments, some programs will need to perform some additional validation of the received values. A common issue at this point is to discover that the supplied arguments are incomplete or incompatible. Suggested best practice is to supply an error message and the complete usage message. For example,

int value1;
int value2;
CommandLine cmd (__FILE__);
cmd.Usage ("...");
cmd.AddValue ("value1", "first value", value1);
cmd.AddValue ("value2", "second value", value1);
cmd.Parse (argc, argv);
if (value1 * value2 < 0)
{
std::cerr << "value1 and value2 must have the same sign!" << std::endl;
std::cerr << cmd;
exit (-1);
}

Finally, note that for examples which will be run by test.py the preferred declaration of a CommandLine instance is

CommandLine cmd (__FILE__);

This will ensure that the program usage and arguments can be added to the Doxygen documentation automatically.

Definition at line 231 of file command-line.h.

Member Typedef Documentation

◆ Callback

typedef bool(* ns3::CommandLine::Callback) (const std::string &value)

Callback function signature for AddValue(const std::string&,const std::string&,Callback<bool,const std::string>).

Parameters
[in]valueThe argument value.

Definition at line 309 of file command-line.h.

◆ HasOptionName

using ns3::CommandLine::HasOptionName = std::tuple<bool, std::string, std::string>
private

Tuple type returned by GetOptionName().

Field Meaning
get<0> Is this an option (beginning with -)?
get<1> The option name (after any -, before =)
get<2> The value (after any =)

Definition at line 549 of file command-line.h.

◆ Items

using ns3::CommandLine::Items = std::vector<std::shared_ptr<Item> >
private

Argument list container.

Definition at line 657 of file command-line.h.

Constructor & Destructor Documentation

◆ CommandLine() [1/3]

ns3::CommandLine::CommandLine ( )

Constructor.

Definition at line 111 of file command-line.cc.

References NS_LOG_FUNCTION.

◆ CommandLine() [2/3]

ns3::CommandLine::CommandLine ( const std::string &  filename)

Construct and register the source file name.

This would typically be called by CommandLine cmd (FILE);

This form is required to generate Doxygen documentation of the arguments and options.

Parameters
[in]filenameThe source file name.

Definition at line 120 of file command-line.cc.

References m_shortName, NS_LOG_FUNCTION, and ns3::SystemPath::Split().

+ Here is the call graph for this function:

◆ CommandLine() [3/3]

ns3::CommandLine::CommandLine ( const CommandLine cmd)

Copy constructor.

Parameters
[in]cmdThe CommandLine to copy from

Definition at line 131 of file command-line.cc.

References second::cmd, and Copy().

+ Here is the call graph for this function:

◆ ~CommandLine()

ns3::CommandLine::~CommandLine ( )

Destructor.

Definition at line 144 of file command-line.cc.

References Clear(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

Member Function Documentation

◆ AddNonOption()

template<typename T >
void ns3::CommandLine::AddNonOption ( const std::string &  name,
const std::string &  help,
T &  value 
)

Add a non-option argument, assigning to POD.

Parameters
[in]nameThe name of the program-supplied argument
[in]helpThe help text used by --PrintHelp
[out]valueA reference to the variable where the value parsed will be stored (if no value is parsed, this variable is not modified).

Definition at line 762 of file command-line.h.

References check-style-clang-format::help, m_NNonOptions, and m_nonOptions.

◆ AddValue() [1/4]

void ns3::CommandLine::AddValue ( const std::string &  name,
const std::string &  attributePath 
)

Add a program argument as a shorthand for an Attribute.

Parameters
[in]nameThe name of the program-supplied argument.
[out]attributePathThe fully-qualified name of the Attribute

Definition at line 778 of file command-line.cc.

References AddValue(), ns3::TypeId::AttributeInformation::checker, HandleAttribute(), ns3::TypeId::AttributeInformation::help, ns3::TypeId::AttributeInformation::initialValue, ns3::TypeId::LookupAttributeByName(), ns3::TypeId::LookupByNameFailSafe(), ns3::MakeBoundCallback(), NS_FATAL_ERROR, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ AddValue() [2/4]

void ns3::CommandLine::AddValue ( const std::string &  name,
const std::string &  help,
char *  value,
std::size_t  num 
)

Retrieve the char* in char* and add it as a program argument.

This variant it used to receive C string pointers from the python bindings.

The C string result stored in value will be null-terminated, and have a maximum length of (num - 1). The result will be truncated to fit, if necessary.

Parameters
[in]nameThe name of the program-supplied argument
[in]helpThe help text used by --PrintHelp
[out]valueA pointer pointing to the beginning of a null-terminated C string buffer provided by the caller. The parsed value will be stored in that buffer (if no value is parsed, this variable is not modified).
numThe size of the buffer pointed to by value, including any terminating null.

Definition at line 746 of file command-line.cc.

References check-style-clang-format::help, m_options, NS_LOG_FUNCTION, and two-ray-to-three-gpp-ch-calibration::num.

◆ AddValue() [3/4]

void ns3::CommandLine::AddValue ( const std::string &  name,
const std::string &  help,
ns3::Callback< bool, const std::string & >  callback,
const std::string &  defaultValue = "" 
)

Add a program argument, using a Callback to parse the value.

Parameters
[in]nameThe name of the program-supplied argument
[in]helpThe help text used by --help
[in]callbackA Callback function that will be invoked to parse and store the value.
[in]defaultValueOptional default value for argument.

The callback should have the signature CommandLine::Callback

Definition at line 762 of file command-line.cc.

References check-style-clang-format::help, m_options, and NS_LOG_FUNCTION.

◆ AddValue() [4/4]

template<typename T >
void ns3::CommandLine::AddValue ( const std::string &  name,
const std::string &  help,
T &  value 
)

Add a program argument, assigning to POD.

Parameters
[in]nameThe name of the program-supplied argument
[in]helpThe help text used by --PrintHelp
[out]valueA reference to the variable where the value parsed will be stored (if no value is parsed, this variable is not modified).

Definition at line 746 of file command-line.h.

References check-style-clang-format::help, and m_options.

Referenced by AddValue().

+ Here is the caller graph for this function:

◆ Clear()

void ns3::CommandLine::Clear ( )
private

Remove all arguments, Usage(), name.

Definition at line 165 of file command-line.cc.

References m_NNonOptions, m_nonOptions, m_options, m_shortName, m_usage, and NS_LOG_FUNCTION.

Referenced by ~CommandLine(), and operator=().

+ Here is the caller graph for this function:

◆ Copy()

void ns3::CommandLine::Copy ( const CommandLine cmd)
private

Copy constructor implementation.

Parameters
[in]cmdCommandLine to copy

Definition at line 151 of file command-line.cc.

References second::cmd, m_NNonOptions, m_nonOptionCount, m_nonOptions, m_options, m_shortName, m_usage, and NS_LOG_FUNCTION.

Referenced by CommandLine(), and operator=().

+ Here is the caller graph for this function:

◆ GetExtraNonOption()

std::string ns3::CommandLine::GetExtraNonOption ( std::size_t  i) const

Get extra non-option arguments by index.

This allows CommandLine to accept more non-option arguments than have been configured explicitly with AddNonOption().

This is only valid after calling Parse().

Parameters
[in]iThe index of the non-option argument to return.
Returns
The i'th non-option argument, as a string.

Definition at line 807 of file command-line.cc.

References m_NNonOptions, and m_nonOptions.

◆ GetName()

std::string ns3::CommandLine::GetName ( ) const

Get the program name.

Returns
The program name. Only valid after calling Parse()

Definition at line 183 of file command-line.cc.

References m_shortName.

◆ GetNExtraNonOptions()

std::size_t ns3::CommandLine::GetNExtraNonOptions ( ) const

Get the total number of non-option arguments found, including those configured with AddNonOption() and extra non-option arguments.

This is only valid after calling Parse().

Returns
the number of non-option arguments found.

Definition at line 823 of file command-line.cc.

References m_NNonOptions, and m_nonOptions.

◆ GetOptionName()

CommandLine::HasOptionName ns3::CommandLine::GetOptionName ( const std::string &  param) const
private

Strip leading -- or - from options.

Parameters
[in]paramOption name to search
Returns
false if none found, indicating this is a non-option.

Definition at line 231 of file command-line.cc.

Referenced by HandleHardOptions(), and HandleOption().

+ Here is the caller graph for this function:

◆ GetVersion()

std::string ns3::CommandLine::GetVersion ( ) const

Get the program version.

Returns
The program version

Definition at line 445 of file command-line.cc.

References ns3::Version::LongVersion().

Referenced by PrintVersion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleArgument()

bool ns3::CommandLine::HandleArgument ( const std::string &  name,
const std::string &  value 
) const
private

Match name against the program or general arguments, and dispatch to the appropriate handler.

Parameters
[in]nameThe argument name
[in]valueThe command line value
Returns
true if the argument was handled successfully

Definition at line 688 of file command-line.cc.

References HandleAttribute(), m_options, NS_LOG_DEBUG, NS_LOG_FUNCTION, and PrintHelp().

Referenced by HandleOption().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleAttribute()

bool ns3::CommandLine::HandleAttribute ( const std::string &  name,
const std::string &  value 
)
staticprivate

Callback function to handle attributes.

Parameters
[in]nameThe full name of the Attribute.
[in]valueThe value to assign to name.
Returns
true if the value was set successfully, false otherwise.

Definition at line 837 of file command-line.cc.

References ns3::Config::SetDefaultFailSafe(), and ns3::Config::SetGlobalFailSafe().

Referenced by AddValue(), and HandleArgument().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleHardOptions()

void ns3::CommandLine::HandleHardOptions ( const std::vector< std::string > &  args) const
private

Handle hard-coded options.

Note
: if any hard-coded options are found this function exits.
Parameters
[in]argsVector of hard-coded options to handle.

Definition at line 273 of file command-line.cc.

References check-style-clang-format::args, GetOptionName(), NS_LOG_FUNCTION, PrintAttributes(), PrintGlobals(), PrintGroup(), PrintGroups(), PrintHelp(), PrintTypeIds(), and PrintVersion().

Referenced by Parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleNonOption()

bool ns3::CommandLine::HandleNonOption ( const std::string &  value)
private

Handle a non-option.

Parameters
[in]valueThe command line non-option value.
Returns
true if value could be parsed correctly.

Definition at line 346 of file command-line.cc.

References m_nonOptionCount, m_nonOptions, NS_LOG_FUNCTION, NS_LOG_LOGIC, and PrintHelp().

Referenced by Parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HandleOption()

bool ns3::CommandLine::HandleOption ( const std::string &  param) const
private

Handle an option in the form param=value.

Parameters
[in]paramThe option string.
Returns
true if this was really an option.

Definition at line 332 of file command-line.cc.

References GetOptionName(), and HandleArgument().

Referenced by Parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

CommandLine & ns3::CommandLine::operator= ( const CommandLine cmd)

Assignment.

Parameters
[in]cmdThe CommandLine to assign from
Returns
The CommandLine

Definition at line 137 of file command-line.cc.

References Clear(), second::cmd, and Copy().

+ Here is the call graph for this function:

◆ Parse() [1/2]

void ns3::CommandLine::Parse ( int  argc,
char *  argv[] 
)

Parse the program arguments.

Parameters
[in]argcThe 'argc' variable: number of arguments (including the main program name as first element).
[in]argvThe 'argv' variable: a null-terminated array of strings, each of which identifies a command-line argument.

Obviously, this method will parse the input command-line arguments and will attempt to handle them all.

As a side effect, this method saves the program basename, which can be retrieved by GetName().

Definition at line 375 of file command-line.cc.

References check-style-clang-format::args, and NS_LOG_FUNCTION.

◆ Parse() [2/2]

void ns3::CommandLine::Parse ( std::vector< std::string >  args)

Parse the program arguments.

This version may be convenient when synthesizing arguments programmatically. Other than the type of argument this behaves identically to Parse(int, char *)

Parameters
[in]argsThe vector of arguments.

Definition at line 194 of file command-line.cc.

References check-style-clang-format::args, ns3::Singleton< DesMetrics >::Get(), HandleHardOptions(), HandleNonOption(), HandleOption(), ns3::DesMetrics::Initialize(), m_nonOptionCount, NS_ASSERT_MSG, NS_LOG_FUNCTION, and PrintDoxygenUsage().

+ Here is the call graph for this function:

◆ PrintAttributeList()

void ns3::CommandLine::PrintAttributeList ( std::ostream &  os,
const TypeId  tid,
std::stringstream &  header 
) const
private

Print the Attributes for a single type.

Parameters
[in,out]osthe output stream.
[in]tidThe TypeId whose Attributes should be displayed,
[in]headerA header line to print if tid has Attributes

Definition at line 559 of file command-line.cc.

References ns3::TypeId::AttributeInformation::checker, ns3::TypeId::GetAttribute(), ns3::TypeId::GetAttributeFullName(), ns3::TypeId::GetAttributeN(), ns3::TypeId::AttributeInformation::help, ns3::TypeId::AttributeInformation::initialValue, and NS_LOG_FUNCTION.

Referenced by PrintAttributes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintAttributes()

void ns3::CommandLine::PrintAttributes ( std::ostream &  os,
const std::string &  type 
) const
private

Handler for --PrintAttributes: print the attributes for a given type as well as its parents.

Parameters
[in,out]osthe output stream.
[in]typeThe type name whose Attributes should be displayed,

Definition at line 588 of file command-line.cc.

References ns3::TypeId::GetName(), ns3::TypeId::GetParent(), ns3::TypeId::LookupByNameFailSafe(), NS_FATAL_ERROR, NS_LOG_FUNCTION, PrintAttributeList(), and check-style-clang-format::type.

Referenced by HandleHardOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintDoxygenUsage()

void ns3::CommandLine::PrintDoxygenUsage ( ) const
private

Append usage message in Doxygen format to the file indicated by the NS_COMMANDLINE_INTROSPECTION environment variable.

This is typically only called once, by Parse().

Definition at line 462 of file command-line.cc.

References ns3::SystemPath::Append(), anonymous_namespace{command-line.cc}::Encode(), ns3::EnvironmentVariable::Get(), m_NNonOptions, m_nonOptions, m_options, m_shortName, m_usage, NS_FATAL_ERROR, NS_LOG_FUNCTION, and NS_LOG_INFO.

Referenced by Parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintGlobals()

void ns3::CommandLine::PrintGlobals ( std::ostream &  os) const
private

Handler for --PrintGlobals: print all global variables and values.

Parameters
[in,out]osThe output stream to print on.

Definition at line 531 of file command-line.cc.

References ns3::GlobalValue::Begin(), ns3::GlobalValue::End(), ns3::StringValue::Get(), and NS_LOG_FUNCTION.

Referenced by HandleHardOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintGroup()

void ns3::CommandLine::PrintGroup ( std::ostream &  os,
const std::string &  group 
) const
private

Handler for --PrintGroup: print all types belonging to a given group.

Parameters
[in,out]osThe output stream.
[in]groupThe name of the TypeId group to display

Definition at line 618 of file command-line.cc.

References ns3::TypeId::GetGroupName(), ns3::TypeId::GetName(), ns3::TypeId::GetRegistered(), ns3::TypeId::GetRegisteredN(), and NS_LOG_FUNCTION.

Referenced by HandleHardOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintGroups()

void ns3::CommandLine::PrintGroups ( std::ostream &  os) const
private

Handler for --PrintGroups: print all TypeId group names.

Parameters
[in,out]osThe output stream.

Definition at line 668 of file command-line.cc.

References ns3::TypeId::GetGroupName(), ns3::TypeId::GetRegistered(), ns3::TypeId::GetRegisteredN(), and NS_LOG_FUNCTION.

Referenced by HandleHardOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintHelp()

void ns3::CommandLine::PrintHelp ( std::ostream &  os) const

Print program usage to the desired output stream.

Handler for --PrintHelp and --help: print Usage(), argument names, and help strings

Alternatively, an overloaded operator << can be used:

CommandLine cmd (__FILE__);
cmd.Parse (argc, argv);
...
std::cerr << cmd;
Parameters
[in,out]osThe output stream to print on.

Definition at line 383 of file command-line.cc.

References m_NNonOptions, m_nonOptions, m_options, m_shortName, m_usage, max, and NS_LOG_FUNCTION.

Referenced by HandleArgument(), HandleHardOptions(), and HandleNonOption().

+ Here is the caller graph for this function:

◆ PrintTypeIds()

void ns3::CommandLine::PrintTypeIds ( std::ostream &  os) const
private

Handler for --PrintTypeIds: print all TypeId names.

Parameters
[in,out]osThe output stream.

Definition at line 645 of file command-line.cc.

References ns3::TypeId::GetName(), ns3::TypeId::GetRegistered(), ns3::TypeId::GetRegisteredN(), and NS_LOG_FUNCTION.

Referenced by HandleHardOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintVersion()

void ns3::CommandLine::PrintVersion ( std::ostream &  os) const

Print ns-3 version to the desired output stream.

Handler for --PrintVersion and --version.

Parameters
[in,out]osThe output stream to print on.

Definition at line 456 of file command-line.cc.

References GetVersion().

Referenced by HandleHardOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Usage()

void ns3::CommandLine::Usage ( const std::string &  usage)

Supply the program usage and documentation.

Parameters
[in]usageProgram usage message to write with --help.

Definition at line 177 of file command-line.cc.

References m_usage.

Member Data Documentation

◆ m_NNonOptions

std::size_t ns3::CommandLine::m_NNonOptions
private

The expected number of non-option arguments.

Definition at line 665 of file command-line.h.

Referenced by AddNonOption(), Clear(), Copy(), GetExtraNonOption(), GetNExtraNonOptions(), PrintDoxygenUsage(), and PrintHelp().

◆ m_nonOptionCount

std::size_t ns3::CommandLine::m_nonOptionCount
private

The number of actual non-option arguments seen so far.

Definition at line 667 of file command-line.h.

Referenced by Copy(), HandleNonOption(), and Parse().

◆ m_nonOptions

Items ns3::CommandLine::m_nonOptions
private

The list of non-option arguments.

Definition at line 662 of file command-line.h.

Referenced by AddNonOption(), Clear(), Copy(), GetExtraNonOption(), GetNExtraNonOptions(), HandleNonOption(), PrintDoxygenUsage(), and PrintHelp().

◆ m_options

Items ns3::CommandLine::m_options
private

The list of option arguments.

Definition at line 660 of file command-line.h.

Referenced by AddValue(), Clear(), Copy(), HandleArgument(), PrintDoxygenUsage(), and PrintHelp().

◆ m_shortName

std::string ns3::CommandLine::m_shortName
private

The source file name (without .cc), as would be given to ns3 run

Definition at line 671 of file command-line.h.

Referenced by CommandLine(), Clear(), Copy(), GetName(), PrintDoxygenUsage(), and PrintHelp().

◆ m_usage

std::string ns3::CommandLine::m_usage
private

The Usage string.

Definition at line 669 of file command-line.h.

Referenced by Clear(), Copy(), PrintDoxygenUsage(), PrintHelp(), and Usage().


The documentation for this class was generated from the following files: