Show initial values of arguments; show attribute value.
authorPeter D. Barnes, Jr. <barnes26@llnl.gov>
Mon, 18 Aug 2014 12:36:07 -0700
changeset 10865 23eb0f6c139a
parent 10864 d3887343ddb3
child 10866 e4b913c6fe41
Show initial values of arguments; show attribute value.
src/core/examples/command-line-example.cc
--- a/src/core/examples/command-line-example.cc	Mon Aug 18 12:35:33 2014 -0700
+++ b/src/core/examples/command-line-example.cc	Mon Aug 18 12:36:07 2014 -0700
@@ -28,7 +28,7 @@
 using namespace ns3;
 
 
-std::string g_cbArg="cbArg default";
+std::string g_cbArg = "cbArg default";
 
 bool SetCbArg (std::string val)
 {
@@ -43,6 +43,26 @@
   int         intArg  = 1;
   bool        boolArg = false;
   std::string strArg  = "strArg default";
+  // Attribute path
+  const std::string attrClass = "ns3::RandomVariableStream";
+  const std::string attrName  = "Antithetic";
+  const std::string attrPath  = attrClass + "::" + attrName;
+ 
+  // Cache the initial values.  Normally one wouldn't do this,
+  // but we want to demonstrate that CommandLine has changed them.
+  const int intDef = intArg;
+  const bool boolDef = boolArg;
+  const std::string strDef = strArg;
+  const std::string cbDef  = g_cbArg;
+  // Look up default value for attribute
+  const TypeId tid = TypeId::LookupByName (attrClass);
+  std::string attrDef;
+  {
+    struct TypeId::AttributeInformation info;
+    tid.LookupAttributeByName (attrName, &info);
+    attrDef = info.initialValue->SerializeToString (info.checker);
+  }
+  
   
   CommandLine cmd;
   cmd.Usage ("CommandLine example program.\n"
@@ -51,18 +71,70 @@
   cmd.AddValue ("intArg",  "an int argument",       intArg);
   cmd.AddValue ("boolArg", "a bool argument",       boolArg);
   cmd.AddValue ("strArg",  "a string argument",     strArg);
-  cmd.AddValue ("anti",    "ns3::RandomVariableStream::Antithetic");
+  cmd.AddValue ("anti",    attrPath);
   cmd.AddValue ("cbArg",   "a string via callback", MakeCallback (SetCbArg));
   cmd.Parse (argc, argv);
 
-  std::cout << std::left
-            << std::setw (10) << "intArg:"         << intArg           << std::endl;
-  std::cout << std::setw (10) << "boolArg:"
-            << std::boolalpha                      << boolArg
-            << std::noboolalpha                                        << std::endl;
+  // Show initial values:
+  std::cout << std::endl;
+  std::cout << cmd.GetName () << ":" << std::endl;
+  std::cout << "Initial values:" << std::endl;
+  
+  std::cout << std::left << std::setw (10) << "intArg:"
+            <<                    intDef
+            << std::endl;
+  std::cout << std::setw (10)              << "boolArg:"
+            << std::boolalpha  << boolDef  << std::noboolalpha
+            << std::endl;
+  
+  std::cout << std::setw (10)              << "strArg:"
+            << "\""            << strDef   << "\""
+            << std::endl;
+
+  // Look up new default value for attribute
+  {
+    struct TypeId::AttributeInformation info;
+    tid.LookupAttributeByName (attrName, &info);
   
-  std::cout << std::setw (10) << "strArg:" << "\"" << strArg  << "\""  << std::endl;
-  std::cout << std::setw (10) << "cbArg:"  << "\"" << g_cbArg << "\""  << std::endl;
+    std::cout << std::setw (10)            << "anti:"
+              << "\""
+              << info.initialValue->SerializeToString (info.checker)
+              << "\""
+              << std::endl;
+  }
+  std::cout << std::setw (10)              << "cbArg:"
+            << "\""            << cbDef    << "\""
+            << std::endl;
+  std::cout << std::endl;
+
+
+  // Show final values
+  std::cout << std::left << std::setw (10) << "intArg:"
+            <<                    intArg
+            << std::endl;
+  std::cout << std::setw (10)              << "boolArg:"
+            << std::boolalpha  << boolArg
+            << std::noboolalpha
+            << std::endl;
+  
+  std::cout << std::setw (10)              << "strArg:"
+            << "\""            << strArg   << "\""
+            << std::endl;
+
+  // Look up new default value for attribute
+  {
+    struct TypeId::AttributeInformation info;
+    tid.LookupAttributeByName (attrName, &info);
+  
+    std::cout << std::setw (10)            << "anti:"
+              << "\""
+              << info.initialValue->SerializeToString (info.checker)
+              << "\""
+              << std::endl;
+  }
+  std::cout << std::setw (10)              << "cbArg:"
+            << "\""            << g_cbArg  << "\""
+            << std::endl;
 
   return 0;
 }