aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-22 14:56:52 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-22 14:56:52 +0000
commit6c6e80837fd76b7b5298b57c7bf6dc62ac4f25d9 (patch)
tree465408a0ad83cf4ff2a7db44c249414fdfeb6982
parente4422395996b9d9f1b7a57a5a058836f1144b8f8 (diff)
downloadpaludis-6c6e80837fd76b7b5298b57c7bf6dc62ac4f25d9.tar.gz
paludis-6c6e80837fd76b7b5298b57c7bf6dc62ac4f25d9.tar.xz
Make it easier to find a named info key
-rw-r--r--paludis/repository.cc19
-rw-r--r--paludis/repository.hh6
2 files changed, 25 insertions, 0 deletions
diff --git a/paludis/repository.cc b/paludis/repository.cc
index 2a72f7d..5e937cc 100644
--- a/paludis/repository.cc
+++ b/paludis/repository.cc
@@ -186,6 +186,16 @@ RepositoryInfoSection::add_kv(const std::string & k, const std::string & v)
return *this;
}
+std::string
+RepositoryInfoSection::get_key_with_default(const std::string & k, const std::string & d) const
+{
+ std::map<std::string, std::string>::const_iterator p(_imp->kvs.find(k));
+ if (p != _imp->kvs.end())
+ return p->second;
+ else
+ return d;
+}
+
std::tr1::shared_ptr<const RepositoryInfo>
Repository::info(bool) const
{
@@ -213,6 +223,15 @@ RepositoryInfo::end_sections() const
return SectionIterator(_imp->sections.end());
}
+std::string
+RepositoryInfo::get_key_with_default(const std::string & k, const std::string & d) const
+{
+ std::string result(d);
+ for (SectionIterator i(begin_sections()), i_end(end_sections()) ; i != i_end ; ++i)
+ result = (*i)->get_key_with_default(k, result);
+ return result;
+}
+
std::tr1::shared_ptr<const CategoryNamePartCollection>
Repository::do_category_names_containing_package(const PackageNamePart & p) const
{
diff --git a/paludis/repository.hh b/paludis/repository.hh
index eeb148e..4b1f24f 100644
--- a/paludis/repository.hh
+++ b/paludis/repository.hh
@@ -130,6 +130,9 @@ namespace paludis
/// Add a key/value pair.
RepositoryInfoSection & add_kv(const std::string &, const std::string &);
+
+ /// Fetch a value, with default.
+ std::string get_key_with_default(const std::string &, const std::string &) const;
};
/**
@@ -166,6 +169,9 @@ namespace paludis
/// Add a section.
RepositoryInfo & add_section(std::tr1::shared_ptr<const RepositoryInfoSection>);
+
+ /// Fetch a value from any of our sections, with default.
+ std::string get_key_with_default(const std::string &, const std::string &) const;
};
/**