Coverage Report

Created: 2023-10-30 17:15

/builds/2mk6rsew/0/parcoach/parcoach/src/include/parcoach/andersen/GraphTraits.h
Line
Count
Source
1
#ifndef ANDERSEN_GRAPHTRAITS_H
2
#define ANDERSEN_GRAPHTRAITS_H
3
4
// An iterator adapter that takes an iterator over a map and returns the
5
// corresponding iterator over the VALUE part of the map (i.e. throws away the
6
// KEY part). Such an adapter is useful when we want an iterator to nodes of a
7
// graph while internally the graph class save the nodes in the value part of a
8
// map
9
template <class MapIterator> class MapValueIterator {
10
private:
11
  MapIterator itr;
12
  typedef typename MapIterator::value_type::second_type MapValueType;
13
14
public:
15
3.52k
  explicit MapValueIterator(MapIterator const &i) : itr(i) {}
16
17
18.1k
  bool operator==(MapValueIterator const &other) { return itr == other.itr; }
18
18.1k
  bool operator!=(MapValueIterator const &other) { return !(*this == other); }
19
20
  MapValueType const &operator*() { return itr->second; }
21
  MapValueType const &operator*() const { return itr->second; }
22
23
16.4k
  MapValueType const *operator->() const { return &(itr->second); }
24
25
  // Pre-increment
26
16.4k
  MapValueIterator &operator++() {
27
16.4k
    ++itr;
28
16.4k
    return *this;
29
16.4k
  }
30
  // Post-increment
31
  const MapValueIterator operator++(int) {
32
    MapValueIterator ret(itr);
33
    ++itr;
34
    return ret;
35
  }
36
};
37
38
// This class should be specialized by different graph types used in Andersen's
39
// anlysis, which is why the default version is empty
40
template <class GraphType> class AndersGraphTraits {
41
  // Elements to provide:
42
43
  // typedef NodeType           - Type of Node in the graph
44
  // typedef NodeIterator       - Type used to iterator over nodes in graph
45
  // typedef ChildIterator      - Type used to iterate over children in graph
46
47
  // static ChildIterator child_begin(NodeType*)
48
  // static ChildIterator child_end(NodeType*)
49
  // - Return iterators that point to the beginning and ending of the child node
50
  // list for the specified node
51
52
  // static NodeIterator node_begin(const GraphType*)
53
  // static NodeIterator node_end(const GraphType*)
54
  // - Allow iteration over all nodes in the graph
55
};
56
57
#endif