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