parse command-line argumentsInstances of this class can be used to parse command-line arguments: users can register new arguments with CommandLine::AddValue but the most important functionality provided by this class is that it can be used to set the 'initial value' of every attribute in the system with the --TypeIdNameAttributeName=value syntax and it can be used to set the value of every GlobalValue in the system with the --GlobalValueName=value syntax. More...
#include <command-line.h>
Classes | |
class | CallbackItem |
class | Item |
class | UserItem |
Public Member Functions | |
~CommandLine () | |
template<typename T > | |
void | AddValue (const std::string &name, const std::string &help, T &value) |
void | AddValue (const std::string &name, const std::string &help, Callback< bool, std::string > callback) |
void | Parse (int argc, char *argv[]) const |
Private Types | |
typedef std::list< Item * > | Items |
Private Member Functions | |
void | HandleArgument (std::string name, std::string value) const |
void | PrintHelp (void) const |
void | PrintGlobals (void) const |
void | PrintAttributes (std::string type) const |
void | PrintGroup (std::string group) const |
void | PrintTypeIds (void) const |
void | PrintGroups (void) const |
Private Attributes | |
Items | m_items |
parse command-line arguments
Instances of this class can be used to parse command-line arguments: users can register new arguments with CommandLine::AddValue but the most important functionality provided by this class is that it can be used to set the 'initial value' of every attribute in the system with the --TypeIdNameAttributeName=value syntax and it can be used to set the value of every GlobalValue in the system with the --GlobalValueName=value syntax.
Definition at line 44 of file command-line.h.
typedef std::list<Item *> ns3::CommandLine::Items [private] |
Definition at line 113 of file command-line.h.
ns3::CommandLine::~CommandLine | ( | ) |
Definition at line 32 of file command-line.cc.
References m_items.
void ns3::CommandLine::AddValue | ( | const std::string & | name, | |
const std::string & | help, | |||
Callback< bool, std::string > | callback | |||
) |
name | the name of the user-supplied argument | |
help | some help text used by --PrintHelp | |
callback | a callback function that will be invoked to parse and collect the value. This normally used by language bindings. |
Definition at line 264 of file command-line.cc.
References ns3::CommandLine::CallbackItem::m_callback, ns3::CommandLine::Item::m_help, m_items, ns3::CommandLine::Item::m_name, and NS_LOG_FUNCTION.
void ns3::CommandLine::AddValue | ( | const std::string & | name, | |
const std::string & | help, | |||
T & | value | |||
) | [inline] |
name | the name of the user-supplied argument | |
help | some help text used by --PrintHelp | |
value | a reference to the variable where the value parsed will be stored (if no value is parsed, this variable is not modified). |
Definition at line 123 of file command-line.h.
References ns3::CommandLine::Item::m_help, m_items, ns3::CommandLine::Item::m_name, and ns3::CommandLine::UserItem< T >::m_valuePtr.
Referenced by PrintPsrVsCollisionInterval(), and CommandLineTest::RunTests().
void ns3::CommandLine::HandleArgument | ( | std::string | name, | |
std::string | value | |||
) | const [private] |
Definition at line 200 of file command-line.cc.
References m_items, NS_LOG_DEBUG, PrintAttributes(), PrintGlobals(), PrintGroup(), PrintGroups(), PrintHelp(), PrintTypeIds(), ns3::Config::SetDefaultFailSafe(), and ns3::Config::SetGlobalFailSafe().
Referenced by Parse().
void ns3::CommandLine::Parse | ( | int | argc, | |
char * | argv[] | |||
) | const |
argc | the 'argc' variable: number of arguments (including the main program name as first element). | |
argv | the '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.
Definition at line 45 of file command-line.cc.
References HandleArgument().
Referenced by CommandLineTest::Parse().
void ns3::CommandLine::PrintAttributes | ( | std::string | type | ) | const [private] |
Definition at line 122 of file command-line.cc.
References ns3::TypeId::GetAttributeChecker(), ns3::TypeId::GetAttributeFullName(), ns3::TypeId::GetAttributeHelp(), ns3::TypeId::GetAttributeInitialValue(), ns3::TypeId::GetAttributeN(), ns3::TypeId::LookupByNameFailSafe(), and NS_FATAL_ERROR.
Referenced by HandleArgument().
void ns3::CommandLine::PrintGlobals | ( | void | ) | const [private] |
Definition at line 107 of file command-line.cc.
References ns3::GlobalValue::Begin(), ns3::GlobalValue::End(), and ns3::StringValue::Get().
Referenced by HandleArgument().
void ns3::CommandLine::PrintGroup | ( | std::string | group | ) | const [private] |
Definition at line 142 of file command-line.cc.
References ns3::TypeId::GetGroupName(), ns3::TypeId::GetName(), ns3::TypeId::GetRegistered(), and ns3::TypeId::GetRegisteredN().
Referenced by HandleArgument().
void ns3::CommandLine::PrintGroups | ( | void | ) | const [private] |
Definition at line 167 of file command-line.cc.
References ns3::TypeId::GetGroupName(), ns3::TypeId::GetRegistered(), and ns3::TypeId::GetRegisteredN().
Referenced by HandleArgument().
void ns3::CommandLine::PrintHelp | ( | void | ) | const [private] |
void ns3::CommandLine::PrintTypeIds | ( | void | ) | const [private] |
Definition at line 156 of file command-line.cc.
References ns3::TypeId::GetName(), ns3::TypeId::GetRegistered(), and ns3::TypeId::GetRegisteredN().
Referenced by HandleArgument().
Items ns3::CommandLine::m_items [private] |
Definition at line 114 of file command-line.h.
Referenced by AddValue(), HandleArgument(), PrintHelp(), and ~CommandLine().