From 042d2e38e5432e7da2cc76c224d155e6c4a67427 Mon Sep 17 00:00:00 2001
From: "Peter D. Barnes, Jr."
Date: Tue, 3 Apr 2018 14:49:27 -0700
Subject: [PATCH] core: bug 2901: Add CommandLine::Parse (const
std::vector> args);
---
CHANGES.html | 2 ++
RELEASE_NOTES | 1 +
src/core/model/command-line.cc | 17 ++++++++++++-----
src/core/model/command-line.h | 12 ++++++++++++
4 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/CHANGES.html b/CHANGES.html
index 32943af6c..0388a992a 100644
--- a/CHANGES.html
+++ b/CHANGES.html
@@ -53,6 +53,8 @@ us a note on ns-developers mailing list.
Changes from ns-3.28 to ns-3-dev
New API:
+ Added CommandLine::Parse (const std::vector> args)
+ NS_LOG_FUNCTION can now log the contents of vectors
Changes to existing API:
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 9e3d464c2..0bb081eb3 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -28,6 +28,7 @@ New user-visible features
Bugs fixed
----------
+- Bug 2901 - Add CommandLine::Parse (const std::vector> args)
Known issues
------------
diff --git a/src/core/model/command-line.cc b/src/core/model/command-line.cc
index 7f014be04..2d5c303f2 100644
--- a/src/core/model/command-line.cc
+++ b/src/core/model/command-line.cc
@@ -110,16 +110,15 @@ CommandLine::Item::~Item ()
}
void
-CommandLine::Parse (int argc, char *argv[])
+CommandLine::Parse (std::vector args)
{
- NS_LOG_FUNCTION (this << argc << argv);
+ NS_LOG_FUNCTION (this << args.size () << args);
- m_name = SystemPath::Split (argv[0]).back ();
+ m_name = SystemPath::Split (args[0]).back ();
- for (int iargc = 1; iargc < argc; iargc++)
+ for (auto param : args)
{
// remove "--" or "-" heading.
- std::string param = argv[iargc];
std::string::size_type cur = param.find ("--");
if (cur == 0)
{
@@ -159,6 +158,14 @@ CommandLine::Parse (int argc, char *argv[])
}
+void
+CommandLine::Parse (int argc, char *argv[])
+{
+ NS_LOG_FUNCTION (this << argc);
+ std::vector args (argv, argv + argc);
+ Parse (args);
+}
+
void
CommandLine::PrintHelp (std::ostream &os) const
{
diff --git a/src/core/model/command-line.h b/src/core/model/command-line.h
index cd583de73..a4aee8e52 100644
--- a/src/core/model/command-line.h
+++ b/src/core/model/command-line.h
@@ -23,6 +23,7 @@
#include
#include
#include
+#include
#include "callback.h"
@@ -284,6 +285,17 @@ public:
*/
void Parse (int argc, char *argv[]);
+ /**
+ * Parse the program arguments.
+ *
+ * This version may be convenient when synthesizing arguments
+ * programmatically. Other than the type of argument this behaves
+ * identically to Parse(int, char *)
+ *
+ * \param [in] args The vector of arguments.
+ */
+ void Parse (std::vector args);
+
/**
* Get the program name
*