aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-05-18 23:34:30 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-05-18 23:34:37 +0100
commitdce1c03da9ae2ef9016fd5458d7aa706e2aaee3f (patch)
tree68fa91bd5eab2532f93af497910fa2e5c378c25d
parent233005583dd130e5cc12cafef32a1a57271e2068 (diff)
downloadpaludis-dce1c03da9ae2ef9016fd5458d7aa706e2aaee3f.tar.gz
paludis-dce1c03da9ae2ef9016fd5458d7aa706e2aaee3f.tar.xz
Make choice ctor params use named values
-rw-r--r--paludis/choice-fwd.hh4
-rw-r--r--paludis/choice.cc42
-rw-r--r--paludis/choice.hh37
-rw-r--r--paludis/repositories/e/e_choices_key.cc51
-rw-r--r--paludis/repositories/e/ebuild_id.cc11
-rw-r--r--paludis/repositories/fake/fake_package_id.cc11
-rw-r--r--paludis/repositories/unpackaged/unpackaged_key.cc12
-rw-r--r--paludis/unchoices_key.cc11
8 files changed, 125 insertions, 54 deletions
diff --git a/paludis/choice-fwd.hh b/paludis/choice-fwd.hh
index 1c84602..a8aa233 100644
--- a/paludis/choice-fwd.hh
+++ b/paludis/choice-fwd.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -37,6 +37,8 @@ namespace paludis
class Choice;
class ChoiceValue;
+ class ChoiceParams;
+
struct ChoicePrefixNameValidator;
struct ChoiceNameWithPrefixValidator;
struct UnprefixedChoiceNameValidator;
diff --git a/paludis/choice.cc b/paludis/choice.cc
index 60a32e3..85a4cb1 100644
--- a/paludis/choice.cc
+++ b/paludis/choice.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -204,31 +204,17 @@ namespace paludis
struct Implementation<Choice>
{
std::list<std::tr1::shared_ptr<const ChoiceValue> > values;
- const std::string raw_name;
- const std::string human_name;
- const ChoicePrefixName prefix;
- const bool contains_every_value;
- const bool hidden;
- const bool show_with_no_prefix;
- const bool consider_added_or_changed;
-
- Implementation(const std::string & r, const std::string & h, const ChoicePrefixName & p,
- const bool c, const bool i, const bool s, const bool a) :
- raw_name(r),
- human_name(h),
- prefix(p),
- contains_every_value(c),
- hidden(i),
- show_with_no_prefix(s),
- consider_added_or_changed(a)
+ const ChoiceParams params;
+
+ Implementation(const ChoiceParams & p) :
+ params(p)
{
}
};
}
-Choice::Choice(const std::string & r, const std::string & h, const ChoicePrefixName & p,
- const bool c, const bool i, const bool s, const bool a) :
- PrivateImplementationPattern<Choice>(new Implementation<Choice>(r, h, p, c, i, s, a))
+Choice::Choice(const ChoiceParams & p) :
+ PrivateImplementationPattern<Choice>(new Implementation<Choice>(p))
{
}
@@ -245,43 +231,43 @@ Choice::add(const std::tr1::shared_ptr<const ChoiceValue> & v)
const std::string
Choice::raw_name() const
{
- return _imp->raw_name;
+ return _imp->params.raw_name();
}
const std::string
Choice::human_name() const
{
- return _imp->human_name;
+ return _imp->params.human_name();
}
const bool
Choice::contains_every_value() const
{
- return _imp->contains_every_value;
+ return _imp->params.contains_every_value();
}
const bool
Choice::hidden() const
{
- return _imp->hidden;
+ return _imp->params.hidden();
}
const bool
Choice::show_with_no_prefix() const
{
- return _imp->show_with_no_prefix;
+ return _imp->params.show_with_no_prefix();
}
const bool
Choice::consider_added_or_changed() const
{
- return _imp->consider_added_or_changed;
+ return _imp->params.consider_added_or_changed();
}
const ChoicePrefixName
Choice::prefix() const
{
- return _imp->prefix;
+ return _imp->params.prefix();
}
Choice::ConstIterator
diff --git a/paludis/choice.hh b/paludis/choice.hh
index 22394c4..ce6522c 100644
--- a/paludis/choice.hh
+++ b/paludis/choice.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -25,6 +25,8 @@
#include <paludis/util/wrapped_forward_iterator-fwd.hh>
#include <paludis/util/private_implementation_pattern.hh>
#include <paludis/util/exception.hh>
+#include <paludis/util/named_value.hh>
+#include <paludis/util/validated.hh>
#include <tr1/memory>
#include <string>
@@ -41,6 +43,17 @@
namespace paludis
{
+ namespace n
+ {
+ struct consider_added_or_changed;
+ struct contains_every_value;
+ struct hidden;
+ struct human_name;
+ struct prefix;
+ struct raw_name;
+ struct show_with_no_prefix;
+ }
+
/**
* Thrown if a ChoicePrefixName is given an invalid value.
*
@@ -193,6 +206,23 @@ namespace paludis
};
/**
+ * Named parameters for Choice::Choice.
+ *
+ * \since 0.38
+ * \ingroup g_choices
+ */
+ struct ChoiceParams
+ {
+ NamedValue<n::consider_added_or_changed, bool> consider_added_or_changed;
+ NamedValue<n::contains_every_value, bool> contains_every_value;
+ NamedValue<n::hidden, bool> hidden;
+ NamedValue<n::human_name, std::string> human_name;
+ NamedValue<n::prefix, ChoicePrefixName> prefix;
+ NamedValue<n::raw_name, std::string> raw_name;
+ NamedValue<n::show_with_no_prefix, bool> show_with_no_prefix;
+ };
+
+ /**
* An individual choice in a Choices collection.
*
* Examples of a choice include USE, individual USE_EXPAND values (linguas, video_cards etc)
@@ -208,9 +238,8 @@ namespace paludis
///\name Basic operations
///\{
- Choice(const std::string & raw_name, const std::string & human_name, const ChoicePrefixName & prefix,
- const bool contains_every_value, const bool hidden, const bool show_with_no_prefix,
- const bool consider_added_or_changed);
+ ///\since 0.38
+ Choice(const ChoiceParams &);
~Choice();
///\}
diff --git a/paludis/repositories/e/e_choices_key.cc b/paludis/repositories/e/e_choices_key.cc
index c2ca3e6..b8df449 100644
--- a/paludis/repositories/e/e_choices_key.cc
+++ b/paludis/repositories/e/e_choices_key.cc
@@ -37,6 +37,7 @@
#include <paludis/util/member_iterator-impl.hh>
#include <paludis/util/map.hh>
#include <paludis/util/sequence.hh>
+#include <paludis/util/make_named_values.hh>
#include <paludis/environment.hh>
#include <paludis/stringify_formatter-impl.hh>
@@ -255,14 +256,15 @@ EChoicesKey::value() const
if (! _imp->id->eapi()->supported())
return _imp->value;
- std::tr1::shared_ptr<Choice> use(new Choice(
- _imp->id->eapi()->supported()->ebuild_environment_variables()->env_use(),
- _imp->id->eapi()->supported()->ebuild_environment_variables()->env_use(),
- ChoicePrefixName(""),
- false,
- false,
- true,
- true));
+ std::tr1::shared_ptr<Choice> use(new Choice(make_named_values<ChoiceParams>(
+ value_for<n::consider_added_or_changed>(true),
+ value_for<n::contains_every_value>(false),
+ value_for<n::hidden>(false),
+ value_for<n::human_name>(_imp->id->eapi()->supported()->ebuild_environment_variables()->env_use()),
+ value_for<n::prefix>(ChoicePrefixName("")),
+ value_for<n::raw_name>(_imp->id->eapi()->supported()->ebuild_environment_variables()->env_use()),
+ value_for<n::show_with_no_prefix>(true)
+ )));
_imp->value->add(use);
bool has_fancy_test_flag(false);
@@ -288,8 +290,15 @@ EChoicesKey::value() const
std::string lower_u;
std::transform(u->begin(), u->end(), std::back_inserter(lower_u), &::tolower);
- std::tr1::shared_ptr<Choice> exp(new Choice(stringify(*u), lower_u, ChoicePrefixName(lower_u),
- false, hidden ? hidden->end() != hidden->find(*u) : false, false, true));
+ std::tr1::shared_ptr<Choice> exp(new Choice(make_named_values<ChoiceParams>(
+ value_for<n::consider_added_or_changed>(true),
+ value_for<n::contains_every_value>(false),
+ value_for<n::hidden>(hidden ? hidden->end() != hidden->find(*u) : false),
+ value_for<n::human_name>(lower_u),
+ value_for<n::prefix>(ChoicePrefixName(lower_u)),
+ value_for<n::raw_name>(stringify(*u)),
+ value_for<n::show_with_no_prefix>(false)
+ )));
_imp->value->add(exp);
MyOptionsFinder::Prefixes::iterator p(myoptions.prefixes.find(ChoicePrefixName(lower_u)));
@@ -396,7 +405,15 @@ EChoicesKey::value() const
std::string env_arch(_imp->id->eapi()->supported()->ebuild_environment_variables()->env_arch());
if ((! env_arch.empty()) && _imp->maybe_e_repository)
{
- std::tr1::shared_ptr<Choice> arch(new Choice(env_arch, env_arch, ChoicePrefixName(""), false, true, false, false));
+ std::tr1::shared_ptr<Choice> arch(new Choice(make_named_values<ChoiceParams>(
+ value_for<n::consider_added_or_changed>(false),
+ value_for<n::contains_every_value>(false),
+ value_for<n::hidden>(true),
+ value_for<n::human_name>(env_arch),
+ value_for<n::prefix>(ChoicePrefixName("")),
+ value_for<n::raw_name>(env_arch),
+ value_for<n::show_with_no_prefix>(false)
+ )));
_imp->value->add(arch);
for (Set<UnprefixedChoiceName>::ConstIterator a(_imp->maybe_e_repository->arch_flags()->begin()), a_end(_imp->maybe_e_repository->arch_flags()->end()) ;
@@ -412,9 +429,15 @@ EChoicesKey::value() const
{
std::string lower_u;
std::transform(u->begin(), u->end(), std::back_inserter(lower_u), &::tolower);
- std::tr1::shared_ptr<Choice> exp(new Choice(stringify(*u), lower_u, ChoicePrefixName(lower_u),
- ! _imp->id->eapi()->supported()->ebuild_options()->require_use_expand_in_iuse(),
- hidden ? hidden->end() != hidden->find(*u) : false, false, true));
+ std::tr1::shared_ptr<Choice> exp(new Choice(make_named_values<ChoiceParams>(
+ value_for<n::consider_added_or_changed>(true),
+ value_for<n::contains_every_value>(! _imp->id->eapi()->supported()->ebuild_options()->require_use_expand_in_iuse()),
+ value_for<n::hidden>(hidden ? hidden->end() != hidden->find(*u) : false),
+ value_for<n::human_name>(lower_u),
+ value_for<n::prefix>(ChoicePrefixName(lower_u)),
+ value_for<n::raw_name>(stringify(*u)),
+ value_for<n::show_with_no_prefix>(false)
+ )));
_imp->value->add(exp);
std::set<UnprefixedChoiceName> values;
diff --git a/paludis/repositories/e/ebuild_id.cc b/paludis/repositories/e/ebuild_id.cc
index 1d73f4e..1a3fa0a 100644
--- a/paludis/repositories/e/ebuild_id.cc
+++ b/paludis/repositories/e/ebuild_id.cc
@@ -1305,8 +1305,15 @@ EbuildID::add_build_options(const std::tr1::shared_ptr<Choices> & choices) const
{
if (eapi()->supported())
{
- std::tr1::shared_ptr<Choice> build_options(new Choice(canonical_build_options_raw_name(), canonical_build_options_human_name(),
- canonical_build_options_prefix(), false, false, false, false));
+ std::tr1::shared_ptr<Choice> build_options(new Choice(make_named_values<ChoiceParams>(
+ value_for<n::consider_added_or_changed>(false),
+ value_for<n::contains_every_value>(false),
+ value_for<n::hidden>(false),
+ value_for<n::human_name>(canonical_build_options_human_name()),
+ value_for<n::prefix>(canonical_build_options_prefix()),
+ value_for<n::raw_name>(canonical_build_options_raw_name()),
+ value_for<n::show_with_no_prefix>(false)
+ )));
choices->add(build_options);
bool may_be_unrestricted_test(true), may_be_unrestricted_strip(true);
diff --git a/paludis/repositories/fake/fake_package_id.cc b/paludis/repositories/fake/fake_package_id.cc
index 1969188..5256868 100644
--- a/paludis/repositories/fake/fake_package_id.cc
+++ b/paludis/repositories/fake/fake_package_id.cc
@@ -489,8 +489,15 @@ FakeMetadataChoicesKey::add(const std::string & n, const std::string & v)
{
if (_imp->choices.end() == _imp->choices.find(n))
{
- std::tr1::shared_ptr<Choice> c(new Choice(n.empty() ? "default" : n, n.empty() ? "default" : n, ChoicePrefixName(n),
- false, false, false, false));
+ std::tr1::shared_ptr<Choice> c(new Choice(make_named_values<ChoiceParams>(
+ value_for<n::consider_added_or_changed>(false),
+ value_for<n::contains_every_value>(false),
+ value_for<n::hidden>(false),
+ value_for<n::human_name>(n.empty() ? "default" : n),
+ value_for<n::prefix>(ChoicePrefixName(n)),
+ value_for<n::raw_name>(n.empty() ? "default" : n),
+ value_for<n::show_with_no_prefix>(false)
+ )));
_imp->value->add(c);
_imp->choices.insert(std::make_pair(n, c));
}
diff --git a/paludis/repositories/unpackaged/unpackaged_key.cc b/paludis/repositories/unpackaged/unpackaged_key.cc
index 4086205..7d37d44 100644
--- a/paludis/repositories/unpackaged/unpackaged_key.cc
+++ b/paludis/repositories/unpackaged/unpackaged_key.cc
@@ -27,6 +27,7 @@
#include <paludis/util/validated.hh>
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/set.hh>
+#include <paludis/util/make_named_values.hh>
#include <paludis/choice.hh>
#include <paludis/elike_choices.hh>
#include <tr1/memory>
@@ -163,8 +164,15 @@ UnpackagedChoicesKey::value() const
if (! _imp->value)
{
_imp->value.reset(new Choices);
- std::tr1::shared_ptr<Choice> build_options(new Choice(canonical_build_options_raw_name(), canonical_build_options_human_name(),
- canonical_build_options_prefix(), false, false, false, false));
+ std::tr1::shared_ptr<Choice> build_options(new Choice(make_named_values<ChoiceParams>(
+ value_for<n::consider_added_or_changed>(false),
+ value_for<n::contains_every_value>(false),
+ value_for<n::hidden>(false),
+ value_for<n::human_name>(canonical_build_options_human_name()),
+ value_for<n::prefix>(canonical_build_options_prefix()),
+ value_for<n::raw_name>(canonical_build_options_raw_name()),
+ value_for<n::show_with_no_prefix>(false)
+ )));
build_options->add(make_shared_ptr(new ELikeSplitChoiceValue(_imp->id->shared_from_this(), _imp->env, build_options)));
build_options->add(make_shared_ptr(new ELikeStripChoiceValue(_imp->id->shared_from_this(), _imp->env, build_options)));
_imp->value->add(build_options);
diff --git a/paludis/unchoices_key.cc b/paludis/unchoices_key.cc
index 84b3abb..b7a3832 100644
--- a/paludis/unchoices_key.cc
+++ b/paludis/unchoices_key.cc
@@ -24,6 +24,7 @@
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/set.hh>
#include <paludis/util/sequence.hh>
+#include <paludis/util/make_named_values.hh>
using namespace paludis;
@@ -39,7 +40,15 @@ namespace
UnChoicesKey() :
_value(new Choices)
{
- _value->add(make_shared_ptr(new Choice("Choices", "Choices", ChoicePrefixName(""), true, true, true, false)));
+ _value->add(make_shared_ptr(new Choice(make_named_values<ChoiceParams>(
+ value_for<n::consider_added_or_changed>(false),
+ value_for<n::contains_every_value>(true),
+ value_for<n::hidden>(true),
+ value_for<n::human_name>("Choices"),
+ value_for<n::prefix>(ChoicePrefixName("")),
+ value_for<n::raw_name>("Choices"),
+ value_for<n::show_with_no_prefix>(true)
+ ))));
}
~UnChoicesKey()