aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-05-16 00:23:28 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-05-16 00:40:11 +0100
commitf8d3ddff29df085db2d96c11fa53c0f462d46746 (patch)
treeb142ba566f49aeebe3d039cd1c27f93033743d81
parent7f486c0c5feb7e99e221c5036bfc9b60124f4a1d (diff)
downloadpaludis-f8d3ddff29df085db2d96c11fa53c0f462d46746.tar.gz
paludis-f8d3ddff29df085db2d96c11fa53c0f462d46746.tar.xz
Add slot filters
-rw-r--r--paludis/filter.cc63
-rw-r--r--paludis/filter.hh14
-rw-r--r--ruby/filter.cc67
3 files changed, 144 insertions, 0 deletions
diff --git a/paludis/filter.cc b/paludis/filter.cc
index 12752a7..60f0853 100644
--- a/paludis/filter.cc
+++ b/paludis/filter.cc
@@ -320,6 +320,59 @@ namespace
return "same slot as " + stringify(*as_id);
}
};
+
+ struct SlotHandler :
+ AllFilterHandlerBase
+ {
+ const SlotName slot;
+
+ SlotHandler(const SlotName & s) :
+ slot(s)
+ {
+ }
+
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ const std::tr1::shared_ptr<const PackageIDSet> & id) const
+ {
+ std::tr1::shared_ptr<PackageIDSet> result(new PackageIDSet);
+
+ for (PackageIDSet::ConstIterator i(id->begin()), i_end(id->end()) ;
+ i != i_end ; ++i)
+ if ((*i)->slot_key() && (*i)->slot_key()->value() == slot)
+ result->insert(*i);
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "slot is " + stringify(slot);
+ }
+ };
+
+ struct NoSlotHandler :
+ AllFilterHandlerBase
+ {
+ virtual std::tr1::shared_ptr<const PackageIDSet> ids(
+ const Environment * const,
+ const std::tr1::shared_ptr<const PackageIDSet> & id) const
+ {
+ std::tr1::shared_ptr<PackageIDSet> result(new PackageIDSet);
+
+ for (PackageIDSet::ConstIterator i(id->begin()), i_end(id->end()) ;
+ i != i_end ; ++i)
+ if (! (*i)->slot_key())
+ result->insert(*i);
+
+ return result;
+ }
+
+ virtual std::string as_string() const
+ {
+ return "has no slot";
+ }
+ };
}
filter::All::All() :
@@ -353,6 +406,16 @@ filter::SameSlot::SameSlot(const std::tr1::shared_ptr<const PackageID> & i) :
{
}
+filter::Slot::Slot(const SlotName & s) :
+ Filter(make_shared_ptr(new SlotHandler(s)))
+{
+}
+
+filter::NoSlot::NoSlot() :
+ Filter(make_shared_ptr(new NoSlotHandler))
+{
+}
+
std::ostream &
paludis::operator<< (std::ostream & s, const Filter & f)
{
diff --git a/paludis/filter.hh b/paludis/filter.hh
index 7f826cf..1078d09 100644
--- a/paludis/filter.hh
+++ b/paludis/filter.hh
@@ -114,6 +114,20 @@ namespace paludis
public:
SameSlot(const std::tr1::shared_ptr<const PackageID> &);
};
+
+ class PALUDIS_VISIBLE Slot :
+ public Filter
+ {
+ public:
+ Slot(const SlotName &);
+ };
+
+ class PALUDIS_VISIBLE NoSlot :
+ public Filter
+ {
+ public:
+ NoSlot();
+ };
}
#ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
diff --git a/ruby/filter.cc b/ruby/filter.cc
index 6a5ff44..3997bb7 100644
--- a/ruby/filter.cc
+++ b/ruby/filter.cc
@@ -32,6 +32,8 @@ namespace
static VALUE c_filter_installed_at_root;
static VALUE c_filter_and;
static VALUE c_filter_same_slot;
+ static VALUE c_filter_slot;
+ static VALUE c_filter_no_slot;
VALUE
filter_init(int, VALUE *, VALUE self)
@@ -182,6 +184,55 @@ namespace
}
}
+ /*
+ * call-seq:
+ * new(slot) -> Filter
+ *
+ * Create a Filter that accepts packages that have a given slot.
+ */
+ VALUE
+ filter_slot_new(VALUE self, VALUE s_v)
+ {
+ Filter * ptr(0);
+ try
+ {
+ SlotName s(std::string(StringValuePtr(s_v)));
+ ptr = new filter::Slot(s);
+ VALUE data(Data_Wrap_Struct(self, 0, &Common<Filter>::free, ptr));
+ rb_obj_call_init(data, 1, &s_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
+ /*
+ * call-seq:
+ * new() -> Filter
+ *
+ * Create a Filter that accepts packages that have no slot.
+ */
+ VALUE
+ filter_no_slot_new(VALUE self_v)
+ {
+ Filter * ptr(0);
+ try
+ {
+ ptr = new filter::NoSlot;
+ VALUE data(Data_Wrap_Struct(self_v, 0, &Common<Filter>::free, ptr));
+ rb_obj_call_init(data, 0, &self_v);
+ return data;
+ }
+ catch (const std::exception & e)
+ {
+ delete ptr;
+ exception_to_ruby_exception(e);
+ }
+ }
+
void do_register_filter()
{
/*
@@ -249,6 +300,22 @@ namespace
*/
c_filter_same_slot = rb_define_class_under(c_filter_module, "SameSlot", c_filter);
rb_define_singleton_method(c_filter_same_slot, "new", RUBY_FUNC_CAST(&filter_same_slot_new), 1);
+
+ /*
+ * Document-class: Paludis::Filter::Slot
+ *
+ * Accept packages that have a particular slot.
+ */
+ c_filter_slot = rb_define_class_under(c_filter_module, "Slot", c_filter);
+ rb_define_singleton_method(c_filter_slot, "new", RUBY_FUNC_CAST(&filter_slot_new), 1);
+
+ /*
+ * Document-class: Paludis::Filter::NoSlot
+ *
+ * Accept packages that have no slot.
+ */
+ c_filter_no_slot = rb_define_class_under(c_filter_module, "NoSlot", c_filter);
+ rb_define_singleton_method(c_filter_no_slot, "new", RUBY_FUNC_CAST(&filter_no_slot_new), 0);
}
}