aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-23 01:31:25 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-08-23 01:31:25 +0000
commit80aa5f9203c94bc0c5d399e411323c01b77ad4d3 (patch)
treeaff0deaaab0cd83711face29e5617aa730934cb2
parent9a285f35db8ec2d94dd50ae96f30731792f7a4ec (diff)
downloadpaludis-80aa5f9203c94bc0c5d399e411323c01b77ad4d3.tar.gz
paludis-80aa5f9203c94bc0c5d399e411323c01b77ad4d3.tar.xz
Provide default implementations for most Environment virtual functions, to reduce the amount of boilerplate code for special Environment implementations.
-rw-r--r--paludis/environment.cc75
-rw-r--r--paludis/environment.hh46
2 files changed, 110 insertions, 11 deletions
diff --git a/paludis/environment.cc b/paludis/environment.cc
index 1ff1a54..7934efe 100644
--- a/paludis/environment.cc
+++ b/paludis/environment.cc
@@ -23,6 +23,7 @@
#include <paludis/util/log.hh>
#include <paludis/util/save.hh>
#include <paludis/util/tokeniser.hh>
+#include <paludis/util/collection_concrete.hh>
#include <set>
#include <list>
@@ -378,3 +379,77 @@ Hook::operator() (const std::string & k, const std::string & v) const
return result;
}
+bool
+Environment::query_use(const UseFlagName &, const PackageDatabaseEntry *) const
+{
+ return false;
+}
+
+UseFlagNameCollection::Pointer
+Environment::query_enabled_use_matching(const std::string &, const PackageDatabaseEntry *) const
+{
+ return UseFlagNameCollection::Pointer(new UseFlagNameCollection::Concrete);
+}
+
+bool
+Environment::accept_keyword(const KeywordName & keyword, const PackageDatabaseEntry * const) const
+{
+ if (keyword == KeywordName("*"))
+ return true;
+
+ return false;
+}
+
+bool
+Environment::accept_license(const std::string &, const PackageDatabaseEntry * const) const
+{
+ return false;
+}
+
+bool
+Environment::query_user_masks(const PackageDatabaseEntry &) const
+{
+ return false;
+}
+
+bool
+Environment::query_user_unmasks(const PackageDatabaseEntry &) const
+{
+ return false;
+}
+
+std::string
+Environment::bashrc_files() const
+{
+ return "";
+}
+
+
+std::string
+Environment::hook_dirs() const
+{
+ return "";
+}
+
+namespace
+{
+ static const std::multimap<std::string, std::string> environment_mirrors;
+}
+
+Environment::MirrorIterator
+Environment::begin_mirrors(const std::string &) const
+{
+ return MirrorIterator(environment_mirrors.begin());
+}
+
+Environment::MirrorIterator
+Environment::end_mirrors(const std::string &) const
+{
+ return MirrorIterator(environment_mirrors.end());
+}
+
+void
+Environment::perform_hook(const Hook &) const
+{
+}
+
diff --git a/paludis/environment.hh b/paludis/environment.hh
index b91d500..16aeef9 100644
--- a/paludis/environment.hh
+++ b/paludis/environment.hh
@@ -124,25 +124,33 @@ namespace paludis
/**
* Does the user want the specified USE flag set for a
* particular package?
+ *
+ * Default behaviour: all USE flags turned off.
*/
- virtual bool query_use(const UseFlagName &, const PackageDatabaseEntry *) const = 0;
+ virtual bool query_use(const UseFlagName &, const PackageDatabaseEntry *) const;
/**
* Fetch a list of enabled USE flags that start with a given prefix,
* for USE_EXPAND.
+ *
+ * Default behaviour: no USE flags.
*/
virtual UseFlagNameCollection::Pointer query_enabled_use_matching(
- const std::string & prefix, const PackageDatabaseEntry *) const = 0;
+ const std::string & prefix, const PackageDatabaseEntry *) const;
/**
* Is the specified KEYWORD accepted?
+ *
+ * Default behaviour: only "*" accepted.
*/
- virtual bool accept_keyword(const KeywordName &, const PackageDatabaseEntry * const) const = 0;
+ virtual bool accept_keyword(const KeywordName &, const PackageDatabaseEntry * const) const;
/**
* Is the specified LICENSE accepted?
+ *
+ * Default behaviour: no.
*/
- virtual bool accept_license(const std::string &, const PackageDatabaseEntry * const) const = 0;
+ virtual bool accept_license(const std::string &, const PackageDatabaseEntry * const) const;
/**
* Fetch the masks for a particular package.
@@ -151,13 +159,17 @@ namespace paludis
/**
* Are there any user masks on a package?
+ *
+ * Default behaviour: no.
*/
- virtual bool query_user_masks(const PackageDatabaseEntry &) const = 0;
+ virtual bool query_user_masks(const PackageDatabaseEntry &) const;
/**
* Are there any user unmasks on a package?
+ *
+ * Default behaviour: no.
*/
- virtual bool query_user_unmasks(const PackageDatabaseEntry &) const = 0;
+ virtual bool query_user_unmasks(const PackageDatabaseEntry &) const;
/**
* Fetch our package database.
@@ -169,13 +181,17 @@ namespace paludis
/**
* Our bashrc files.
+ *
+ * Default behaviour: none.
*/
- virtual std::string bashrc_files() const = 0;
+ virtual std::string bashrc_files() const;
/**
* Our hook directories.
+ *
+ * Default behaviour: none.
*/
- virtual std::string hook_dirs() const = 0;
+ virtual std::string hook_dirs() const;
/**
* How to run paludis.
@@ -194,13 +210,19 @@ namespace paludis
/**
* Iterator to the start of our mirrors.
+ *
+ * Default behaviour: no mirrors. If specialising, also do
+ * Environment::end_mirrors.
*/
- virtual MirrorIterator begin_mirrors(const std::string & mirror) const = 0;
+ virtual MirrorIterator begin_mirrors(const std::string & mirror) const;
/**
* Iterator to past the end of our mirrors.
+ *
+ * Default behaviour: no mirrors. If specialising, also do
+ * Environment::begin_mirrors.
*/
- virtual MirrorIterator end_mirrors(const std::string & mirror) const = 0;
+ virtual MirrorIterator end_mirrors(const std::string & mirror) const;
/**
* Fetch a named package set.
@@ -273,8 +295,10 @@ namespace paludis
/**
* Perform a hook.
+ *
+ * Default behaviour: nothing happens.
*/
- virtual void perform_hook(const Hook & hook) const = 0;
+ virtual void perform_hook(const Hook & hook) const;
};
}