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;
73 const int intDef = intArg;
74 const bool boolDef = boolArg;
75 const std::string strDef = strArg;
76 const std::string cbDef =
g_cbArg;
83 attrDef = info.originalInitialValue->SerializeToString (info.checker);
88 cmd.
Usage (
"CommandLine example program.\n"
90 "This little program demonstrates how to use CommandLine.");
91 cmd.
AddValue (
"intArg",
"an int argument", intArg);
92 cmd.
AddValue (
"boolArg",
"a bool argument", boolArg);
93 cmd.
AddValue (
"strArg",
"a string argument", strArg);
96 cmd.
Parse (argc, argv);
99 std::cout << std::endl;
100 std::cout << cmd.
GetName () <<
":" << std::endl;
101 std::cout <<
"Initial values:" << std::endl;
103 std::cout << std::left << std::setw (10) <<
"intArg:"
106 std::cout << std::setw (10) <<
"boolArg:"
107 << std::boolalpha << boolDef << std::noboolalpha
110 std::cout << std::setw (10) <<
"strArg:"
111 <<
"\"" << strDef <<
"\""
113 std::cout << std::setw (10) <<
"anti:"
114 <<
"\"" << attrDef <<
"\""
116 std::cout << std::setw (10) <<
"cbArg:"
117 <<
"\"" << cbDef <<
"\""
119 std::cout << std::endl;
123 std::cout <<
"Final values:" << std::endl;
124 std::cout << std::left << std::setw (10) <<
"intArg:"
127 std::cout << std::setw (10) <<
"boolArg:"
128 << std::boolalpha << boolArg
132 std::cout << std::setw (10) <<
"strArg:"
133 <<
"\"" << strArg <<
"\""
141 std::cout << std::setw (10) <<
"anti:"
143 << info.initialValue->SerializeToString (info.checker)
147 std::cout << std::setw (10) <<
"cbArg:"
std::string GetName() const
Get the program name.
void Usage(const std::string usage)
Supply the program usage and documentation.
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 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.
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
std::string g_cbArg
Global variable to illustrate command line arguments handled by a Callback function.
void Parse(int argc, char *argv[])
Parse the program arguments.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.