aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Richard Brown <rbrown@exherbo.org> 2007-06-05 17:19:44 +0000
committerAvatar Richard Brown <rbrown@exherbo.org> 2007-06-05 17:19:44 +0000
commit66b1c876c09833a4dd57d2be968a9acb1052e068 (patch)
treece8db98533b5d7904d98698fb6b44a8cdd9bfae0
parent37760513c55f802f31d5f137f0304b65cf352acb (diff)
downloadpaludis-66b1c876c09833a4dd57d2be968a9acb1052e068.tar.gz
paludis-66b1c876c09833a4dd57d2be968a9acb1052e068.tar.xz
(ruby) Fix Contents and DepTag visitors.
-rw-r--r--ruby/contents.cc136
-rw-r--r--ruby/contents_TEST.rb46
-rw-r--r--ruby/dep_tag.cc66
-rw-r--r--ruby/paludis_ruby.hh3
4 files changed, 120 insertions, 131 deletions
diff --git a/ruby/contents.cc b/ruby/contents.cc
index ae83fe9..01c1b10 100644
--- a/ruby/contents.cc
+++ b/ruby/contents.cc
@@ -19,6 +19,7 @@
#include <paludis_ruby.hh>
#include <paludis/contents.hh>
+#include <paludis/util/visitor-impl.hh>
#include <ruby.h>
using namespace paludis;
@@ -37,6 +38,70 @@ namespace
static VALUE c_contents_dev_entry;
static VALUE c_contents_fifo_entry;
+ struct V :
+ ConstVisitor<ContentsVisitorTypes>
+ {
+ VALUE value;
+ tr1::shared_ptr<const ContentsEntry> mm;
+
+ V(tr1::shared_ptr<const ContentsEntry> _m) :
+ mm(_m)
+ {
+ }
+
+ void visit(const ContentsFileEntry &)
+ {
+ value = Data_Wrap_Struct(c_contents_file_entry, 0, &Common<tr1::shared_ptr<const ContentsFileEntry> >::free,
+ new tr1::shared_ptr<const ContentsFileEntry>(tr1::static_pointer_cast<const ContentsFileEntry>(mm)));
+ }
+
+ void visit(const ContentsDirEntry &)
+ {
+ value = Data_Wrap_Struct(c_contents_dir_entry, 0, &Common<tr1::shared_ptr<const ContentsDirEntry> >::free,
+ new tr1::shared_ptr<const ContentsDirEntry>(tr1::static_pointer_cast<const ContentsDirEntry>(mm)));
+ }
+
+ void visit(const ContentsMiscEntry &)
+ {
+ value = Data_Wrap_Struct(c_contents_misc_entry, 0, &Common<tr1::shared_ptr<const ContentsMiscEntry> >::free,
+ new tr1::shared_ptr<const ContentsMiscEntry>(tr1::static_pointer_cast<const ContentsMiscEntry>(mm)));
+ }
+
+ void visit(const ContentsSymEntry &)
+ {
+ value = Data_Wrap_Struct(c_contents_sym_entry, 0, &Common<tr1::shared_ptr<const ContentsSymEntry> >::free,
+ new tr1::shared_ptr<const ContentsSymEntry>(tr1::static_pointer_cast<const ContentsSymEntry>(mm)));
+ }
+
+ void visit(const ContentsFifoEntry &)
+ {
+ value = Data_Wrap_Struct(c_contents_fifo_entry, 0, &Common<tr1::shared_ptr<const ContentsFifoEntry> >::free,
+ new tr1::shared_ptr<const ContentsFifoEntry>(tr1::static_pointer_cast<const ContentsFifoEntry>(mm)));
+ }
+
+ void visit(const ContentsDevEntry &)
+ {
+ value = Data_Wrap_Struct(c_contents_dev_entry, 0, &Common<tr1::shared_ptr<const ContentsDevEntry> >::free,
+ new tr1::shared_ptr<const ContentsDevEntry>(tr1::static_pointer_cast<const ContentsDevEntry>(mm)));
+ }
+ };
+
+
+ VALUE
+ contents_entry_to_value(tr1::shared_ptr<const ContentsEntry> m)
+ {
+ try
+ {
+ V v(m);
+ m->accept(v);
+ return v.value;
+ }
+ catch (const std::exception & e)
+ {
+ exception_to_ruby_exception(e);
+ }
+ }
+
VALUE
contents_init(VALUE self)
{
@@ -92,7 +157,6 @@ namespace
}
}
-#if CIARANM_REMOVED_THIS
/*
* call-seq:
* each {|contents_entry| block}
@@ -109,7 +173,6 @@ namespace
rb_yield(contents_entry_to_value(*i));
return self;
}
-#endif
VALUE
contents_entry_init(int, VALUE *, VALUE self)
@@ -204,9 +267,7 @@ namespace
rb_include_module(c_contents, rb_mEnumerable);
rb_define_singleton_method(c_contents, "new", RUBY_FUNC_CAST(&contents_new), 0);
rb_define_method(c_contents, "initialize", RUBY_FUNC_CAST(&contents_init), 0);
-#if CIARANM_REMOVED_THIS
rb_define_method(c_contents, "each", RUBY_FUNC_CAST(&contents_each), 0);
-#endif
rb_define_method(c_contents, "add", RUBY_FUNC_CAST(&contents_add), 1);
/*
@@ -274,73 +335,6 @@ namespace
}
}
-#if CIARANM_REMOVED_THIS
-VALUE
-paludis::ruby::contents_entry_to_value(tr1::shared_ptr<const ContentsEntry> m)
-{
- struct V :
- ContentsVisitorTypes::ConstVisitor
- {
- VALUE value;
- tr1::shared_ptr<const ContentsEntry> mm;
-
- V(tr1::shared_ptr<const ContentsEntry> _m) :
- mm(_m)
- {
- }
-
- void visit(const ContentsFileEntry *)
- {
- value = Data_Wrap_Struct(c_contents_file_entry, 0, &Common<tr1::shared_ptr<const ContentsFileEntry> >::free,
- new tr1::shared_ptr<const ContentsFileEntry>(tr1::static_pointer_cast<const ContentsFileEntry>(mm)));
- }
-
- void visit(const ContentsDirEntry *)
- {
- value = Data_Wrap_Struct(c_contents_dir_entry, 0, &Common<tr1::shared_ptr<const ContentsDirEntry> >::free,
- new tr1::shared_ptr<const ContentsDirEntry>(tr1::static_pointer_cast<const ContentsDirEntry>(mm)));
- }
-
- void visit(const ContentsMiscEntry *)
- {
- value = Data_Wrap_Struct(c_contents_misc_entry, 0, &Common<tr1::shared_ptr<const ContentsMiscEntry> >::free,
- new tr1::shared_ptr<const ContentsMiscEntry>(tr1::static_pointer_cast<const ContentsMiscEntry>(mm)));
- }
-
- void visit(const ContentsSymEntry *)
- {
- value = Data_Wrap_Struct(c_contents_sym_entry, 0, &Common<tr1::shared_ptr<const ContentsSymEntry> >::free,
- new tr1::shared_ptr<const ContentsSymEntry>(tr1::static_pointer_cast<const ContentsSymEntry>(mm)));
- }
-
- void visit(const ContentsFifoEntry *)
- {
- value = Data_Wrap_Struct(c_contents_fifo_entry, 0, &Common<tr1::shared_ptr<const ContentsFifoEntry> >::free,
- new tr1::shared_ptr<const ContentsFifoEntry>(tr1::static_pointer_cast<const ContentsFifoEntry>(mm)));
- }
-
- void visit(const ContentsDevEntry *)
- {
- value = Data_Wrap_Struct(c_contents_dev_entry, 0, &Common<tr1::shared_ptr<const ContentsDevEntry> >::free,
- new tr1::shared_ptr<const ContentsDevEntry>(tr1::static_pointer_cast<const ContentsDevEntry>(mm)));
- }
- };
-
- tr1::shared_ptr<const ContentsEntry> * m_ptr(0);
- try
- {
- V v(m);
- m->accept(&v);
- return v.value;
- }
- catch (const std::exception & e)
- {
- delete m_ptr;
- exception_to_ruby_exception(e);
- }
-}
-#endif
-
VALUE
paludis::ruby::contents_to_value(tr1::shared_ptr<const Contents> m)
{
diff --git a/ruby/contents_TEST.rb b/ruby/contents_TEST.rb
index d5a6f70..aea60f9 100644
--- a/ruby/contents_TEST.rb
+++ b/ruby/contents_TEST.rb
@@ -215,10 +215,10 @@ module Paludis
get_c
end
-### def test_responds_to
-### c = get_c
-### [:add, :entries, :each].each {|sym| assert_respond_to c, sym}
-### end
+ def test_responds_to
+ c = get_c
+ [:add, :entries, :each].each {|sym| assert_respond_to c, sym}
+ end
def test_add
assert_nothing_raised do
@@ -226,25 +226,25 @@ module Paludis
end
end
-### def test_entries
-### c = get_c
-###
-### assert_equal true, c.entries.empty?
-###
-### cfe = get_cfe
-### cse = get_cse
-### c.add(cfe)
-###
-### assert_equal 1, c.entries.length
-### assert_equal cfe.to_s, c.entries.first.to_s
-###
-### c.add(cse)
-###
-### assert_equal 2, c.entries.length
-### assert_equal cfe.to_s, c.entries.first.to_s
-### assert_equal cse.to_s, c.entries.last.to_s
-###
-### end
+ def test_entries
+ c = get_c
+
+ assert_equal true, c.entries.empty?
+
+ cfe = get_cfe
+ cse = get_cse
+ c.add(cfe)
+
+ assert_equal 1, c.entries.length
+ assert_equal cfe.to_s, c.entries.first.to_s
+
+ c.add(cse)
+
+ assert_equal 2, c.entries.length
+ assert_equal cfe.to_s, c.entries.first.to_s
+ assert_equal cse.to_s, c.entries.last.to_s
+
+ end
end
end
diff --git a/ruby/dep_tag.cc b/ruby/dep_tag.cc
index 58a3b5f..e05b4b6 100644
--- a/ruby/dep_tag.cc
+++ b/ruby/dep_tag.cc
@@ -32,6 +32,36 @@ namespace
static VALUE c_dependency_dep_tag;
static VALUE c_glsa_dep_tag;
static VALUE c_general_set_dep_tag;
+ struct V :
+ ConstVisitor<DepTagVisitorTypes>
+ {
+ VALUE value;
+ tr1::shared_ptr<const DepTag> mm;
+
+ V(tr1::shared_ptr<const DepTag> _m) :
+ mm(_m)
+ {
+ }
+
+ void visit(const DependencyDepTag &)
+ {
+ value = Data_Wrap_Struct(c_dependency_dep_tag, 0, &Common<tr1::shared_ptr<const DependencyDepTag> >::free,
+ new tr1::shared_ptr<const DependencyDepTag>(tr1::static_pointer_cast<const DependencyDepTag>(mm)));
+ }
+
+ void visit(const GLSADepTag &)
+ {
+ value = Data_Wrap_Struct(c_glsa_dep_tag, 0, &Common<tr1::shared_ptr<const GLSADepTag> >::free,
+ new tr1::shared_ptr<const GLSADepTag>(tr1::static_pointer_cast<const GLSADepTag>(mm)));
+ }
+
+ void visit(const GeneralSetDepTag &)
+ {
+ value = Data_Wrap_Struct(c_general_set_dep_tag, 0, &Common<tr1::shared_ptr<const GeneralSetDepTag> >::free,
+ new tr1::shared_ptr<const GeneralSetDepTag>(tr1::static_pointer_cast<const GeneralSetDepTag>(mm)));
+ }
+ };
+
VALUE
dep_tag_init(VALUE self, VALUE)
@@ -196,54 +226,20 @@ namespace
}
}
-#if CIARANM_REMOVED_THIS
VALUE
paludis::ruby::dep_tag_to_value(tr1::shared_ptr<const DepTag> m)
{
- struct V :
- DepTagVisitorTypes::ConstVisitor
- {
- VALUE value;
- tr1::shared_ptr<const DepTag> mm;
-
- V(tr1::shared_ptr<const DepTag> _m) :
- mm(_m)
- {
- }
-
- void visit(const DependencyDepTag *)
- {
- value = Data_Wrap_Struct(c_dependency_dep_tag, 0, &Common<tr1::shared_ptr<const DependencyDepTag> >::free,
- new tr1::shared_ptr<const DependencyDepTag>(tr1::static_pointer_cast<const DependencyDepTag>(mm)));
- }
-
- void visit(const GLSADepTag *)
- {
- value = Data_Wrap_Struct(c_glsa_dep_tag, 0, &Common<tr1::shared_ptr<const GLSADepTag> >::free,
- new tr1::shared_ptr<const GLSADepTag>(tr1::static_pointer_cast<const GLSADepTag>(mm)));
- }
-
- void visit(const GeneralSetDepTag *)
- {
- value = Data_Wrap_Struct(c_general_set_dep_tag, 0, &Common<tr1::shared_ptr<const GeneralSetDepTag> >::free,
- new tr1::shared_ptr<const GeneralSetDepTag>(tr1::static_pointer_cast<const GeneralSetDepTag>(mm)));
- }
- };
-
- tr1::shared_ptr<const DepTag> * m_ptr(0);
try
{
V v(m);
- m->accept(&v);
+ m->accept(v);
return v.value;
}
catch (const std::exception & e)
{
- delete m_ptr;
exception_to_ruby_exception(e);
}
}
-#endif
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 89ba2d2..d696c3e 100644
--- a/ruby/paludis_ruby.hh
+++ b/ruby/paludis_ruby.hh
@@ -71,9 +71,8 @@ namespace paludis
VALUE version_metadata_to_value(tr1::shared_ptr<const VersionMetadata>);
#if CIARANM_REMOVED_THIS
VALUE dep_spec_to_value(tr1::shared_ptr<const DepSpec>);
- VALUE contents_entry_to_value(tr1::shared_ptr<const ContentsEntry>);
- VALUE dep_tag_to_value(tr1::shared_ptr<const DepTag>);
#endif
+ VALUE dep_tag_to_value(tr1::shared_ptr<const DepTag>);
VALUE qualified_package_name_to_value(const QualifiedPackageName &);
VALUE contents_to_value(tr1::shared_ptr<const Contents>);
VALUE eapi_to_value(const tr1::shared_ptr<const EAPI> &);