aboutsummaryrefslogtreecommitdiff
path: root/ruby
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-30 11:37:31 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-04-04 08:32:59 +0100
commit28626b8aa3b39d400f8f9eb3a0730ac101b2e53a (patch)
treec60cfb02dcee2efcf7045ccfd53316e5a8fe94a8 /ruby
parenta004eeed5dda3432dcb1a4c0a865ae24daae4fd3 (diff)
downloadpaludis-28626b8aa3b39d400f8f9eb3a0730ac101b2e53a.tar.gz
paludis-28626b8aa3b39d400f8f9eb3a0730ac101b2e53a.tar.xz
slot to requirements
Diffstat (limited to 'ruby')
-rw-r--r--ruby/dep_spec.cc139
-rw-r--r--ruby/dep_spec_TEST.rb12
-rw-r--r--ruby/package_dep_spec_constraint.cc77
3 files changed, 115 insertions, 113 deletions
diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc
index da98fb9f8..6e6e2a696 100644
--- a/ruby/dep_spec.cc
+++ b/ruby/dep_spec.cc
@@ -67,56 +67,6 @@ namespace
static VALUE c_version_requirements_mode;
- static VALUE c_slot_requirement;
- static VALUE c_slot_exact_requirement;
- static VALUE c_slot_any_locked_requirement;
- static VALUE c_slot_any_unlocked_requirement;
-
- struct V
- {
- VALUE value;
- std::shared_ptr<const SlotRequirement> mm;
-
- V(std::shared_ptr<const SlotRequirement> _m) :
- mm(_m)
- {
- }
-
- void visit(const SlotExactRequirement &)
- {
- value = Data_Wrap_Struct(c_slot_exact_requirement, 0, &Common<std::shared_ptr<const SlotRequirement> >::free,
- new std::shared_ptr<const SlotRequirement>(mm));
- }
-
- void visit(const SlotAnyLockedRequirement &)
- {
- value = Data_Wrap_Struct(c_slot_any_locked_requirement, 0, &Common<std::shared_ptr<const SlotRequirement> >::free,
- new std::shared_ptr<const SlotRequirement>(mm));
- }
-
- void visit(const SlotAnyUnlockedRequirement &)
- {
- value = Data_Wrap_Struct(c_slot_any_unlocked_requirement, 0, &Common<std::shared_ptr<const SlotRequirement> >::free,
- new std::shared_ptr<const SlotRequirement>(mm));
- }
-
- };
-
- VALUE
- slot_requirement_to_value(std::shared_ptr<const SlotRequirement> m)
- {
- try
- {
- V v(m);
- m->accept(v);
- return v.value;
- }
- catch (const std::exception & e)
- {
- exception_to_ruby_exception(e);
- }
- }
-
struct WrappedSpecBase;
template <typename> struct WrappedSpec;
@@ -628,46 +578,62 @@ namespace
/*
* call-seq:
- * text -> String
+ * any_slot_constraint -> AnySlotConstraint or Nil
*
- * Fetch our text.
+ * Fetch the any-slot constraint (may be Nil).
*/
VALUE
- string_dep_spec_text(VALUE self)
+ package_dep_spec_any_slot_constraint(VALUE self)
{
std::shared_ptr<WrappedSpecBase> * ptr;
Data_Get_Struct(self, std::shared_ptr<WrappedSpecBase>, ptr);
- return rb_str_new2(stringify(std::static_pointer_cast<const StringDepSpec>((*ptr)->base_spec())->text()).c_str());
+ if (! bool(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->any_slot_constraint()))
+ return Qnil;
+ return package_dep_spec_constraint_to_value(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->any_slot_constraint());
}
/*
* call-seq:
- * to_s -> String
+ * exact_slot_constraint -> ExactSlotConstraint or Nil
*
- * Fetch a string representation of ourself.
+ * Fetch the exact-slot constraint (may be Nil).
*/
- template <typename T_>
- VALUE dep_spec_to_s(VALUE self)
+ VALUE
+ package_dep_spec_exact_slot_constraint(VALUE self)
{
std::shared_ptr<WrappedSpecBase> * ptr;
Data_Get_Struct(self, std::shared_ptr<WrappedSpecBase>, ptr);
- return rb_str_new2(stringify(*std::static_pointer_cast<const WrappedSpec<T_> >(*ptr)->spec()).c_str());
+ if (! bool(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->exact_slot_constraint()))
+ return Qnil;
+ return package_dep_spec_constraint_to_value(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->exact_slot_constraint());
}
/*
* call-seq:
- * slot_requirement -> SlotRequirement or Nil
+ * text -> String
*
- * Fetch the slot requirement.
+ * Fetch our text.
*/
VALUE
- package_dep_spec_slot_requirement_ptr(VALUE self)
+ string_dep_spec_text(VALUE self)
{
std::shared_ptr<WrappedSpecBase> * ptr;
Data_Get_Struct(self, std::shared_ptr<WrappedSpecBase>, ptr);
- if (! bool(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->slot_requirement_ptr()))
- return Qnil;
- return slot_requirement_to_value(std::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->slot_requirement_ptr());
+ return rb_str_new2(stringify(std::static_pointer_cast<const StringDepSpec>((*ptr)->base_spec())->text()).c_str());
+ }
+
+ /*
+ * call-seq:
+ * to_s -> String
+ *
+ * Fetch a string representation of ourself.
+ */
+ template <typename T_>
+ VALUE dep_spec_to_s(VALUE self)
+ {
+ std::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::shared_ptr<WrappedSpecBase>, ptr);
+ return rb_str_new2(stringify(*std::static_pointer_cast<const WrappedSpec<T_> >(*ptr)->spec()).c_str());
}
/*
@@ -958,14 +924,6 @@ namespace
}
- VALUE
- slot_exact_requirement_slot(VALUE self)
- {
- std::shared_ptr<const SlotExactRequirement> * ptr;
- Data_Get_Struct(self, std::shared_ptr<const SlotExactRequirement>, ptr);
- return rb_str_new2(stringify((*ptr)->slot()).c_str());
- }
-
void do_register_dep_spec()
{
/*
@@ -1103,12 +1061,13 @@ namespace
rb_define_method(c_package_dep_spec, "package_name_constraint", RUBY_FUNC_CAST(&package_dep_spec_package_name_constraint), 0);
rb_define_method(c_package_dep_spec, "package_name_part_constraint", RUBY_FUNC_CAST(&package_dep_spec_package_name_part_constraint), 0);
rb_define_method(c_package_dep_spec, "category_name_part_constraint", RUBY_FUNC_CAST(&package_dep_spec_category_name_part_constraint), 0);
- rb_define_method(c_package_dep_spec, "slot_requirement", RUBY_FUNC_CAST(&package_dep_spec_slot_requirement_ptr), 0);
rb_define_method(c_package_dep_spec, "in_repository_constraint", RUBY_FUNC_CAST(&package_dep_spec_in_repository_constraint), 0);
rb_define_method(c_package_dep_spec, "from_repository_constraint", RUBY_FUNC_CAST(&package_dep_spec_from_repository_constraint), 0);
rb_define_method(c_package_dep_spec, "installable_to_repository_constraint", RUBY_FUNC_CAST(&package_dep_spec_installable_to_repository_constraint), 0);
rb_define_method(c_package_dep_spec, "installed_at_path_constraint", RUBY_FUNC_CAST(&package_dep_spec_installed_at_path_constraint), 0);
rb_define_method(c_package_dep_spec, "installable_to_path_constraint", RUBY_FUNC_CAST(&package_dep_spec_installable_to_path_constraint), 0);
+ rb_define_method(c_package_dep_spec, "any_slot_constraint", RUBY_FUNC_CAST(&package_dep_spec_any_slot_constraint), 0);
+ rb_define_method(c_package_dep_spec, "exact_slot_constraint", RUBY_FUNC_CAST(&package_dep_spec_exact_slot_constraint), 0);
rb_define_method(c_package_dep_spec, "version_requirements", RUBY_FUNC_CAST(&package_dep_spec_version_requirements_ptr), 0);
rb_define_method(c_package_dep_spec, "version_requirements_mode", RUBY_FUNC_CAST(&package_dep_spec_version_requirements_mode), 0);
#ifdef CIARANM_REMOVED_THIS
@@ -1190,38 +1149,6 @@ namespace
// cc_enum_special<paludis/version_requirements.hh, VersionRequirementsMode, c_version_requirements_mode>
rb_define_module_function(paludis_module(), "parse_user_package_dep_spec", RUBY_FUNC_CAST(&paludis_parse_user_dep_spec), -1);
-
- /*
- * Document-class: Paludis::SlotRequirement
- *
- * A SlotRequirement
- */
- c_slot_requirement = rb_define_class_under(paludis_module(), "SlotRequirement", rb_cObject);
- rb_funcall(c_slot_requirement, rb_intern("private_class_method"), 1, rb_str_new2("new"));
- rb_define_method(c_slot_requirement, "as_string", RUBY_FUNC_CAST(&Common<std::shared_ptr<const SlotRequirement> >::to_s_via_ptr), 0);
- rb_define_method(c_slot_requirement, "to_s", RUBY_FUNC_CAST(&Common<std::shared_ptr<const SlotRequirement> >::to_s_via_ptr), 0);
-
- /*
- * Document-class: Paludis::ExactSlotRequirement
- *
- * An exact slot requiremet (:)
- */
- c_slot_exact_requirement = rb_define_class_under(paludis_module(), "SlotExactRequirement", c_slot_requirement);
- rb_define_method(c_slot_exact_requirement, "slot", RUBY_FUNC_CAST(&slot_exact_requirement_slot), 0);
-
- /*
- * Document-class: Paludis::SlotAnyLockedRequirement
- *
- * An any locked slot requiremet (:=)
- */
- c_slot_any_locked_requirement = rb_define_class_under(paludis_module(), "SlotAnyLockedRequirement", c_slot_requirement);
-
- /*
- * Document-class: Paludis::ExactSlotRequirement
- *
- * An any unlocked slot requiremet (:*)
- */
- c_slot_any_unlocked_requirement = rb_define_class_under(paludis_module(), "SlotAnyUnlockedRequirement", c_slot_requirement);
}
}
diff --git a/ruby/dep_spec_TEST.rb b/ruby/dep_spec_TEST.rb
index 7e3db1b9c..d0d63e3f1 100644
--- a/ruby/dep_spec_TEST.rb
+++ b/ruby/dep_spec_TEST.rb
@@ -130,13 +130,11 @@ module Paludis
end
def test_slot
- assert_kind_of SlotExactRequirement, pda.slot_requirement
- assert_equal ":100", pda.slot_requirement.to_s
- assert_equal "100", pda.slot_requirement.slot
- assert_nil pdb.slot_requirement
- assert_nil pdc.slot_requirement
- assert_nil pdd.slot_requirement
- assert_nil pde.slot_requirement
+ assert_equal "100", pda.exact_slot_constraint.name
+ assert_nil pdb.exact_slot_constraint
+ assert_nil pdc.exact_slot_constraint
+ assert_nil pdd.exact_slot_constraint
+ assert_nil pde.exact_slot_constraint
end
def test_package
diff --git a/ruby/package_dep_spec_constraint.cc b/ruby/package_dep_spec_constraint.cc
index 4d4ed3852..62799087a 100644
--- a/ruby/package_dep_spec_constraint.cc
+++ b/ruby/package_dep_spec_constraint.cc
@@ -39,6 +39,8 @@ namespace
static VALUE c_installed_at_path_constraint;
static VALUE c_installable_to_path_constraint;
static VALUE c_installable_to_repository_constraint;
+ static VALUE c_any_slot_constraint;
+ static VALUE c_exact_slot_constraint;
struct V
{
@@ -97,6 +99,18 @@ namespace
value = Data_Wrap_Struct(c_installable_to_repository_constraint, 0, &Common<std::shared_ptr<const PackageDepSpecConstraint> >::free,
new std::shared_ptr<const PackageDepSpecConstraint>(mm));
}
+
+ void visit(const AnySlotConstraint &)
+ {
+ value = Data_Wrap_Struct(c_any_slot_constraint, 0, &Common<std::shared_ptr<const PackageDepSpecConstraint> >::free,
+ new std::shared_ptr<const PackageDepSpecConstraint>(mm));
+ }
+
+ void visit(const ExactSlotConstraint &)
+ {
+ value = Data_Wrap_Struct(c_exact_slot_constraint, 0, &Common<std::shared_ptr<const PackageDepSpecConstraint> >::free,
+ new std::shared_ptr<const PackageDepSpecConstraint>(mm));
+ }
};
/*
@@ -229,6 +243,45 @@ namespace
return (std::static_pointer_cast<const InstallableToRepositoryConstraint>(*ptr))->include_masked() ? Qtrue : Qfalse;
}
+ /*
+ * Document-method: locking?
+ *
+ * The locking constraint.
+ */
+ static VALUE
+ any_slot_constraint_locking(VALUE self)
+ {
+ std::shared_ptr<const PackageDepSpecConstraint> * ptr;
+ Data_Get_Struct(self, std::shared_ptr<const PackageDepSpecConstraint>, ptr);
+ return (std::static_pointer_cast<const AnySlotConstraint>(*ptr))->locking() ? Qtrue : Qfalse;
+ }
+
+ /*
+ * Document-method: locked?
+ *
+ * The locked constraint.
+ */
+ static VALUE
+ exact_slot_constraint_locked(VALUE self)
+ {
+ std::shared_ptr<const PackageDepSpecConstraint> * ptr;
+ Data_Get_Struct(self, std::shared_ptr<const PackageDepSpecConstraint>, ptr);
+ return (std::static_pointer_cast<const ExactSlotConstraint>(*ptr))->locked() ? Qtrue : Qfalse;
+ }
+
+ /*
+ * Document-method: name
+ *
+ * The name constraint.
+ */
+ static VALUE
+ exact_slot_constraint_name(VALUE self)
+ {
+ std::shared_ptr<const PackageDepSpecConstraint> * ptr;
+ Data_Get_Struct(self, std::shared_ptr<const PackageDepSpecConstraint>, ptr);
+ return rb_str_new2(stringify((std::static_pointer_cast<const ExactSlotConstraint>(*ptr))->name()).c_str());
+ }
+
void do_register_package_dep_spec_constraint()
{
/*
@@ -329,6 +382,30 @@ namespace
&installable_to_repository_constraint_name), 0);
rb_define_method(c_installable_to_repository_constraint, "include_masked?", RUBY_FUNC_CAST(
&installable_to_repository_constraint_include_masked), 0);
+
+ /*
+ * Document-class: Paludis::AnySlotConstraint
+ *
+ * Represents a :* or := constraint in a PackageDepSpec.
+ */
+ c_any_slot_constraint = rb_define_class_under(
+ paludis_module(), "AnySlotConstraint", c_package_dep_spec_constraint);
+ rb_funcall(c_any_slot_constraint, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_any_slot_constraint, "locking?", RUBY_FUNC_CAST(
+ &any_slot_constraint_locking), 0);
+
+ /*
+ * Document-class: Paludis::ExactSlotConstraint
+ *
+ * Represents a :slot or :=slot constraint in a PackageDepSpec.
+ */
+ c_exact_slot_constraint = rb_define_class_under(
+ paludis_module(), "ExactSlotConstraint", c_package_dep_spec_constraint);
+ rb_funcall(c_exact_slot_constraint, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_exact_slot_constraint, "locked?", RUBY_FUNC_CAST(
+ &exact_slot_constraint_locked), 0);
+ rb_define_method(c_exact_slot_constraint, "name", RUBY_FUNC_CAST(
+ &exact_slot_constraint_name), 0);
}
}