next up previous contents index
Next: Node Attribute Accessors ( Up: Graphs and Iterators Previous: Constant Accessors ( constant_da   Contents   Index


Node Member Accessors ( node_member_da )

Definition

An instance da of class node_member_da<Str,T> manages the access to a node parameter that is organized as a member of a struct type, which is the first template argument of a parameterized graph GRAPH<Str,?>. The parameter is of type T and the struct of type Str.

Classes edge_member_da<Str,T> is defined completely analogously.

#include < LEDA/graph/graph_iterator.h >

Creation

node_member_da< Str,T> da introduces a variable da of this class that is not bound.

node_member_da< Str,T> da(Ptr ptr) introduces a variable da of this class, which is bound to ptr.

Operations

T get(const node_member_da< Str,T> & ma, const Iter& it)
    returns the associated value of it for this accessor.

void set(node_member_da< Str,T> & ma, const Iter& it, T val)
    sets the associated value of it for this accessor to the given value.

Implementation

Constant Overhead.

The instance da accesses its parameter through a pointer to member of type Ptr, which is defined for example by typedef T Str::*Ptr.

Example

We have a parameterized graph G where the node information type is the following struct type Str:

  struct Str {
    int x;
    color col; };

We want to count the number of red nodes. Since we have the template function of sect. node_array_da we can easily use it to do the computation:

  int count_red(GRAPH<Str,double> G) {
    node_member_da<Str,color> Color(&Str::col);
    return count_red_t(G,Color); }


next up previous contents index
Next: Node Attribute Accessors ( Up: Graphs and Iterators Previous: Constant Accessors ( constant_da   Contents   Index
Christian Uhrig 2017-04-07