Author: aschnell Date: Mon Jul 16 14:53:50 2007 New Revision: 6020 URL: http://svn.opensuse.org/viewcvs/zypp?rev=6020&view=rev Log: - fixed ruby-like "each" iterator generation Modified: trunk/libzypp-bindings/examples/ruby/list_target_resolvables.rb trunk/libzypp-bindings/swig/ruby.i trunk/libzypp-bindings/swig/zypp.i Modified: trunk/libzypp-bindings/examples/ruby/list_target_resolvables.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp-bindings/examples/ruby/list_target_resolvables.rb?rev=6020&r1=6019&r2=6020&view=diff ============================================================================== --- trunk/libzypp-bindings/examples/ruby/list_target_resolvables.rb (original) +++ trunk/libzypp-bindings/examples/ruby/list_target_resolvables.rb Mon Jul 16 14:53:50 2007 @@ -3,10 +3,16 @@ include Rzypp z = ZYppFactory::instance.get_zypp +# puts z.class t = z.initialize_target("/") +# puts t.class + r = z.target.resolvables -puts r.class +# puts r.class + r.each do | p | - puts "#{p.name} #{p.edition}" + # puts p.class + puts p.name end + Modified: trunk/libzypp-bindings/swig/ruby.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp-bindings/swig/ruby.i?rev=6020&r1=6019&r2=6020&view=diff ============================================================================== --- trunk/libzypp-bindings/swig/ruby.i (original) +++ trunk/libzypp-bindings/swig/ruby.i Mon Jul 16 14:53:50 2007 @@ -8,30 +8,51 @@ } \ } -#define iter( cl, storetype ) \ -%mixin cl "Enumerable"; \ -%extend cl { \ - void each() { \ - cl::iterator i = self->begin(); \ - while ( i != self->end() ) { \ - rb_yield( SWIG_NewPointerObj( (void *) &*i, $descriptor(storetype), 1)); \ - ++i; \ - } \ - } \ -} -#define iter2( cl, storetype ) \ -%mixin cl "Enumerable"; \ -%extend cl { \ +// #define iter( cl, storetype ) \ +// %mixin cl "Enumerable"; \ +// %extend cl { \ +// void each() { \ +// cl::iterator i = self->begin(); \ +// while ( i != self->end() ) { \ +// rb_yield( SWIG_NewPointerObj( (void *) &*i, $descriptor(storetype), 1)); \ +// ++i; \ +// } \ +// } \ +// } + + +/* + * Extend cls with an ruby-like each iterator. Yields objects of type storetype. + * Parameter storetype must be a pointer type. + */ +#define iter2( cls, storetype ) \ +%mixin cls "Enumerable"; \ +%extend cls { \ void each() { \ - cl::iterator i = self->begin(); \ + cls::iterator i = self->begin(); \ while ( i != self->end() ) { \ - rb_yield( SWIG_NewPointerObj( (void *) &*i, $descriptor(storetype), 0)); \ + const storetype tmp = &**i; \ + rb_yield( SWIG_NewPointerObj( (void*) tmp, $descriptor(storetype), 0)); \ ++i; \ } \ } \ } + +// %mixin ResStore "Enumerable"; +// %extend ResStore { +// void each() { +// ResStore::iterator i = self->begin(); +// while ( i != self->end() ) { +// const ResObject* tmp = &**i; +// rb_yield( SWIG_NewPointerObj( (void*) tmp, $descriptor(ResObject*), 0)); +// ++i; +// } +// } +// } + + #define auto_iterator( cl, storetype ) \ %mixin cl "Enumerable"; \ %extend cl { \ @@ -96,4 +117,3 @@ %rename("rpmNoSignature=") ZYppCommitPolicy::rpmNoSignature(bool); %rename("syncPoolAfterCommit=") ZYppCommitPolicy::syncPoolAfterCommit(bool); - Modified: trunk/libzypp-bindings/swig/zypp.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp-bindings/swig/zypp.i?rev=6020&r1=6019&r2=6020&view=diff ============================================================================== --- trunk/libzypp-bindings/swig/zypp.i (original) +++ trunk/libzypp-bindings/swig/zypp.i Mon Jul 16 14:53:50 2007 @@ -102,7 +102,7 @@ /* define iterators using swig macros */ -iter2( ResStore, ResObject::Ptr ) +iter2( ResStore, ResObject* ) auto_iterator( std::list<RepoInfo>, RepoInfo ) %alias Arch::asString "to_s"; @@ -158,4 +158,4 @@ explicit ZYpp( const Impl_Ptr & impl_r ); }; -%include "ZYppFactory.i" \ No newline at end of file +%include "ZYppFactory.i" -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org