OpenSDN source code
db_graph_vertex.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef ctrlplane_db_graph_entry_h
7 #define ctrlplane_db_graph_entry_h
8 
9 #include "db/db_entry.h"
10 #include "db/db_graph_base.h"
11 
12 class DBGraph;
13 class DBGraphEdge;
14 class DBGraphVertex;
15 
16 namespace boost {
17 template <>
18 struct is_POD<DBGraphEdge> : public false_type {};
19 
20 template <>
21 struct is_POD<DBGraphVertex> : public false_type {};
22 }
23 
24 class DBGraphVertex : public DBEntry {
25 public:
28 
30 
31  class adjacency_iterator : public boost::iterator_facade<
32  adjacency_iterator, DBGraphVertex, boost::forward_traversal_tag
33  > {
34  public:
37  private:
39  void increment() {
40  ++iter_;
41  }
42  bool equal(const adjacency_iterator &rhs) const {
43  if (graph_ == NULL) {
44  return (rhs.graph_ == NULL);
45  }
46  if (rhs.graph_ == NULL) {
47  return iter_ == end_;
48  }
49  return iter_ == rhs.iter_;
50  }
51  DBGraphVertex &dereference() const;
55  };
56 
57  class edge_iterator : public boost::iterator_facade<
58  edge_iterator, DBGraphEdge, boost::forward_traversal_tag
59  > {
60  public:
61  edge_iterator();
63  DBGraphVertex *target() const;
64  private:
66  void increment() {
67  ++iter_;
68  }
69  bool equal(const edge_iterator &rhs) const {
70  if (graph_ == NULL) {
71  return (rhs.graph_ == NULL);
72  }
73  if (rhs.graph_ == NULL) {
74  return iter_ == end_;
75  }
76  return iter_ == rhs.iter_;
77  }
78  DBGraphEdge &dereference() const;
83  };
84 
86  return adjacency_iterator(graph, vertex_id_);
87  }
89  return adjacency_iterator();
90  }
91 
93  return edge_iterator(graph, this);
94  }
96  return edge_iterator();
97  }
98 
99  bool HasAdjacencies(DBGraph *graph) const;
100 
101  void set_vertex(const Vertex &vertex_id) {
102  vertex_id_ = vertex_id;
103  }
104 
106  vertex_id_ = NULL;
107  }
108 
109  bool IsVertexValid() {
110  return (vertex_id_ != NULL);
111  }
112 
113  Vertex vertex() const { return vertex_id_; }
114 
115  void set_visited(uint64_t current_graph_walk_num) {
116  visited_at_ = current_graph_walk_num;
117  }
118 
119  bool visited(uint64_t current_graph_walk_num) {
120  return (visited_at_ == current_graph_walk_num);
121  }
122 
123  virtual std::string ToString() const = 0;
124 
125 private:
127  uint64_t visited_at_;
128 };
129 
130 #endif
boost::graph_traits< graph_t >::adjacency_iterator adjacency_iterator
Definition: db_graph_base.h:61
boost::graph_traits< graph_t >::vertex_descriptor vertex_descriptor
Definition: db_graph_base.h:59
boost::graph_traits< graph_t >::edge_descriptor edge_descriptor
Definition: db_graph_base.h:60
boost::graph_traits< graph_t >::out_edge_iterator out_edge_iterator
Definition: db_graph_base.h:63
DBGraphBase::adjacency_iterator iter_
DBGraphVertex & dereference() const
bool equal(const adjacency_iterator &rhs) const
DBGraphBase::adjacency_iterator end_
friend class boost::iterator_core_access
DBGraphBase::out_edge_iterator end_
DBGraphBase::out_edge_iterator iter_
DBGraphEdge & dereference() const
DBGraphVertex * target() const
bool equal(const edge_iterator &rhs) const
friend class boost::iterator_core_access
bool visited(uint64_t current_graph_walk_num)
void set_visited(uint64_t current_graph_walk_num)
DBGraphBase::edge_descriptor Edge
uint64_t visited_at_
Vertex vertex() const
void VertexInvalidate()
edge_iterator edge_list_begin(DBGraph *graph)
adjacency_iterator end(DBGraph *graph)
virtual std::string ToString() const =0
DBGraphBase::vertex_descriptor Vertex
adjacency_iterator begin(DBGraph *graph)
bool HasAdjacencies(DBGraph *graph) const
edge_iterator edge_list_end(DBGraph *graph)
void set_vertex(const Vertex &vertex_id)