From 47a985c9cad22d1a76f58db1c556633bab020f4a Mon Sep 17 00:00:00 2001
From: Alexander Afanasyev
Date: Tue, 13 Aug 2013 23:19:31 -0700
Subject: [PATCH] [PATCH] core: Extending public interface of CommandLine class
---
CHANGES.html | 14 ++++++
RELEASE_NOTES | 3 ++
src/core/model/command-line.cc | 92 +++++++++++++++++-----------------
src/core/model/command-line.h | 52 +++++++++++++++----
4 files changed, 105 insertions(+), 56 deletions(-)
diff --git a/CHANGES.html b/CHANGES.html
index c07c05125..4ac3d0926 100644
--- a/CHANGES.html
+++ b/CHANGES.html
@@ -113,6 +113,20 @@ us a note on ns-developers mailing list.
Changed behavior:
+ - Now it is possible to request printing command line arguments to the
+desired output stream using PrintHelp or operator <<
+
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+...
+
+ std::cerr << cmd;
+
+or
+
+ cmd.PrintHelp (std::cerr);
+
+
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index b4ab71995..3744c15fb 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -44,6 +44,8 @@ New user-visible features
- Radvd application have a new Helper. See the updated
examples/ipv6/radvd.cc for an example.
- 11n- It is now possible to create a high throughput (HT) node that used the new 11n data rates and preambles.
+- It is now possible to request printing command line arguments to the
+ desired output stream using PrintHelp or operator <<
Bugs fixed
----------
@@ -75,6 +77,7 @@ Bugs fixed
- Bug 1731 - lte-phy-error-model passes unexpectedly
- Bug 1742 - IPv6 HbH and Dst Extension Header size is not correctly calculated
- Bug 1752 - RadvdInterface m_defaultLifeTime is set to milliseconds instead of seconds
+- Bug 1754 - Missing GIL lock in generated callback destructor
Known issues
------------
diff --git a/src/core/model/command-line.cc b/src/core/model/command-line.cc
index 2a259bac2..58ea1012a 100644
--- a/src/core/model/command-line.cc
+++ b/src/core/model/command-line.cc
@@ -147,17 +147,17 @@ CommandLine::Parse (int iargc, char *argv[])
}
void
-CommandLine::PrintHelp (void) const
+CommandLine::PrintHelp (std::ostream &os) const
{
NS_LOG_FUNCTION (this);
- std::cout << m_name << " [Program Arguments] [General Arguments]"
- << std::endl;
+ os << m_name << " [Program Arguments] [General Arguments]"
+ << std::endl;
if (m_usage.length ())
{
- std::cout << std::endl;
- std::cout << m_usage << std::endl;
+ os << std::endl;
+ os << m_usage << std::endl;
}
if (!m_items.empty ())
@@ -169,25 +169,25 @@ CommandLine::PrintHelp (void) const
}
width += 3;
- std::cout << std::endl;
- std::cout << "Program Arguments:" << std::endl;
+ os << std::endl;
+ os << "Program Arguments:" << std::endl;
for (Items::const_iterator i = m_items.begin (); i != m_items.end (); ++i)
{
- std::cout << " --"
- << std::left << std::setw (width) << ( (*i)->m_name + ":")
- << std::right
- << (*i)->m_help;
+ os << " --"
+ << std::left << std::setw (width) << ( (*i)->m_name + ":")
+ << std::right
+ << (*i)->m_help;
if ( (*i)->HasDefault ())
{
- std::cout << " [" << (*i)->GetDefault () << "]";
- }
- std::cout << std::endl;
- }
+ os << " [" << (*i)->GetDefault () << "]";
+ }
+ os << std::endl;
+}
}
- std::cout << std::endl;
- std::cout
+ os << std::endl;
+ os
<< "General Arguments:\n"
<< " --PrintGlobals: Print the list of globals.\n"
<< " --PrintGroups: Print the list of groups.\n"
@@ -199,80 +199,80 @@ CommandLine::PrintHelp (void) const
}
void
-CommandLine::PrintGlobals (void) const
+CommandLine::PrintGlobals (std::ostream &os) const
{
NS_LOG_FUNCTION (this);
- std::cout << "Global values:" << std::endl;
+ os << "Global values:" << std::endl;
for (GlobalValue::Iterator i = GlobalValue::Begin ();
i != GlobalValue::End ();
++i)
{
- std::cout << " --" << (*i)->GetName () << "=[";
+ os << " --" << (*i)->GetName () << "=[";
Ptr checker = (*i)->GetChecker ();
StringValue v;
(*i)->GetValue (v);
- std::cout << v.Get () << "]" << std::endl;
- std::cout << " " << (*i)->GetHelp () << std::endl;
+ os << v.Get () << "]" << std::endl;
+ os << " " << (*i)->GetHelp () << std::endl;
}
}
void
-CommandLine::PrintAttributes (std::string type) const
+CommandLine::PrintAttributes (std::ostream &os, const std::string &type) const
{
NS_LOG_FUNCTION (this);
TypeId tid;
if (!TypeId::LookupByNameFailSafe (type, &tid))
{
- NS_FATAL_ERROR ("Unknown type=" << type << " in --PrintAttributes");
+ NS_FATAL_ERROR ("Unknown type="<SerializeToString (info.checker) << "]"
+ os << info.initialValue->SerializeToString (info.checker) << "]"
<< std::endl;
- std::cout << " " << info.help << std::endl;
+ os << " " << info.help << std::endl;
}
}
void
-CommandLine::PrintGroup (std::string group) const
+CommandLine::PrintGroup (std::ostream &os, const std::string &group) const
{
NS_LOG_FUNCTION (this);
- std::cout << "TypeIds in group " << group << ":" << std::endl;
+ os << "TypeIds in group " << group << ":" << std::endl;
for (uint32_t i = 0; i < TypeId::GetRegisteredN (); ++i)
{
TypeId tid = TypeId::GetRegistered (i);
if (tid.GetGroupName () == group)
{
- std::cout << " " <::const_iterator k = groups.begin ();
k != groups.end ();
++k)
{
- std::cout << " " << *k << std::endl;
+ os << " " << *k << std::endl;
}
}
void
-CommandLine::HandleArgument (std::string name, std::string value) const
+CommandLine::HandleArgument (const std::string &name, const std::string &value) const
{
NS_LOG_FUNCTION (this << name << value);
- NS_LOG_DEBUG ("Handle arg name=" << name << " value=" << value);
+ NS_LOG_DEBUG ("Handle arg name="<