From 005e129287766330f3e2823e8f9902dc9232ebbc Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Wed, 22 Feb 2017 12:23:23 +0900 Subject: [PATCH 1/5] [ruby] make std::unordered_map include Enumerable. --- Lib/ruby/std_unordered_map.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/ruby/std_unordered_map.i b/Lib/ruby/std_unordered_map.i index b2cef6520..c3f60bbba 100644 --- a/Lib/ruby/std_unordered_map.i +++ b/Lib/ruby/std_unordered_map.i @@ -77,7 +77,7 @@ %rename("include?") std::unordered_map::__contains__ const; %rename("has_key?") std::unordered_map::has_key const; -%mixin std::map "Enumerable"; -%alias std::unordered_map::push "<<"; +%mixin std::unordered_map "Enumerable"; +%alias std::unordered_map::push "<<"; %include From 9f4308278637e181bd4aa64e2afcc2e0d50031e2 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Fri, 24 Feb 2017 16:58:34 +0900 Subject: [PATCH 2/5] [ruby] make std::multiset and std::unordered_multiset include Enumerable. tests added. --- .../test-suite/ruby/cpp11_hash_tables_runme.rb | 16 ++++++++++++++++ Lib/ruby/std_multiset.i | 2 +- Lib/ruby/std_unordered_multiset.i | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/ruby/cpp11_hash_tables_runme.rb b/Examples/test-suite/ruby/cpp11_hash_tables_runme.rb index db910505e..a7b384692 100644 --- a/Examples/test-suite/ruby/cpp11_hash_tables_runme.rb +++ b/Examples/test-suite/ruby/cpp11_hash_tables_runme.rb @@ -5,6 +5,9 @@ require 'cpp11_hash_tables' Cpp11_hash_tables::MultiMapIntInt.new({1=>7}), Cpp11_hash_tables::UnorderedMapIntInt.new({1=>7}), Cpp11_hash_tables::UnorderedMultiMapIntInt.new({1=>7})].each{|x| + + swig_assert_equal("x.find_all{|e,k| e == 1}", "[[1,7]]", binding) + swig_assert_equal("x[1]", "7", binding) swig_assert_equal("x[2]", "nil", binding) x[2] = 9 @@ -27,6 +30,9 @@ require 'cpp11_hash_tables' Cpp11_hash_tables::MultiSetInt.new([1]), Cpp11_hash_tables::UnorderedSetInt.new([1]), Cpp11_hash_tables::UnorderedMultiSetInt.new([1])].each{|x| + + swig_assert_equal("x.find_all{|e| e == 1}", "[1]", binding) + swig_assert_equal("x.include?(1)", "true", binding) swig_assert_equal("x.include?(2)", "false", binding) x << 2 @@ -42,3 +48,13 @@ require 'cpp11_hash_tables' x << 1 swig_assert_equal("x.count(1)", "2", binding) } + +[Cpp11_hash_tables::MapIntInt, + Cpp11_hash_tables::MultiMapIntInt, + Cpp11_hash_tables::UnorderedMapIntInt, + Cpp11_hash_tables::UnorderedMultiMapIntInt, + Cpp11_hash_tables::SetInt, + Cpp11_hash_tables::UnorderedSetInt, + Cpp11_hash_tables::UnorderedMultiSetInt].each{|k| + swig_assert("k.include?(Enumerable)", binding) +} diff --git a/Lib/ruby/std_multiset.i b/Lib/ruby/std_multiset.i index 87a7b292a..252ae10d2 100644 --- a/Lib/ruby/std_multiset.i +++ b/Lib/ruby/std_multiset.i @@ -36,7 +36,7 @@ #define %swig_multiset_methods(Set...) %swig_set_methods(Set) - +%mixin std::multiset "Enumerable"; %rename("delete") std::multiset::__delete__; %rename("reject!") std::multiset::reject_bang; diff --git a/Lib/ruby/std_unordered_multiset.i b/Lib/ruby/std_unordered_multiset.i index 8e0a62b30..29fa73a98 100644 --- a/Lib/ruby/std_unordered_multiset.i +++ b/Lib/ruby/std_unordered_multiset.i @@ -36,6 +36,8 @@ #define %swig_unordered_multiset_methods(Set...) %swig_unordered_set_methods(Set) +%mixin std::unordered_multiset "Enumerable"; + %rename("delete") std::unordered_multiset::__delete__; %rename("reject!") std::unordered_multiset::reject_bang; %rename("map!") std::unordered_multiset::map_bang; From c88b9e877778b25c46db79daa10a1fb73fdfb197 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Sat, 25 Feb 2017 16:08:21 +0900 Subject: [PATCH 3/5] [ruby] make std::list include Enumerable. --- Examples/test-suite/ruby/li_std_list_runme.rb | 8 ++++++++ Lib/ruby/std_list.i | 1 + 2 files changed, 9 insertions(+) create mode 100644 Examples/test-suite/ruby/li_std_list_runme.rb diff --git a/Examples/test-suite/ruby/li_std_list_runme.rb b/Examples/test-suite/ruby/li_std_list_runme.rb new file mode 100644 index 000000000..b1182e2e3 --- /dev/null +++ b/Examples/test-suite/ruby/li_std_list_runme.rb @@ -0,0 +1,8 @@ +require 'swig_assert' + +require 'li_std_list' + +include Li_std_list + +x = DoubleList.new([1,2,3]) +swig_assert_equal("[1.0]", "x.find_all{|e| e == 1 }", binding) diff --git a/Lib/ruby/std_list.i b/Lib/ruby/std_list.i index 8d4284bbc..5f179cc69 100644 --- a/Lib/ruby/std_list.i +++ b/Lib/ruby/std_list.i @@ -27,6 +27,7 @@ #define %swig_list_methods(Type...) %swig_sequence_methods(Type) #define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type); +%mixin std::list "Enumerable"; %rename("delete") std::list::__delete__; %rename("reject!") std::list::reject_bang; From b525848063bf0b15a12e1da7734f149ae5b5a642 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Sun, 26 Feb 2017 07:17:33 +0900 Subject: [PATCH 4/5] [ruyb] enable std::list test for Ruby. --- Examples/test-suite/ruby/Makefile.in | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/ruby/Makefile.in b/Examples/test-suite/ruby/Makefile.in index a127860b0..47ea44037 100644 --- a/Examples/test-suite/ruby/Makefile.in +++ b/Examples/test-suite/ruby/Makefile.in @@ -14,6 +14,7 @@ CPP_TEST_CASES = \ li_cstring \ li_factory \ li_std_functors \ + li_std_list \ li_std_multimap \ li_std_pair_lang_object \ li_std_queue \ From a02b7810bc24036f1f891cc7fa4a28c4e1a45869 Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Sun, 26 Feb 2017 22:12:39 +0900 Subject: [PATCH 5/5] [ruby] add a test to make sure that std::multiset is including Enumerable. --- Examples/test-suite/ruby/cpp11_hash_tables_runme.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/test-suite/ruby/cpp11_hash_tables_runme.rb b/Examples/test-suite/ruby/cpp11_hash_tables_runme.rb index a7b384692..203b0ce06 100644 --- a/Examples/test-suite/ruby/cpp11_hash_tables_runme.rb +++ b/Examples/test-suite/ruby/cpp11_hash_tables_runme.rb @@ -54,6 +54,7 @@ require 'cpp11_hash_tables' Cpp11_hash_tables::UnorderedMapIntInt, Cpp11_hash_tables::UnorderedMultiMapIntInt, Cpp11_hash_tables::SetInt, + Cpp11_hash_tables::MultiSetInt, Cpp11_hash_tables::UnorderedSetInt, Cpp11_hash_tables::UnorderedMultiSetInt].each{|k| swig_assert("k.include?(Enumerable)", binding)