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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2. Creation<br />

node member da da;<br />

introduces a variable da of this class that is not bound.<br />

node member da da(Ptr ptr);<br />

introduces a variable da of this class, which is bound to ptr.<br />

3. Operations<br />

T<br />

void<br />

get(const node member da& ma, const Iter& it)<br />

returns the associated value of it for this accessor.<br />

set(node member da& ma, const Iter& it, T val)<br />

sets the associated value of it for this accessor to the<br />

given value.<br />

4. Implementation<br />

Constant Overhead.<br />

<strong>The</strong> instance da accesses its parameter through a pointer to member of type Ptr, which<br />

is defined for example by typedef T Str::*Ptr.<br />

5. Example<br />

We have a parameterized graph G where the node information type is the following struct<br />

type Str:<br />

struct Str {<br />

int x;<br />

color col; };<br />

We want to count the number of red nodes. Since we have the template function of<br />

sect. 13.13 we can easily use it to do the computation:<br />

int count_red(GRAPH G) {<br />

node_member_da Color(&Str::col);<br />

return count_red_t(G,Color); }

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

Saved successfully!

Ooh no, something went wrong!