aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-09 01:23:02 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-09 01:23:57 +0100
commitb27f5bc69db94543a9018b5150222ffab7f659e6 (patch)
tree41a40be59ba46122e6ca8c6b8414719ab3218759
parentb2764c36584febd0584cc5a1a7ab0c6bd44704d0 (diff)
downloadpaludis-b27f5bc69db94543a9018b5150222ffab7f659e6.tar.gz
paludis-b27f5bc69db94543a9018b5150222ffab7f659e6.tar.xz
ruby bindings annotations support
-rw-r--r--ruby/dep_spec.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc
index 382bf18..f010e0d 100644
--- a/ruby/dep_spec.cc
+++ b/ruby/dep_spec.cc
@@ -657,6 +657,93 @@ namespace
/*
* call-seq:
+ * each_metadata {|key| block } -> Nil
+ *
+ * Our metadata.
+ */
+ VALUE
+ dep_spec_each_metadata(VALUE self)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ try
+ {
+ for (DepSpec::MetadataConstIterator it((*ptr)->base_spec()->begin_metadata()),
+ it_end((*ptr)->base_spec()->end_metadata()); it_end != it; ++it)
+ {
+ VALUE val(metadata_key_to_value(*it));
+ if (Qnil != val)
+ rb_yield(val);
+ }
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
+ return Qnil;
+ }
+
+ /*
+ * call-seq:
+ * [String] -> MetadataKey or Nil
+ *
+ * The named metadata key.
+ */
+ VALUE
+ dep_spec_subscript(VALUE self, VALUE raw_name)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ try
+ {
+ DepSpec::MetadataConstIterator it((*ptr)->base_spec()->find_metadata(StringValuePtr(raw_name)));
+ if ((*ptr)->base_spec()->end_metadata() == it)
+ return Qnil;
+ return metadata_key_to_value(*it);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
+ return Qnil;
+ }
+
+ /*
+ * Document-method: choices_key
+ *
+ * call-seq:
+ * annotations_key -> MetadataSectionKey
+ *
+ * Our annotations
+ */
+ template <typename T_, const std::tr1::shared_ptr<const T_> (DepSpec::* m_) () const>
+ struct KeyValue
+ {
+ static VALUE
+ fetch(VALUE self)
+ {
+ std::tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, std::tr1::shared_ptr<WrappedSpecBase>, ptr);
+ std::tr1::shared_ptr<const T_> key(((*(*ptr)->base_spec()).*m_)());
+
+ try
+ {
+ if (key)
+ return metadata_key_to_value(key);
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+
+ return Qnil;
+ }
+ };
+
+ /*
+ * call-seq:
* text -> String
*
* Fetch our text.
@@ -1013,6 +1100,10 @@ namespace
*/
c_dep_spec = rb_define_class_under(paludis_module(), "DepSpec", rb_cObject);
rb_funcall(c_dep_spec, rb_intern("private_class_method"), 1, rb_str_new2("new"));
+ rb_define_method(c_dep_spec, "each_metadata", RUBY_FUNC_CAST(&dep_spec_each_metadata), 0);
+ rb_define_method(c_dep_spec, "[]", RUBY_FUNC_CAST(&dep_spec_subscript), 1);
+ rb_define_method(c_dep_spec, "annotations_key",
+ RUBY_FUNC_CAST((&KeyValue<MetadataSectionKey, &DepSpec::annotations_key>::fetch)), 0);
/*
* Document-class: Paludis::AllDepSpec