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",
"second non-option", nonOpt2);
103 cmd.Parse (argc, argv);
106 std::cout << std::endl;
107 std::cout <<
cmd.GetName () <<
":" << std::endl;
110 std::cout <<
"Program Version: ";
111 cmd.PrintVersion (std::cout);
112 std::cout << std::endl;
114 std::cout <<
"Initial values:" << std::endl;
116 std::cout << std::left << std::setw (10) <<
"intArg:"
119 std::cout << std::setw (10) <<
"boolArg:"
120 << std::boolalpha << boolDef << std::noboolalpha
123 std::cout << std::setw (10) <<
"strArg:"
124 <<
"\"" << strDef <<
"\""
126 std::cout << std::setw (10) <<
"anti:"
127 <<
"\"" << attrDef <<
"\""
129 std::cout << std::setw (10) <<
"cbArg:"
130 <<
"\"" << cbDef <<
"\""
132 std::cout << std::left << std::setw (10) <<
"nonOpt1:"
135 std::cout << std::left << std::setw (10) <<
"nonOpt2:"
138 std::cout << std::endl;
142 std::cout <<
"Final values:" << std::endl;
143 std::cout << std::left << std::setw (10) <<
"intArg:"
146 std::cout << std::setw (10) <<
"boolArg:"
147 << std::boolalpha << boolArg << std::noboolalpha
150 std::cout << std::setw (10) <<
"strArg:"
151 <<
"\"" << strArg <<
"\""
159 std::cout << std::setw (10) <<
"anti:"
161 << info.initialValue->SerializeToString (info.checker)
165 std::cout << std::setw (10) <<
"cbArg:"
168 std::cout << std::left << std::setw (10) <<
"nonOpt1:"
171 std::cout << std::left << std::setw (10) <<
"nonOpt2:"
174 std::cout << std::left <<
"Number of extra non-option arguments:"
175 <<
cmd.GetNExtraNonOptions ()
178 for (std::size_t i = 0; i <
cmd.GetNExtraNonOptions (); ++i)
180 std::cout << std::left << std::setw (10) <<
"extra:"
181 <<
"\"" <<
cmd.GetExtraNonOption (i) <<
"\""
Parse command-line arguments.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...