diff options
-rw-r--r-- | Examples/test-suite/ruby/newobject2_runme.rb | 2 | ||||
-rw-r--r-- | Lib/ruby/rubyclasses.swg | 39 | ||||
-rw-r--r-- | Lib/ruby/rubycontainer.swg | 58 | ||||
-rw-r--r-- | Lib/ruby/rubycontainer_extended.swg | 11 | ||||
-rw-r--r-- | Lib/ruby/rubyiterators.swg | 2 |
5 files changed, 73 insertions, 39 deletions
diff --git a/Examples/test-suite/ruby/newobject2_runme.rb b/Examples/test-suite/ruby/newobject2_runme.rb index 9f609e8da..3468293f5 100644 --- a/Examples/test-suite/ruby/newobject2_runme.rb +++ b/Examples/test-suite/ruby/newobject2_runme.rb @@ -18,7 +18,7 @@ require 'newobject2' include Newobject2 GC.track_class = Foo -GC.stats +GC.stats if $VERBOSE 100.times { foo1 = makeFoo } GC.stats if $VERBOSE swig_assert( 'fooCount == 100', nil, "but is #{fooCount}" ) diff --git a/Lib/ruby/rubyclasses.swg b/Lib/ruby/rubyclasses.swg index 6cf7c9fb5..d8b97232e 100644 --- a/Lib/ruby/rubyclasses.swg +++ b/Lib/ruby/rubyclasses.swg @@ -200,5 +200,42 @@ namespace std { %} +// +// Fragment that contains traits to properly deal with GC_VALUE. +// These functions may be invoked as a need of the from(), asval(), +// asptr() and as() template functors, usually used in %typemaps. +// +%fragment(SWIG_Traits_frag(swig::GC_VALUE),"header",fragment="StdTraits") { +namespace swig { + template <> struct traits<GC_VALUE > { + typedef value_category category; + static const char* type_name() { return "GC_VALUE"; } + }; + + template <> struct traits_from<GC_VALUE> { + typedef GC_VALUE value_type; + static VALUE from(const value_type& val) { + return static_cast<VALUE>(val); + } + }; + + template <> + struct traits_check<GC_VALUE, value_category> { + static bool check(GC_VALUE) { + return true; + } + }; + + template <> struct traits_asval<GC_VALUE > { + typedef GC_VALUE value_type; + static int asval(VALUE obj, value_type *val) { + if (val) *val = obj; + return SWIG_OK; + } + }; +} // swig +} // %fragment(traits for swig::GC_VALUE) + + +#endif // __cplusplus -#endif diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index 9f5b95ad8..d151adb84 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -36,36 +36,6 @@ %include <std_except.i> -%fragment(SWIG_Traits_frag(swig::GC_VALUE),"header",fragment="StdTraits") { -namespace swig { - template <> struct traits<GC_VALUE > { - typedef value_category category; - static const char* type_name() { return "GC_VALUE"; } - }; - - template <> struct traits_from<GC_VALUE> { - typedef GC_VALUE value_type; - static VALUE from(const value_type& val) { - return static_cast<VALUE>(val); - } - }; - - template <> - struct traits_check<GC_VALUE, value_category> { - static bool check(GC_VALUE) { - return true; - } - }; - - template <> struct traits_asval<GC_VALUE > { - typedef GC_VALUE value_type; - static int asval(VALUE obj, value_type *val) { - if (val) *val = obj; - return SWIG_OK; - } - }; -} // swig -} // %fragment(traits for swig::GC_VALUE) %fragment("RubySequence_Base","header") { @@ -425,6 +395,10 @@ namespace swig } } +/** + * Macros used to typemap an STL iterator -> SWIGIterator conversion. + * + */ %define %swig_sequence_iterator(Sequence...) #if defined(SWIG_EXPORT_ITERATOR_METHODS) class iterator; @@ -514,6 +488,11 @@ namespace swig %enddef + +/** + * Macro used to define common Ruby printing methods for STL container + * + */ %define %swig_sequence_printing_methods(Sequence...) %extend { @@ -569,6 +548,10 @@ namespace swig %enddef +/** + * Macro used to add common methods to all STL sequence-type containers + * + */ %define %swig_sequence_methods_common(Sequence...) %swig_container_methods(%arg(Sequence)) %swig_sequence_iterator(%arg(Sequence)) @@ -674,6 +657,11 @@ namespace swig %enddef +/** + * Macro used to add functions for back insertion of values in + * STL Sequence containers + * + */ %define %swig_sequence_back_inserters( Sequence... ) %extend { @@ -705,6 +693,11 @@ namespace swig } %enddef + +/** + * Macro used to add functions for Sequences + * + */ %define %swig_sequence_methods(Sequence...) %swig_sequence_methods_common(%arg(Sequence)); %swig_sequence_back_inserters(%arg(Sequence)); @@ -842,6 +835,11 @@ namespace swig %enddef +/** + * Macro used to add functions for front insertion of + * elements in STL sequence containers that support it. + * + */ %define %swig_sequence_front_inserters( Sequence... ) %extend { diff --git a/Lib/ruby/rubycontainer_extended.swg b/Lib/ruby/rubycontainer_extended.swg index e868bcb0c..360e399ce 100644 --- a/Lib/ruby/rubycontainer_extended.swg +++ b/Lib/ruby/rubycontainer_extended.swg @@ -6,9 +6,9 @@ * @brief This file contains additional functions that make containers * behave closer to ruby primitive types. * However, some of these functions place some restrictions on - * the underlying object inside of the container (that it has - * an == comparison function, that it has an = assignment - * operator, etc). + * the underlying object inside of the container and the iterator + * (that it has to have an == comparison function, that it has to have + * an = assignment operator, etc). * */ @@ -54,7 +54,7 @@ // - // map! + // map! -- the equivalent of std::transform // Container< Type >* map_bang() { @@ -134,7 +134,6 @@ %__swig_container_extend_primtypes( std::vector ); -%__swig_container_extend_primtypes( std::set ); -%__swig_container_extend_primtypes( std::list ); %__swig_container_extend_primtypes( std::deque ); +%__swig_container_extend_primtypes( std::list ); diff --git a/Lib/ruby/rubyiterators.swg b/Lib/ruby/rubyiterators.swg index 78ddd3959..eafa265f4 100644 --- a/Lib/ruby/rubyiterators.swg +++ b/Lib/ruby/rubyiterators.swg @@ -9,7 +9,7 @@ * Users can derive form the RubySwigIterator to implemet their * own iterators. As an example (real one since we use it for STL/STD * containers), the template RubySwigIterator_T does the - * implementation for genereic C++ iterators. + * implementation for generic C++ iterators. * ----------------------------------------------------------------------------- */ %include <std_common.i> |