Author: kkaempf Date: Sat Dec 22 19:09:20 2007 New Revision: 8147 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8147&view=rev Log: more API cleanup limit 'each' iterators to Ruby (using rb_yield) index access to Solvables for Repo and Pool index access to Relations for Dependency Modified: trunk/sat-solver/bindings/ruby/tests/relation.rb trunk/sat-solver/bindings/ruby/tests/repo.rb trunk/sat-solver/bindings/ruby/tests/solver.rb trunk/sat-solver/bindings/satsolver.i Modified: trunk/sat-solver/bindings/ruby/tests/relation.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/relation.rb?rev=8147&r1=8146&r2=8147&view=diff ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/relation.rb (original) +++ trunk/sat-solver/bindings/ruby/tests/relation.rb Sat Dec 22 19:09:20 2007 @@ -10,13 +10,16 @@ @repo = SatSolver::Repo.new( @pool, "test" ) assert @repo @pool.arch = "i686" - @repo.add_solv( "../../../testsuite/data.libzypp/basic-exercises/exercise-1-packages.solv" ) + @repo = @pool.add_solv( "../../../testsuite/data.libzypp/basic-exercises/exercise-1-packages.solv" ) assert @repo.size > 0 end def test_relation rel = SatSolver::Relation.new( @pool, "A", SatSolver::REL_EQ, "1.0-0" ) puts "Relation: #{rel}" - @repo.each_solvable{ |s| + @repo.each { |s| + unless (s.provides.empty?) + puts s.provides[0] + end s.provides.each { |p| res1 = (p <=> rel) puts "#{p} cmp #{rel} => #{res1}" Modified: trunk/sat-solver/bindings/ruby/tests/repo.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/repo.rb?rev=8147&r1=8146&r2=8147&view=diff ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/repo.rb (original) +++ trunk/sat-solver/bindings/ruby/tests/repo.rb Sat Dec 22 19:09:20 2007 @@ -26,7 +26,7 @@ assert pool pool.arch = "i686" repo = pool.add_solv( "../../../testsuite/data.libzypp/basic-exercises/exercise-1-packages.solv" ) - repo.each_solvable{ |s| + repo.each { |s| puts s } assert true Modified: trunk/sat-solver/bindings/ruby/tests/solver.rb URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/solver.rb?rev=8147&r1=8146&r2=8147&view=diff ============================================================================== --- trunk/sat-solver/bindings/ruby/tests/solver.rb (original) +++ trunk/sat-solver/bindings/ruby/tests/solver.rb Sat Dec 22 19:09:20 2007 @@ -19,6 +19,11 @@ solver = SatSolver::Solver.new( pool, system ) solver.allow_uninstall = 1 solver.solve( transaction ) - solver.print_decisions + solver.each_to_install { |s| + puts "Install #{s}" + } + solver.each_to_erase { |s| + puts "Erase #{s}" + } end end Modified: trunk/sat-solver/bindings/satsolver.i URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8147&r1=8146&r2=8147&view=diff ============================================================================== --- trunk/sat-solver/bindings/satsolver.i (original) +++ trunk/sat-solver/bindings/satsolver.i Sat Dec 22 19:09:20 2007 @@ -49,6 +49,18 @@ return dependency; } +static int dependency_size( const Dependency *dep ) +{ + if (!dep) return 0; + int i = 0; + if (dep->relation) { + Id *ids = dep->solvable->repo->idarraydata + dep->relation; + while (*ids++) + ++i; + } + return i; +} + typedef struct _Action { SolverCmd cmd; Id id; @@ -209,12 +221,21 @@ int repo_count() { return $self->nrepos; } + Repo *get_repo( int i ) + { + if ( i < 0 ) return NULL; + if ( i >= $self->nrepos ) return NULL; + return $self->repos[i]; + } + +#if defined(SWIGRUBY) void each_repo() { int i; for (i = 0; i < $self->nrepos; ++i ) rb_yield(SWIG_NewPointerObj((void*) $self->repos[i], SWIGTYPE_p__Repo, 0)); } +#endif Repo *find_repo( const char *name ) { @@ -254,6 +275,7 @@ if (i >= $self->nsolvables) return NULL; return $self->solvables + i; } +#if defined(SWIGRUBY) void each() { Solvable *s; @@ -265,6 +287,7 @@ rb_yield(SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0)); } } +#endif Solvable * find( char *name, Repo *repo = NULL ) @@ -330,7 +353,8 @@ Pool *pool() { return $self->pool; } - void each_solvable() +#if defined(SWIGRUBY) + void each() { Solvable *s; Id p; @@ -341,6 +365,8 @@ rb_yield( SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0) ); } } +#endif + #if defined(SWIGRUBY) /* %rename is rejected by swig for [] */ %alias get_solvable "[]"; @@ -419,15 +445,35 @@ ~Dependency() { free( $self ); } int size() + { return dependency_size( $self ); } +#if defined(SWIGRUBY) + %rename("empty?") empty(); +#endif + int empty() + { return dependency_size( $self ) == 0; } + +#if defined(SWIGRUBY) + /* %rename is rejected by swig for [] */ + %alias get_relation "[]"; +#endif + Relation *get_relation( int i ) { - int i = 0; if ($self->relation) { + /* loop over it to detect end */ Id *ids = $self->solvable->repo->idarraydata + $self->relation; - while (*ids++) - ++i; + while ( i-- >= 0 ) { + if ( !*ids ) + break; + if ( i == 0 ) { + return relation_new( *ids, $self->solvable->repo->pool ); + } + ++ids; + } } - return i; + return NULL; } + +#if defined(SWIGRUBY) void each() { if ($self->relation) { @@ -438,6 +484,8 @@ } } } +#endif + #if defined(SWIGRUBY) /* %rename is rejected by swig for [] */ %alias get_relation "[]"; @@ -675,12 +723,12 @@ void print_decisions() { printdecisions( $self ); } -#if 0 void each_to_install() { Id p; Solvable *s; - for (int i = 0; i < $self->decisionq.count; i++) + int i; + for ( i = 0; i < $self->decisionq.count; i++) { p = $self->decisionq.elements[i]; if (p <= 0) @@ -697,7 +745,7 @@ } } - void each_to_remove() + void each_to_erase() { Id p; Solvable *s; @@ -712,7 +760,7 @@ rb_yield(SWIG_NewPointerObj((void*) s, SWIGTYPE_p__Solvable, 0)); } } -#endif + }; #if 0 -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org