reorganise

This commit is contained in:
Jarryd Beck 2014-10-10 17:29:49 +11:00
parent b4d2bffc15
commit 8c9249a8c6
2 changed files with 79 additions and 23 deletions

View File

@ -62,27 +62,7 @@ OptionAdder::operator()
const auto& s = result[2]; const auto& s = result[2];
const auto& l = result[3]; const auto& l = result[3];
auto option = std::make_shared<OptionDetails>(desc, value); m_options.add_option(s.str(), l.str(), desc, value);
if (s.length() != 0)
{
auto in = m_options.m_options.insert(std::make_pair(s.str(), option));
if (!in.second)
{
throw option_exists_error(s.str());
}
}
if (l.length() != 0)
{
auto in = m_options.m_options.insert(std::make_pair(l, option));
if (!in.second)
{
throw option_exists_error(l.str());
}
}
return *this; return *this;
} }
@ -268,4 +248,48 @@ Options::parse(int& argc, char**& argv)
argc = nextKeep; argc = nextKeep;
} }
void
Options::add_option
(
const std::string& s,
const std::string& l,
const std::string& desc,
std::shared_ptr<const Value> value
)
{
auto option = std::make_shared<OptionDetails>(desc, value);
add_one_option(s, option);
add_one_option(l, option);
//add the help details
}
void
Options::add_one_option
(
const std::string& option,
std::shared_ptr<OptionDetails> details
)
{
auto in = m_options.insert(std::make_pair(option, details));
if (!in.second)
{
throw option_exists_error(option);
}
}
std::string
Options::help() const
{
auto group = m_help.find("");
if (group == m_help.end())
{
return "";
}
return "";
}
} }

View File

@ -286,6 +286,18 @@ namespace cxxopts
int m_count; int m_count;
}; };
class HelpDetails
{
public:
HelpDetails();
private:
std::string m_short;
std::string m_long;
std::string m_description;
bool m_arg;
};
class Options class Options
{ {
public: public:
@ -296,6 +308,15 @@ namespace cxxopts
OptionAdder OptionAdder
add_options(); add_options();
void
add_option
(
const std::string& s,
const std::string& l,
const std::string& desc,
std::shared_ptr<const Value> value
);
int int
count(const std::string& o) const count(const std::string& o) const
{ {
@ -325,8 +346,17 @@ namespace cxxopts
void void
parse_positional(std::string option); parse_positional(std::string option);
std::string
help() const;
private: private:
friend class OptionAdder;
void
add_one_option
(
const std::string& option,
std::shared_ptr<OptionDetails> details
);
bool bool
consume_positional(std::string a); consume_positional(std::string a);
@ -352,9 +382,11 @@ namespace cxxopts
const std::string& name const std::string& name
); );
std::map<std::string, std::shared_ptr<OptionDetails>> m_options; std::map<std::string, std::shared_ptr<OptionDetails>> m_options;
std::string m_positional; std::string m_positional;
//mapping from groups to help options
std::map<std::string, std::vector<HelpDetails>> m_help;
}; };
class OptionAdder class OptionAdder