core: bug 2901: Add CommandLine::Parse (const std::vector<std::string>> args);

This commit is contained in:
Peter D. Barnes, Jr.
2018-04-03 14:49:27 -07:00
parent 975a287288
commit 042d2e38e5
4 changed files with 27 additions and 5 deletions

View File

@@ -53,6 +53,8 @@ us a note on ns-developers mailing list.</p>
<hr>
<h1>Changes from ns-3.28 to ns-3-dev</h1>
<h2>New API:</h2>
<li> Added CommandLine::Parse (const std::vector<std::string>> args) </li>
<li> NS_LOG_FUNCTION can now log the contents of vectors </li>
<ul>
</ul>
<h2>Changes to existing API:</h2>

View File

@@ -28,6 +28,7 @@ New user-visible features
Bugs fixed
----------
- Bug 2901 - Add CommandLine::Parse (const std::vector<std::string>> args)
Known issues
------------

View File

@@ -110,16 +110,15 @@ CommandLine::Item::~Item ()
}
void
CommandLine::Parse (int argc, char *argv[])
CommandLine::Parse (std::vector<std::string> 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<std::string> args (argv, argv + argc);
Parse (args);
}
void
CommandLine::PrintHelp (std::ostream &os) const
{

View File

@@ -23,6 +23,7 @@
#include <string>
#include <sstream>
#include <list>
#include <vector>
#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<std::string> args);
/**
* Get the program name
*