aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-16 17:23:28 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-16 17:23:28 +0000
commit516d2cee3d89c65e8acaf815a78b4caff43675bb (patch)
tree2abe029d465d01c669fb27a6e9065c374169f0e3
parentbf42f82637341863181ef31d1b91aac39c5410f9 (diff)
downloadpaludis-516d2cee3d89c65e8acaf815a78b4caff43675bb.tar.gz
paludis-516d2cee3d89c65e8acaf815a78b4caff43675bb.tar.xz
Don't mangle the order of enum arg options when displaying help messages
-rw-r--r--paludis/args/args_option.cc28
-rw-r--r--paludis/args/args_option.hh7
2 files changed, 27 insertions, 8 deletions
diff --git a/paludis/args/args_option.cc b/paludis/args/args_option.cc
index eefc57b..f6ab346 100644
--- a/paludis/args/args_option.cc
+++ b/paludis/args/args_option.cc
@@ -73,12 +73,30 @@ IntegerArg::IntegerArg(ArgsGroup * const group, const std::string& long_name,
{
}
-void EnumArg::set_argument(const std::string & arg)
+namespace
{
- if (_allowed_args.find(arg) == _allowed_args.end())
+ struct ArgIs
{
+ const std::string & arg;
+
+ ArgIs(const std::string & a) :
+ arg(a)
+ {
+ }
+
+ bool operator() (const std::pair<std::string, std::string> & p) const
+ {
+ return p.first == arg;
+ }
+ };
+}
+
+void EnumArg::set_argument(const std::string & arg)
+{
+ if (_allowed_args.end() == std::find_if(_allowed_args.begin(),
+ _allowed_args.end(), ArgIs(arg)))
throw (BadValue("--" + long_name(), arg));
- }
+
_argument = arg;
}
@@ -88,12 +106,12 @@ EnumArg::~EnumArg()
EnumArg::EnumArgOptions::EnumArgOptions(std::string opt, std::string desc)
{
- _options.insert(std::make_pair(opt, desc));
+ _options.push_back(std::make_pair(opt, desc));
}
EnumArg::EnumArgOptions & EnumArg::EnumArgOptions::operator() (std::string opt, std::string desc)
{
- _options.insert(std::make_pair(opt, desc));
+ _options.push_back(std::make_pair(opt, desc));
return *this;
}
diff --git a/paludis/args/args_option.hh b/paludis/args/args_option.hh
index 9a484b9..2e96186 100644
--- a/paludis/args/args_option.hh
+++ b/paludis/args/args_option.hh
@@ -23,6 +23,7 @@
#include <string>
#include <map>
+#include <vector>
#include "args_visitor.hh"
/** \file
@@ -231,7 +232,7 @@ namespace paludis
class EnumArg : public ArgsOption, public Visitable<EnumArg, ArgsVisitorTypes>
{
private:
- const std::map<std::string, std::string> _allowed_args;
+ const std::vector<std::pair<std::string, std::string> > _allowed_args;
std::string _argument;
const std::string _default_arg;
@@ -247,7 +248,7 @@ namespace paludis
{
private:
friend class EnumArg;
- std::map<std::string, std::string> _options;
+ std::vector<std::pair<std::string, std::string> > _options;
public:
/**
@@ -299,7 +300,7 @@ namespace paludis
/**
* Type used to iterate over valid arguments to this option
*/
- typedef std::map<std::string, std::string>::const_iterator AllowedArgIterator;
+ typedef std::vector<std::pair<std::string, std::string> >::const_iterator AllowedArgIterator;
/**
* Returns an iterator pointing to a pair containing the first valid argument,