CVS commit by domi: add some handy algorithms M +22 -0 calcpaths.cc 1.13 M +9 -0 calcpaths.h 1.9 --- kdeedu/kig/misc/calcpaths.cc #1.12:1.13 @@ -180,2 +180,24 @@ Objects getAllParents( const Objects& ob return ret; } + +Objects getAllParents( Object* obj ) +{ + return getAllParents( Objects( obj ) ); +} + +bool isChild( const Object* o, const Objects& os ) +{ + using namespace std; + Objects cur( o->parents() ); + while ( ! cur.empty() ) + { + Objects next; + for ( Objects::const_iterator i = cur.begin(); i != cur.end(); ++i ) + { + if ( os.contains( *i ) ) return true; + next.upush( (*i)->parents() ); + }; + cur = next; + }; + return false; +} --- kdeedu/kig/misc/calcpaths.h #1.8:1.9 @@ -55,4 +55,13 @@ Objects sideOfTreePath( const Objects& f */ Objects getAllParents( const Objects& objs ); +/** + * @overload + */ +Objects getAllParents( Object* obj ); + +/** + * Returns true if o is a descendant of any of the objects in os.. + */ +bool isChild( const Object* o, const Objects& os ); #endif