aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-01-11 22:15:10 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-01-11 22:15:10 +0000
commit0f8982e76bec360e87304788664176fc080fb8c4 (patch)
treebca5e632dea69443881962da4c4a1d04f587609a
parentf6a69f30afa955641d96457f55af75bb91672441 (diff)
downloadpaludis-0f8982e76bec360e87304788664176fc080fb8c4.tar.gz
paludis-0f8982e76bec360e87304788664176fc080fb8c4.tar.xz
(ruby) Add PackageDepSpec::tag=.
-rw-r--r--ruby/dep_spec.cc109
-rw-r--r--ruby/dep_spec_TEST.rb8
-rw-r--r--ruby/dep_tag.cc15
-rw-r--r--ruby/paludis_ruby.hh1
4 files changed, 89 insertions, 44 deletions
diff --git a/ruby/dep_spec.cc b/ruby/dep_spec.cc
index 7771881..2e2e0a1 100644
--- a/ruby/dep_spec.cc
+++ b/ruby/dep_spec.cc
@@ -118,11 +118,11 @@ namespace
public ConstAcceptInterfaceVisitsThis<WrappedSpecVisitorTypes, WrappedSpec<T_> >
{
private:
- tr1::shared_ptr<const T_> _spec;
+ tr1::shared_ptr<T_> _spec;
tr1::shared_ptr<Children> _children;
public:
- WrappedSpec(const tr1::shared_ptr<const T_> & s) :
+ WrappedSpec(const tr1::shared_ptr<T_> & s) :
_spec(s),
_children(new Children)
{
@@ -138,6 +138,11 @@ namespace
return _spec;
}
+ const tr1::shared_ptr<T_> spec()
+ {
+ return _spec;
+ }
+
template <typename Iter_>
WrappedSpec * add_children(Iter_ cur, const Iter_ end);
@@ -280,8 +285,8 @@ namespace
VALUE
uri_labels_dep_spec_labels(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
tr1::shared_ptr<const URILabelsDepSpec> real_ptr(tr1::static_pointer_cast<const WrappedSpec<URILabelsDepSpec> >(*ptr)->spec());
if (rb_block_given_p())
@@ -332,8 +337,8 @@ namespace
VALUE
block_dep_spec_blocked_spec(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * p;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, p);
+ tr1::shared_ptr<WrappedSpecBase> * p;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, p);
return package_dep_spec_to_value(tr1::static_pointer_cast<const WrappedSpec<BlockDepSpec> >(*p)->spec()->blocked_spec());
}
@@ -386,8 +391,8 @@ namespace
VALUE
use_dep_spec_flag(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * p;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, p);
+ tr1::shared_ptr<WrappedSpecBase> * p;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, p);
return rb_str_new2(stringify(tr1::static_pointer_cast<const WrappedSpec<UseDepSpec> >(*p)->spec()->flag()).c_str());
}
@@ -400,8 +405,8 @@ namespace
VALUE
use_dep_spec_inverse(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * p;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, p);
+ tr1::shared_ptr<WrappedSpecBase> * p;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, p);
return tr1::static_pointer_cast<const WrappedSpec<UseDepSpec> >(*p)->spec()->inverse() ? Qtrue : Qfalse;
}
@@ -414,8 +419,8 @@ namespace
VALUE
package_dep_spec_tag(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
if (0 == tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->tag())
return Qnil;
return dep_tag_to_value(tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->tag());
@@ -423,6 +428,21 @@ namespace
/*
* call-seq:
+ * tag=(dep_tag) -> Qnil
+ *
+ * Set the dep tag.
+ */
+ VALUE
+ package_dep_spec_set_tag(VALUE self, VALUE dep_tag)
+ {
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
+ (tr1::static_pointer_cast<WrappedSpec<PackageDepSpec> >(*ptr))->spec()->set_tag(value_to_dep_tag(dep_tag));
+ return Qnil;
+ }
+
+ /*
+ * call-seq:
* without_use_requirements -> PackageDepSpec
*
* Fetch us without our use requirements.
@@ -430,8 +450,8 @@ namespace
VALUE
package_dep_spec_without_use_requirements(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
return package_dep_spec_to_value(tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->without_use_requirements());
}
@@ -444,8 +464,8 @@ namespace
VALUE
package_dep_spec_package(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
if (0 == tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->package_ptr())
return Qnil;
return rb_str_new2(stringify(*tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->package_ptr()).c_str());
@@ -460,8 +480,8 @@ namespace
VALUE
package_dep_spec_package_name_part(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
if (0 == tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->package_name_part_ptr())
return Qnil;
return rb_str_new2(stringify(*tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->
@@ -477,8 +497,8 @@ namespace
VALUE
package_dep_spec_category_name_part(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
if (0 == tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->category_name_part_ptr())
return Qnil;
return rb_str_new2(stringify(*tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->
@@ -494,8 +514,8 @@ namespace
VALUE
string_dep_spec_text(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
return rb_str_new2(stringify(tr1::static_pointer_cast<const StringDepSpec>((*ptr)->base_spec())->text()).c_str());
}
@@ -508,8 +528,8 @@ namespace
template <typename T_>
VALUE dep_spec_to_s(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
return rb_str_new2(stringify(*tr1::static_pointer_cast<const WrappedSpec<T_> >(*ptr)->spec()).c_str());
}
@@ -522,8 +542,8 @@ namespace
VALUE
package_dep_spec_slot_ptr(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
if (0 == tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->slot_ptr())
return Qnil;
return rb_str_new2(stringify((*tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->slot_ptr())).c_str());
@@ -538,8 +558,8 @@ namespace
VALUE
package_dep_spec_repository_ptr(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
if (0 == tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->repository_ptr())
return Qnil;
return rb_str_new2(stringify((*tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->repository_ptr())).c_str());
@@ -554,8 +574,8 @@ namespace
VALUE
package_dep_spec_version_requirements_ptr(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
VALUE result(rb_ary_new());
VALUE result_hash;
if (tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->version_requirements_ptr())
@@ -584,8 +604,8 @@ namespace
VALUE
package_dep_spec_use_requirements(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
VALUE result(rb_ary_new());
VALUE result_hash;
if (tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->use_requirements_ptr())
@@ -609,8 +629,8 @@ namespace
VALUE
package_dep_spec_version_requirements_mode(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
return INT2FIX(tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*ptr)->spec()->version_requirements_mode());
}
@@ -620,8 +640,8 @@ namespace
static VALUE
fetch(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
tr1::shared_ptr<const FetchableURIDepSpec> f_ptr(tr1::static_pointer_cast<const FetchableURIDepSpec>((*ptr)->base_spec()));
return rb_str_new2(((f_ptr.get())->*(m_))().c_str());
}
@@ -639,8 +659,8 @@ namespace
static VALUE
each(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
if ((*ptr)->children())
for (WrappedSpecBase::Children::const_iterator i((*ptr)->children()->begin()), i_end((*ptr)->children()->end()) ;
@@ -659,8 +679,8 @@ namespace
VALUE
named_set_dep_spec_name(VALUE self)
{
- tr1::shared_ptr<const WrappedSpecBase> * ptr;
- Data_Get_Struct(self, tr1::shared_ptr<const WrappedSpecBase>, ptr);
+ tr1::shared_ptr<WrappedSpecBase> * ptr;
+ Data_Get_Struct(self, tr1::shared_ptr<WrappedSpecBase>, ptr);
return rb_str_new2(stringify(tr1::static_pointer_cast<const WrappedSpec<NamedSetDepSpec> >(*ptr)->spec()->text()).c_str());
}
@@ -899,6 +919,7 @@ namespace
rb_define_method(c_package_dep_spec, "use_requirements", RUBY_FUNC_CAST(&package_dep_spec_use_requirements), 0);
#endif
rb_define_method(c_package_dep_spec, "tag", RUBY_FUNC_CAST(&package_dep_spec_tag), 0);
+ rb_define_method(c_package_dep_spec, "tag=", RUBY_FUNC_CAST(&package_dep_spec_set_tag), 1);
rb_define_method(c_package_dep_spec, "without_use_requirements", RUBY_FUNC_CAST(&package_dep_spec_without_use_requirements), 0);
VALUE (* package_dep_spec_to_s) (VALUE) = &dep_spec_to_s<PackageDepSpec>;
rb_define_method(c_package_dep_spec, "to_s", RUBY_FUNC_CAST(package_dep_spec_to_s), 0);
@@ -989,8 +1010,8 @@ paludis::ruby::value_to_package_dep_spec(VALUE v)
{
if (rb_obj_is_kind_of(v, c_package_dep_spec))
{
- tr1::shared_ptr<const WrappedSpecBase> * v_ptr;
- Data_Get_Struct(v, tr1::shared_ptr<const WrappedSpecBase>, v_ptr);
+ tr1::shared_ptr<WrappedSpecBase> * v_ptr;
+ Data_Get_Struct(v, tr1::shared_ptr<WrappedSpecBase>, v_ptr);
return tr1::static_pointer_cast<const WrappedSpec<PackageDepSpec> >(*v_ptr)->spec();
}
else
@@ -1004,8 +1025,8 @@ paludis::ruby::value_to_dep_spec(VALUE v)
{
if (rb_obj_is_kind_of(v, c_dep_spec))
{
- tr1::shared_ptr<const WrappedSpecBase> * v_ptr;
- Data_Get_Struct(v, tr1::shared_ptr<const WrappedSpecBase>, v_ptr);
+ tr1::shared_ptr<WrappedSpecBase> * v_ptr;
+ Data_Get_Struct(v, tr1::shared_ptr<WrappedSpecBase>, v_ptr);
return (*v_ptr)->base_spec();
}
else
diff --git a/ruby/dep_spec_TEST.rb b/ruby/dep_spec_TEST.rb
index d81a014..9447358 100644
--- a/ruby/dep_spec_TEST.rb
+++ b/ruby/dep_spec_TEST.rb
@@ -142,6 +142,14 @@ module Paludis
def test_tag
assert_nil pda.tag
assert_nil pdb.tag
+
+ my_pda = pda
+ my_pda.tag = TargetDepTag.new
+ assert_kind_of TargetDepTag, my_pda.tag
+
+ assert_raise TypeError do
+ pdb.tag = 42
+ end
end
end
diff --git a/ruby/dep_tag.cc b/ruby/dep_tag.cc
index 1a2a953..bd0bac7 100644
--- a/ruby/dep_tag.cc
+++ b/ruby/dep_tag.cc
@@ -348,6 +348,21 @@ paludis::ruby::dep_tag_to_value(tr1::shared_ptr<const DepTag> m)
}
}
+tr1::shared_ptr<const DepTag>
+paludis::ruby::value_to_dep_tag(VALUE v)
+{
+ if (rb_obj_is_kind_of(v, c_dep_tag))
+ {
+ tr1::shared_ptr<const DepTag> * v_ptr;
+ Data_Get_Struct(v, tr1::shared_ptr<const DepTag>, v_ptr);
+ return *v_ptr;
+ }
+ else
+ {
+ rb_raise(rb_eTypeError, "Can't convert %s into DepTag", rb_obj_classname(v));
+ }
+}
+
RegisterRubyClass::Register paludis_ruby_register_dep_tag PALUDIS_ATTRIBUTE((used))
(&do_register_dep_tag);
diff --git a/ruby/paludis_ruby.hh b/ruby/paludis_ruby.hh
index be165ac..572df21 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -96,6 +96,7 @@ namespace paludis
tr1::shared_ptr<const PackageID> value_to_package_id(VALUE);
tr1::shared_ptr<const PackageDepSpec> value_to_package_dep_spec(VALUE v);
tr1::shared_ptr<const DepSpec> value_to_dep_spec(VALUE v);
+ tr1::shared_ptr<const DepTag> value_to_dep_tag(VALUE v);
QualifiedPackageName value_to_qualified_package_name(VALUE v);
tr1::shared_ptr<Environment> value_to_environment(VALUE v);
tr1::shared_ptr<NoConfigEnvironment> value_to_no_config_environment(VALUE v);