25 #include "ns3/core-module.h" 60 int main (
int argc,
char *argv[])
65 std::string strArg =
"strArg default";
67 const std::string attrClass =
"ns3::RandomVariableStream";
68 const std::string attrName =
"Antithetic";
69 const std::string attrPath = attrClass +
"::" + attrName;
76 const int intDef = intArg;
77 const bool boolDef = boolArg;
78 const std::string strDef = strArg;
79 const std::string cbDef =
g_cbArg;
86 attrDef = info.originalInitialValue->SerializeToString (info.checker);
88 const int nonOpt1Def = nonOpt1;
89 const int nonOpt2Def = nonOpt2;
93 cmd.Usage (
"CommandLine example program.\n" 95 "This little program demonstrates how to use CommandLine.");
96 cmd.AddValue (
"intArg",
"an int argument", intArg);
97 cmd.AddValue (
"boolArg",
"a bool argument", boolArg);
98 cmd.AddValue (
"strArg",
"a string argument", strArg);
99 cmd.AddValue (
"anti", attrPath);
101 cmd.AddNonOption (
"nonOpt1",
"first non-option", nonOpt1);
102 cmd.AddNonOption (
"nonOpt2",
"first non-option", nonOpt2);
103 cmd.Parse (argc, argv);
106 std::cout << std::endl;
107 std::cout <<
cmd.GetName () <<
":" << std::endl;
108 std::cout <<
"Initial values:" << std::endl;
110 std::cout << std::left << std::setw (10) <<
"intArg:" 113 std::cout << std::setw (10) <<
"boolArg:" 114 << std::boolalpha << boolDef << std::noboolalpha
117 std::cout << std::setw (10) <<
"strArg:" 118 <<
"\"" << strDef <<
"\"" 120 std::cout << std::setw (10) <<
"anti:" 121 <<
"\"" << attrDef <<
"\"" 123 std::cout << std::setw (10) <<
"cbArg:" 124 <<
"\"" << cbDef <<
"\"" 126 std::cout << std::left << std::setw (10) <<
"nonOpt1:" 129 std::cout << std::left << std::setw (10) <<
"nonOpt2:" 132 std::cout << std::endl;
136 std::cout <<
"Final values:" << std::endl;
137 std::cout << std::left << std::setw (10) <<
"intArg:" 140 std::cout << std::setw (10) <<
"boolArg:" 141 << std::boolalpha << boolArg << std::noboolalpha
144 std::cout << std::setw (10) <<
"strArg:" 145 <<
"\"" << strArg <<
"\"" 153 std::cout << std::setw (10) <<
"anti:" 155 << info.initialValue->SerializeToString (info.checker)
159 std::cout << std::setw (10) <<
"cbArg:" 162 std::cout << std::left << std::setw (10) <<
"nonOpt1:" 165 std::cout << std::left << std::setw (10) <<
"nonOpt2:" 168 std::cout << std::left <<
"Number of extra non-option arguments:" 169 <<
cmd.GetNExtraNonOptions ()
172 for (std::size_t i = 0; i <
cmd.GetNExtraNonOptions (); ++i)
174 std::cout << std::left << std::setw (10) <<
"extra:" 175 <<
"\"" <<
cmd.GetExtraNonOption (i) <<
"\""
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Parse command-line arguments.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool SetCbArg(std::string val)
Function to illustrate command line arguments handled by a Callback function.
std::string g_cbArg
Global variable to illustrate command line arguments handled by a Callback function.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.