31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2. Creation<br />

CompPred cp(const DA& da, const Comp& comp,<br />

typename DA:: value type val);<br />

introduces a variable cp of this class and associates it to the given<br />

data accessor da, compare function comp and value val.<br />

Precondition: Comp is a pointer-to-function type which takes two values<br />

of type typename DA:: value type and produces a boolean return<br />

value. Comp might also be a class with member function<br />

bool operator( )(typename DA:: value type, typename DA:: value type).<br />

3. Example<br />

In the following example, a node iterator for red nodes will be created. At first the basic<br />

part (see sect. 13.13 for explanation of the data accessor node array da):<br />

graph G;<br />

NodeIt it(G);<br />

node_array na_colour(G,black);<br />

node_array_da da_colour(na_colour);<br />

assign_some_color_to_each_node();<br />

Now follows the definition of a “red iterator” (Equal yields true, if the given two values<br />

are equal):<br />

template<br />

class Equal {<br />

public:<br />

bool operator() (T t1, T t2) const {<br />

return t1==t2; }<br />

};<br />

typedef CompPred Predicate;<br />

Predicate PredColour(da_colour,Equal(),red);<br />

FilterNodeIt red_it(PredColour,it);<br />

This simplifies the loop to the following:<br />

while(red_it.valid()) {<br />

do_something(red_it);<br />

++red_it; }

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!