diff options
author | 2011-03-07 15:41:33 +0000 | |
---|---|---|
committer | 2011-03-07 15:41:33 +0000 | |
commit | a4c999be67cb412120d12eb2bb051b550f64736f (patch) | |
tree | 150abdfd09d5c24faa51c07605a686f1fc44277e | |
parent | 6282517cdc8b5462ca03724b9386b31604c64dee (diff) | |
download | paludis-a4c999be67cb412120d12eb2bb051b550f64736f.tar.gz paludis-a4c999be67cb412120d12eb2bb051b550f64736f.tar.xz |
Split up a bit
-rw-r--r-- | paludis/repositories/e/Makefile.am | 6 | ||||
-rw-r--r-- | paludis/repositories/e/dep_parser.cc | 244 | ||||
-rw-r--r-- | paludis/repositories/e/dep_parser.hh | 18 | ||||
-rw-r--r-- | paludis/repositories/e/e_key.cc | 1 | ||||
-rw-r--r-- | paludis/repositories/e/parse_dependency_label.cc | 203 | ||||
-rw-r--r-- | paludis/repositories/e/parse_dependency_label.hh | 41 | ||||
-rw-r--r-- | paludis/repositories/e/parse_plain_text_label.cc | 49 | ||||
-rw-r--r-- | paludis/repositories/e/parse_plain_text_label.hh | 37 | ||||
-rw-r--r-- | paludis/repositories/e/parse_uri_label.cc | 94 | ||||
-rw-r--r-- | paludis/repositories/e/parse_uri_label.hh | 37 |
10 files changed, 471 insertions, 259 deletions
diff --git a/paludis/repositories/e/Makefile.am b/paludis/repositories/e/Makefile.am index 6c9aace9e..d644f8e30 100644 --- a/paludis/repositories/e/Makefile.am +++ b/paludis/repositories/e/Makefile.am @@ -78,6 +78,9 @@ noinst_HEADERS = \ metadata_xml.hh \ myoption.hh \ myoptions_requirements_verifier.hh \ + parse_dependency_label.hh \ + parse_plain_text_label.hh \ + parse_uri_label.hh \ pbin_merger.hh \ pipe_command_handler.hh \ profile.hh \ @@ -149,6 +152,9 @@ libpaludiserepository_la_SOURCES = \ metadata_xml.cc \ myoption.cc \ myoptions_requirements_verifier.cc \ + parse_dependency_label.cc \ + parse_plain_text_label.cc \ + parse_uri_label.cc \ pbin_merger.cc \ pipe_command_handler.cc \ profile.cc \ diff --git a/paludis/repositories/e/dep_parser.cc b/paludis/repositories/e/dep_parser.cc index aaf629113..214439749 100644 --- a/paludis/repositories/e/dep_parser.cc +++ b/paludis/repositories/e/dep_parser.cc @@ -18,6 +18,9 @@ */ #include <paludis/repositories/e/dep_parser.hh> +#include <paludis/repositories/e/parse_dependency_label.hh> +#include <paludis/repositories/e/parse_uri_label.hh> +#include <paludis/repositories/e/parse_plain_text_label.hh> #include <paludis/repositories/e/eapi.hh> #include <paludis/util/stringify.hh> #include <paludis/util/options.hh> @@ -792,244 +795,3 @@ paludis::erepository::parse_required_use(const std::string & s, const Environmen return top; } -namespace -{ - typedef std::tuple<std::string, std::string, std::string> URILabelsIndex; - - struct URILabelsStore : - Singleton<URILabelsStore> - { - Mutex mutex; - std::map<URILabelsIndex, std::shared_ptr<URILabel> > store; - - std::shared_ptr<URILabel> make(const std::string & class_name, const std::string & text) - { - if (class_name == "URIMirrorsThenListedLabel") - return std::make_shared<URIMirrorsThenListedLabel>(text); - else if (class_name == "URIMirrorsOnlyLabel") - return std::make_shared<URIMirrorsOnlyLabel>(text); - else if (class_name == "URIListedOnlyLabel") - return std::make_shared<URIListedOnlyLabel>(text); - else if (class_name == "URIListedThenMirrorsLabel") - return std::make_shared<URIListedThenMirrorsLabel>(text); - else if (class_name == "URILocalMirrorsOnlyLabel") - return std::make_shared<URILocalMirrorsOnlyLabel>(text); - else if (class_name == "URIManualOnlyLabel") - return std::make_shared<URIManualOnlyLabel>(text); - else - throw EDepParseError(text, "Label '" + text + "' maps to unknown class '" + class_name + "'"); - } - - std::shared_ptr<URILabel> get(const std::string & eapi_name, const std::string & class_name, const std::string & text) - { - Lock lock(mutex); - URILabelsIndex x{eapi_name, class_name, text}; - - auto i(store.find(x)); - if (i == store.end()) - i = store.insert(std::make_pair(x, make(class_name, text))).first; - return i->second; - } - }; -} - -std::shared_ptr<URILabelsDepSpec> -paludis::erepository::parse_uri_label(const std::string & s, const EAPI & e) -{ - Context context("When parsing label string '" + s + "' using EAPI '" + e.name() + "':"); - - if (s.empty()) - throw EDepParseError(s, "Empty label"); - - std::string c(e.supported()->uri_labels()->class_for_label(s.substr(0, s.length() - 1))); - if (c.empty()) - throw EDepParseError(s, "Unknown label"); - - std::shared_ptr<URILabelsDepSpec> l(std::make_shared<URILabelsDepSpec>()); - l->add_label(URILabelsStore::get_instance()->get(e.name(), c, s.substr(0, s.length() - 1))); - - return l; -} - -std::shared_ptr<PlainTextLabelDepSpec> -paludis::erepository::parse_plain_text_label(const std::string & s) -{ - Context context("When parsing label string '" + s + "':"); - - if (s.empty()) - throw EDepParseError(s, "Empty label"); - - std::string c(s.substr(0, s.length() - 1)); - if (c.empty()) - throw EDepParseError(s, "Unknown label"); - - return std::make_shared<PlainTextLabelDepSpec>(s); -} - -namespace -{ - bool enabled_if_option( - const Environment * const env, - const std::shared_ptr<const PackageID> & id, - const std::string label, - const ChoiceNameWithPrefix n) - { - auto repo(env->package_database()->fetch_repository(id->repository_name())); - if (repo->installed_root_key()) - return false; - - if (! id->choices_key()) - { - Log::get_instance()->message("e.dep_parser.label_enabled.no_choices", ll_warning, lc_context) - << "ID " << *id << " has no choices, so cannot tell whether label '" << label << "' is enabled"; - return false; - } - - const std::shared_ptr<const ChoiceValue> v(id->choices_key()->value()->find_by_name_with_prefix(n)); - if (! v) - { - Log::get_instance()->message("e.dep_parser.label_enabled.no_choice", ll_warning, lc_context) - << "ID " << *id << " has no choice named '" << n << "', so cannot tell whether label '" - << label << "' is enabled"; - return false; - } - - return v->enabled(); - } -} - -namespace -{ - typedef std::tuple<std::string, std::string, std::string> DepLabelsIndex; - - struct EnabledByChoiceTestDependencyLabel : - DependenciesTestLabel - { - std::string label_text; - ChoiceNameWithPrefix choice_name; - - EnabledByChoiceTestDependencyLabel(const std::string & s, const ChoiceNameWithPrefix & p) : - label_text(s), - choice_name(p) - { - } - - virtual bool enabled(const Environment * const env, const std::shared_ptr<const PackageID> & id) const - { - return enabled_if_option(env, id, label_text, choice_name); - } - - virtual const std::string text() const - { - return label_text; - } - }; - - struct DepLabelsStore : - Singleton<DepLabelsStore> - { - Mutex mutex; - std::map<DepLabelsIndex, std::shared_ptr<DependenciesLabel> > store; - - std::shared_ptr<DependenciesLabel> make(const std::string & class_name, const std::string & text) - { - if (class_name == "DependenciesBuildLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesBuildLabelTag> >(text); - else if (class_name == "DependenciesRunLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesRunLabelTag> >(text); - else if (class_name == "DependenciesPostLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesPostLabelTag> >(text); - else if (class_name == "DependenciesInstallLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesInstallLabelTag> >(text); - else if (class_name == "DependenciesCompileAgainstLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesCompileAgainstLabelTag> >(text); - else if (class_name == "DependenciesFetchLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesFetchLabelTag> >(text); - else if (class_name == "DependenciesSuggestionLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesSuggestionLabelTag> >(text); - else if (class_name == "DependenciesRecommendationLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesRecommendationLabelTag> >(text); - else if (class_name == "DependenciesTestLabel") - return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesTestLabelTag> >(text); - else - throw EDepParseError(text, "Label '" + text + "' maps to unknown class '" + class_name + "'"); - } - - std::shared_ptr<DependenciesLabel> make_test(const std::string & class_name, - const ChoiceNameWithPrefix & c, const std::string & text) - { - if (class_name == "DependenciesTestLabel") - return std::make_shared<EnabledByChoiceTestDependencyLabel>(text, c); - else - throw EDepParseError(text, "Label '" + text + "' maps to unknown test label class '" + class_name + "'"); - } - - std::shared_ptr<DependenciesLabel> get(const std::string & eapi_name, const std::string & class_name, const std::string & text) - { - Lock lock(mutex); - DepLabelsIndex x{eapi_name, class_name, text}; - - auto i(store.find(x)); - if (i == store.end()) - i = store.insert(std::make_pair(x, make(class_name, text))).first; - return i->second; - } - - std::shared_ptr<DependenciesLabel> get_test(const std::string & eapi_name, const std::string & class_name, - const ChoiceNameWithPrefix & choice_name, const std::string & text) - { - Lock lock(mutex); - DepLabelsIndex x{eapi_name, class_name, stringify(choice_name) + "/" + text}; - - auto i(store.find(x)); - if (i == store.end()) - i = store.insert(std::make_pair(x, make_test(class_name, choice_name, text))).first; - return i->second; - } - }; -} - -std::shared_ptr<DependenciesLabelsDepSpec> -paludis::erepository::parse_dependency_label( - const Environment * const, - const std::string & s, - const EAPI & e) -{ - Context context("When parsing label string '" + s + "' using EAPI '" + e.name() + "':"); - - if (s.empty()) - throw EDepParseError(s, "Empty label"); - - std::set<std::string> labels; - std::string label(s.substr(0, s.length() - 1)); - tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(label, "+", "", std::inserter(labels, labels.end())); - - std::shared_ptr<DependenciesLabelsDepSpec> l(std::make_shared<DependenciesLabelsDepSpec>()); - - for (std::set<std::string>::iterator it = labels.begin(), it_e = labels.end(); it != it_e; ++it) - { - std::string c(e.supported()->dependency_labels()->class_for_label(*it)), cc; - if (c.empty()) - throw EDepParseError(s, "Unknown label '" + *it + "'"); - - std::string::size_type p(c.find('/')); - if (std::string::npos != p) - { - cc = c.substr(p + 1); - c.erase(p); - } - - if (c == "DependenciesTestLabel") - { - if (cc.empty()) - l->add_label(DepLabelsStore::get_instance()->get(e.name(), c, *it)); - else - l->add_label(DepLabelsStore::get_instance()->get_test(e.name(), c, ChoiceNameWithPrefix(cc), *it)); - } - else - l->add_label(DepLabelsStore::get_instance()->get(e.name(), c, *it)); - } - - return l; -} - diff --git a/paludis/repositories/e/dep_parser.hh b/paludis/repositories/e/dep_parser.hh index 1d7439af4..9df0bf474 100644 --- a/paludis/repositories/e/dep_parser.hh +++ b/paludis/repositories/e/dep_parser.hh @@ -56,14 +56,6 @@ namespace paludis const Environment * const, const EAPI &, const bool is_installed) PALUDIS_VISIBLE; /** - * Parse a dep spec label. - */ - std::shared_ptr<DependenciesLabelsDepSpec> parse_dependency_label( - const Environment * const, - const std::string & s, - const EAPI &) PALUDIS_VISIBLE; - - /** * Parse a provide heirarchy. */ std::shared_ptr<ProvideSpecTree> parse_provide(const std::string & s, @@ -104,16 +96,6 @@ namespace paludis */ std::shared_ptr<LicenseSpecTree> parse_license(const std::string & s, const Environment * const, const EAPI &, const bool is_installed) PALUDIS_VISIBLE; - - /** - * Parse a URI label. - */ - std::shared_ptr<URILabelsDepSpec> parse_uri_label(const std::string & s, const EAPI &) PALUDIS_VISIBLE; - - /** - * Parse a plain text label. - */ - std::shared_ptr<PlainTextLabelDepSpec> parse_plain_text_label(const std::string & s) PALUDIS_VISIBLE; } } diff --git a/paludis/repositories/e/e_key.cc b/paludis/repositories/e/e_key.cc index dbac197a4..b0eebba0f 100644 --- a/paludis/repositories/e/e_key.cc +++ b/paludis/repositories/e/e_key.cc @@ -20,6 +20,7 @@ #include <paludis/repositories/e/e_key.hh> #include <paludis/repositories/e/ebuild_id.hh> #include <paludis/repositories/e/dep_parser.hh> +#include <paludis/repositories/e/parse_uri_label.hh> #include <paludis/repositories/e/eapi.hh> #include <paludis/repositories/e/vdb_contents_tokeniser.hh> #include <paludis/repositories/e/e_repository.hh> diff --git a/paludis/repositories/e/parse_dependency_label.cc b/paludis/repositories/e/parse_dependency_label.cc new file mode 100644 index 000000000..9c55b968b --- /dev/null +++ b/paludis/repositories/e/parse_dependency_label.cc @@ -0,0 +1,203 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/repositories/e/parse_dependency_label.hh> +#include <paludis/repositories/e/dep_parser.hh> +#include <paludis/repositories/e/eapi.hh> +#include <paludis/util/log.hh> +#include <paludis/util/mutex.hh> +#include <paludis/util/tokeniser.hh> +#include <paludis/util/singleton-impl.hh> +#include <paludis/dep_label.hh> +#include <paludis/choice.hh> +#include <paludis/environment.hh> +#include <paludis/package_database.hh> +#include <paludis/package_id.hh> +#include <paludis/metadata_key.hh> +#include <paludis/always_enabled_dependency_label.hh> +#include <map> +#include <set> + +using namespace paludis; +using namespace paludis::erepository; + +namespace +{ + bool enabled_if_option( + const Environment * const env, + const std::shared_ptr<const PackageID> & id, + const std::string label, + const ChoiceNameWithPrefix n) + { + auto repo(env->package_database()->fetch_repository(id->repository_name())); + if (repo->installed_root_key()) + return false; + + if (! id->choices_key()) + { + Log::get_instance()->message("e.dep_parser.label_enabled.no_choices", ll_warning, lc_context) + << "ID " << *id << " has no choices, so cannot tell whether label '" << label << "' is enabled"; + return false; + } + + const std::shared_ptr<const ChoiceValue> v(id->choices_key()->value()->find_by_name_with_prefix(n)); + if (! v) + { + Log::get_instance()->message("e.dep_parser.label_enabled.no_choice", ll_warning, lc_context) + << "ID " << *id << " has no choice named '" << n << "', so cannot tell whether label '" + << label << "' is enabled"; + return false; + } + + return v->enabled(); + } + + typedef std::tuple<std::string, std::string, std::string> DepLabelsIndex; + + struct EnabledByChoiceTestDependencyLabel : + DependenciesTestLabel + { + std::string label_text; + ChoiceNameWithPrefix choice_name; + + EnabledByChoiceTestDependencyLabel(const std::string & s, const ChoiceNameWithPrefix & p) : + label_text(s), + choice_name(p) + { + } + + virtual bool enabled(const Environment * const env, const std::shared_ptr<const PackageID> & id) const + { + return enabled_if_option(env, id, label_text, choice_name); + } + + virtual const std::string text() const + { + return label_text; + } + }; + + struct DepLabelsStore : + Singleton<DepLabelsStore> + { + Mutex mutex; + std::map<DepLabelsIndex, std::shared_ptr<DependenciesLabel> > store; + + std::shared_ptr<DependenciesLabel> make(const std::string & class_name, const std::string & text) + { + if (class_name == "DependenciesBuildLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesBuildLabelTag> >(text); + else if (class_name == "DependenciesRunLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesRunLabelTag> >(text); + else if (class_name == "DependenciesPostLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesPostLabelTag> >(text); + else if (class_name == "DependenciesInstallLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesInstallLabelTag> >(text); + else if (class_name == "DependenciesCompileAgainstLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesCompileAgainstLabelTag> >(text); + else if (class_name == "DependenciesFetchLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesFetchLabelTag> >(text); + else if (class_name == "DependenciesSuggestionLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesSuggestionLabelTag> >(text); + else if (class_name == "DependenciesRecommendationLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesRecommendationLabelTag> >(text); + else if (class_name == "DependenciesTestLabel") + return std::make_shared<AlwaysEnabledDependencyLabel<DependenciesTestLabelTag> >(text); + else + throw EDepParseError(text, "Label '" + text + "' maps to unknown class '" + class_name + "'"); + } + + std::shared_ptr<DependenciesLabel> make_test(const std::string & class_name, + const ChoiceNameWithPrefix & c, const std::string & text) + { + if (class_name == "DependenciesTestLabel") + return std::make_shared<EnabledByChoiceTestDependencyLabel>(text, c); + else + throw EDepParseError(text, "Label '" + text + "' maps to unknown test label class '" + class_name + "'"); + } + + std::shared_ptr<DependenciesLabel> get(const std::string & eapi_name, const std::string & class_name, const std::string & text) + { + Lock lock(mutex); + DepLabelsIndex x{eapi_name, class_name, text}; + + auto i(store.find(x)); + if (i == store.end()) + i = store.insert(std::make_pair(x, make(class_name, text))).first; + return i->second; + } + + std::shared_ptr<DependenciesLabel> get_test(const std::string & eapi_name, const std::string & class_name, + const ChoiceNameWithPrefix & choice_name, const std::string & text) + { + Lock lock(mutex); + DepLabelsIndex x{eapi_name, class_name, stringify(choice_name) + "/" + text}; + + auto i(store.find(x)); + if (i == store.end()) + i = store.insert(std::make_pair(x, make_test(class_name, choice_name, text))).first; + return i->second; + } + }; +} + +std::shared_ptr<DependenciesLabelsDepSpec> +paludis::erepository::parse_dependency_label( + const Environment * const, + const std::string & s, + const EAPI & e) +{ + Context context("When parsing label string '" + s + "' using EAPI '" + e.name() + "':"); + + if (s.empty()) + throw EDepParseError(s, "Empty label"); + + std::set<std::string> labels; + std::string label(s.substr(0, s.length() - 1)); + tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(label, "+", "", std::inserter(labels, labels.end())); + + std::shared_ptr<DependenciesLabelsDepSpec> l(std::make_shared<DependenciesLabelsDepSpec>()); + + for (std::set<std::string>::iterator it = labels.begin(), it_e = labels.end(); it != it_e; ++it) + { + std::string c(e.supported()->dependency_labels()->class_for_label(*it)), cc; + if (c.empty()) + throw EDepParseError(s, "Unknown label '" + *it + "'"); + + std::string::size_type p(c.find('/')); + if (std::string::npos != p) + { + cc = c.substr(p + 1); + c.erase(p); + } + + if (c == "DependenciesTestLabel") + { + if (cc.empty()) + l->add_label(DepLabelsStore::get_instance()->get(e.name(), c, *it)); + else + l->add_label(DepLabelsStore::get_instance()->get_test(e.name(), c, ChoiceNameWithPrefix(cc), *it)); + } + else + l->add_label(DepLabelsStore::get_instance()->get(e.name(), c, *it)); + } + + return l; +} + diff --git a/paludis/repositories/e/parse_dependency_label.hh b/paludis/repositories/e/parse_dependency_label.hh new file mode 100644 index 000000000..08227eb90 --- /dev/null +++ b/paludis/repositories/e/parse_dependency_label.hh @@ -0,0 +1,41 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_PARSE_DEPENDENCY_LABEL_HH +#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_PARSE_DEPENDENCY_LABEL_HH 1 + +#include <paludis/spec_tree-fwd.hh> +#include <paludis/repositories/e/eapi-fwd.hh> +#include <paludis/util/exception.hh> +#include <paludis/environment-fwd.hh> +#include <string> + +namespace paludis +{ + namespace erepository + { + std::shared_ptr<DependenciesLabelsDepSpec> parse_dependency_label( + const Environment * const, + const std::string & s, + const EAPI &) PALUDIS_VISIBLE; + + } +} + +#endif diff --git a/paludis/repositories/e/parse_plain_text_label.cc b/paludis/repositories/e/parse_plain_text_label.cc new file mode 100644 index 000000000..1055e698b --- /dev/null +++ b/paludis/repositories/e/parse_plain_text_label.cc @@ -0,0 +1,49 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/repositories/e/parse_plain_text_label.hh> +#include <paludis/repositories/e/dep_parser.hh> +#include <paludis/repositories/e/eapi.hh> +#include <paludis/util/log.hh> +#include <paludis/util/mutex.hh> +#include <paludis/util/tokeniser.hh> +#include <paludis/util/singleton-impl.hh> +#include <paludis/dep_label.hh> +#include <paludis/dep_spec.hh> +#include <map> +#include <set> + +using namespace paludis; +using namespace paludis::erepository; + +std::shared_ptr<PlainTextLabelDepSpec> +paludis::erepository::parse_plain_text_label(const std::string & s) +{ + Context context("When parsing label string '" + s + "':"); + + if (s.empty()) + throw EDepParseError(s, "Empty label"); + + std::string c(s.substr(0, s.length() - 1)); + if (c.empty()) + throw EDepParseError(s, "Unknown label"); + + return std::make_shared<PlainTextLabelDepSpec>(s); +} + diff --git a/paludis/repositories/e/parse_plain_text_label.hh b/paludis/repositories/e/parse_plain_text_label.hh new file mode 100644 index 000000000..461b70b39 --- /dev/null +++ b/paludis/repositories/e/parse_plain_text_label.hh @@ -0,0 +1,37 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_PARSE_PLAIN_TEXT_LABEL_HH +#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_PARSE_PLAIN_TEXT_LABEL_HH 1 + +#include <paludis/spec_tree-fwd.hh> +#include <paludis/repositories/e/eapi-fwd.hh> +#include <paludis/util/exception.hh> +#include <paludis/environment-fwd.hh> +#include <string> + +namespace paludis +{ + namespace erepository + { + std::shared_ptr<PlainTextLabelDepSpec> parse_plain_text_label(const std::string & s) PALUDIS_VISIBLE; + } +} + +#endif diff --git a/paludis/repositories/e/parse_uri_label.cc b/paludis/repositories/e/parse_uri_label.cc new file mode 100644 index 000000000..4f2ef7bb9 --- /dev/null +++ b/paludis/repositories/e/parse_uri_label.cc @@ -0,0 +1,94 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/repositories/e/parse_uri_label.hh> +#include <paludis/repositories/e/dep_parser.hh> +#include <paludis/repositories/e/eapi.hh> +#include <paludis/util/log.hh> +#include <paludis/util/mutex.hh> +#include <paludis/util/tokeniser.hh> +#include <paludis/util/singleton-impl.hh> +#include <paludis/dep_label.hh> +#include <paludis/dep_spec.hh> +#include <map> +#include <set> + +using namespace paludis; +using namespace paludis::erepository; + +namespace +{ + typedef std::tuple<std::string, std::string, std::string> URILabelsIndex; + + struct URILabelsStore : + Singleton<URILabelsStore> + { + Mutex mutex; + std::map<URILabelsIndex, std::shared_ptr<URILabel> > store; + + std::shared_ptr<URILabel> make(const std::string & class_name, const std::string & text) + { + if (class_name == "URIMirrorsThenListedLabel") + return std::make_shared<URIMirrorsThenListedLabel>(text); + else if (class_name == "URIMirrorsOnlyLabel") + return std::make_shared<URIMirrorsOnlyLabel>(text); + else if (class_name == "URIListedOnlyLabel") + return std::make_shared<URIListedOnlyLabel>(text); + else if (class_name == "URIListedThenMirrorsLabel") + return std::make_shared<URIListedThenMirrorsLabel>(text); + else if (class_name == "URILocalMirrorsOnlyLabel") + return std::make_shared<URILocalMirrorsOnlyLabel>(text); + else if (class_name == "URIManualOnlyLabel") + return std::make_shared<URIManualOnlyLabel>(text); + else + throw EDepParseError(text, "Label '" + text + "' maps to unknown class '" + class_name + "'"); + } + + std::shared_ptr<URILabel> get(const std::string & eapi_name, const std::string & class_name, const std::string & text) + { + Lock lock(mutex); + URILabelsIndex x{eapi_name, class_name, text}; + + auto i(store.find(x)); + if (i == store.end()) + i = store.insert(std::make_pair(x, make(class_name, text))).first; + return i->second; + } + }; +} + +std::shared_ptr<URILabelsDepSpec> +paludis::erepository::parse_uri_label(const std::string & s, const EAPI & e) +{ + Context context("When parsing label string '" + s + "' using EAPI '" + e.name() + "':"); + + if (s.empty()) + throw EDepParseError(s, "Empty label"); + + std::string c(e.supported()->uri_labels()->class_for_label(s.substr(0, s.length() - 1))); + if (c.empty()) + throw EDepParseError(s, "Unknown label"); + + std::shared_ptr<URILabelsDepSpec> l(std::make_shared<URILabelsDepSpec>()); + l->add_label(URILabelsStore::get_instance()->get(e.name(), c, s.substr(0, s.length() - 1))); + + return l; +} + + diff --git a/paludis/repositories/e/parse_uri_label.hh b/paludis/repositories/e/parse_uri_label.hh new file mode 100644 index 000000000..0879413ee --- /dev/null +++ b/paludis/repositories/e/parse_uri_label.hh @@ -0,0 +1,37 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_PARSE_URI_LABEL_HH +#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_PARSE_URI_LABEL_HH 1 + +#include <paludis/spec_tree-fwd.hh> +#include <paludis/repositories/e/eapi-fwd.hh> +#include <paludis/util/exception.hh> +#include <paludis/environment-fwd.hh> +#include <string> + +namespace paludis +{ + namespace erepository + { + std::shared_ptr<URILabelsDepSpec> parse_uri_label(const std::string & s, const EAPI &) PALUDIS_VISIBLE; + } +} + +#endif |