9#include "ns3/core-module.h"
58#define DefaultFinal(label, defaultValue, finalValue) \
59 std::left << std::setw(20) << label + std::string(":") << std::setw(20) << defaultValue \
63main(
int argc,
char* argv[])
68 std::string strArg =
"strArg default";
71 const std::string attrClass =
"ns3::RandomVariableStream";
72 const std::string attrName =
"Antithetic";
73 const std::string attrPath = attrClass +
"::" + attrName;
76 constexpr int CHARBUF_SIZE = 10;
77 char charbuf[CHARBUF_SIZE] =
"charstar";
85 const int intDef = intArg;
86 const bool boolDef = boolArg;
87 const std::string strDef = strArg;
88 const std::string cbDef =
g_cbArg;
97 const std::string charbufDef{charbuf};
98 const int nonOpt1Def = nonOpt1;
99 const int nonOpt2Def = nonOpt2;
102 cmd.Usage(
"CommandLine example program.\n"
104 "This little program demonstrates how to use CommandLine.");
105 cmd.AddValue(
"intArg",
"an int argument", intArg);
106 cmd.AddValue(
"boolArg",
"a bool argument", boolArg);
107 cmd.AddValue(
"strArg",
"a string argument", strArg);
108 cmd.AddValue(
"anti", attrPath);
110 cmd.AddValue(
"charbuf",
"a char* buffer", charbuf, CHARBUF_SIZE);
111 cmd.AddNonOption(
"nonOpt1",
"first non-option", nonOpt1);
112 cmd.AddNonOption(
"nonOpt2",
"second non-option", nonOpt2);
113 cmd.Parse(argc, argv);
116 std::cout << std::endl;
117 std::cout << cmd.GetName() <<
":" << std::endl;
120 std::cout <<
"Program Version: ";
121 cmd.PrintVersion(std::cout);
122 std::cout << std::endl;
124 std::cout <<
"Argument Initial Value Final Value\n"
125 << std::left << std::boolalpha;
129 (boolDef ?
"true" :
"false"),
130 (boolArg ?
"true" :
"false"))
131 <<
DefaultFinal(
"strArg",
"\"" + strDef +
"\"",
"\"" + strArg +
"\"");
141 std::cout <<
DefaultFinal(
"anti",
"\"" + attrDef +
"\"",
"\"" + antiArg +
"\"")
144 "\"" + charbufDef +
"\"",
145 "\"" + std::string(charbuf) +
"\"")
147 <<
DefaultFinal(
"nonOpt2", nonOpt2Def, nonOpt2) << std::endl;
149 std::cout << std::setw(40)
150 <<
"Number of extra non-option arguments:" << cmd.GetNExtraNonOptions() << std::endl;
152 for (std::size_t i = 0; i < cmd.GetNExtraNonOptions(); ++i)
154 std::cout <<
DefaultFinal(
"extra non-option " + std::to_string(i),
156 "\"" + cmd.GetExtraNonOption(i) +
"\"");
158 std::cout << std::endl;
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, AttributeInformation *info, bool permissive=false) const
Find an Attribute by name, retrieving the associated AttributeInformation.
#define DefaultFinal(label, defaultValue, finalValue)
Print a row containing the name, the default and the final values of an argument.
std::string g_cbArg
Global variable to illustrate command line arguments handled by a Callback function.
bool SetCbArg(const std::string &val)
Function 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, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...