mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
use unique_ptr in ArgParser
This commit is contained in:
parent
86961b2a80
commit
eb632c529e
@ -41,14 +41,6 @@ void dump_value(std::ostream & out, const std::string & v)
|
||||
out << '"' << v << '"';
|
||||
}
|
||||
|
||||
ArgParser::~ArgParser(void)
|
||||
{
|
||||
for(auto iter = arg_entries.begin(); iter != arg_entries.end(); ++iter)
|
||||
delete (*iter);
|
||||
for(auto iter = optional_arg_entries.begin(); iter != optional_arg_entries.end(); ++iter)
|
||||
delete (*iter);
|
||||
}
|
||||
|
||||
ArgParser & ArgParser::add(const char * optname, const char * description, ArgParserCallBack callback)
|
||||
{
|
||||
return add<char>(optname, nullptr, 0, description, callback, true);
|
||||
@ -66,7 +58,7 @@ void ArgParser::parse(int argc, char ** argv) const
|
||||
|
||||
for(auto iter = arg_entries.begin(); iter != arg_entries.end(); ++iter)
|
||||
{
|
||||
const ArgEntryBase * p = *iter;
|
||||
const auto * p = iter->get();
|
||||
if(p->shortname != 0)
|
||||
{
|
||||
optstring.push_back(p->shortname);
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
#ifndef nullptr
|
||||
#define nullptr (NULL)
|
||||
@ -42,8 +43,6 @@ extern void dump_value(std::ostream & out, const std::string & v);
|
||||
class ArgParser
|
||||
{
|
||||
public:
|
||||
~ArgParser(void);
|
||||
|
||||
typedef void (*ArgParserCallBack) (const char * arg);
|
||||
|
||||
/*
|
||||
@ -100,7 +99,7 @@ class ArgParser
|
||||
bool dont_show_default;
|
||||
};
|
||||
|
||||
std::vector<ArgEntryBase *> arg_entries, optional_arg_entries;
|
||||
std::vector<std::unique_ptr<ArgEntryBase>> arg_entries, optional_arg_entries;
|
||||
static const int arg_col_width;
|
||||
};
|
||||
|
||||
@ -111,11 +110,11 @@ ArgParser & ArgParser::add(const char * optname, T * location, const Tv & defaul
|
||||
if((!optname) || (!optname[0]))
|
||||
{
|
||||
// when optname is nullptr or "", it's optional, and description is dropped
|
||||
optional_arg_entries.push_back(new ArgEntry<T, Tv>("", location, default_value, callback, "", dont_show_default));
|
||||
optional_arg_entries.emplace_back(new ArgEntry<T, Tv>("", location, default_value, callback, "", dont_show_default));
|
||||
}
|
||||
else
|
||||
{
|
||||
arg_entries.push_back(new ArgEntry<T, Tv>(optname, location, default_value, callback, (description ? description : ""), dont_show_default));
|
||||
arg_entries.emplace_back(new ArgEntry<T, Tv>(optname, location, default_value, callback, (description ? description : ""), dont_show_default));
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
Loading…
Reference in New Issue
Block a user