-
Notifications
You must be signed in to change notification settings - Fork 291
/
xoptions.cpp
41 lines (34 loc) · 1.52 KB
/
xoptions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/***************************************************************************
* Copyright (c) 2016, Johan Mabille, Loic Gouarin and Sylvain Corlay *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#include <sstream>
#include <string>
#include <vector>
#include "xoptions.hpp"
namespace xcpp
{
cxxopts::ParseResult xoptions::parse(const std::string& line)
{
std::istringstream iss(line);
std::vector<std::string> opt_strings((std::istream_iterator<std::string>(iss)),
std::istream_iterator<std::string>());
std::vector<const char*> copt_strings;
for (std::size_t i = 0; i < opt_strings.size(); ++i)
{
copt_strings.push_back(opt_strings[i].c_str());
}
int argc = copt_strings.size();
// Const-casting as cxxopts::parse moved from (int&, const char**&) to
// (int&, char**&) between 2.1.0 and 2.1.1.).
// This should not be required in 2.2.0.
//
// Macros CXXOPTS__VERSION_[MAJOR/MINOR/PATCH] were only defined
// after 2.1.1.]
auto argv = const_cast<char**>(&copt_strings[0]);
return parent::parse(argc, argv);
}
}