OpenSDN source code
policy_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_policy_graph_vertex_h
7 #define ctrlplane_policy_graph_vertex_h
8 
9 #include <boost/intrusive/list.hpp>
11 
12 class PolicyGraph;
13 class PolicyGraphEdge;
14 class PolicyGraphVertex;
15 
16 namespace boost {
17 template <>
18 struct is_POD<PolicyGraphEdge> : public false_type {};
19 
20 template <>
21 struct is_POD<PolicyGraphVertex> : public false_type {};
22 }
23 
25 public:
28  enum VertexType {
30  POLICY_ACTION = 2
31  };
32 
33  // Graph Vertex is stored in OpenVertexList for quick access
34  boost::intrusive::list_member_hook<> open_vertex_;
35 
36  class adjacency_iterator : public boost::iterator_facade<
37  adjacency_iterator, PolicyGraphVertex, boost::forward_traversal_tag
38  > {
39  public:
42  private:
44  void increment() {
45  ++iter_;
46  }
47  bool equal(const adjacency_iterator &rhs) const {
48  if (graph_ == NULL) {
49  return (rhs.graph_ == NULL);
50  }
51  if (rhs.graph_ == NULL) {
52  return iter_ == end_;
53  }
54  return iter_ == rhs.iter_;
55  }
60  };
61 
62  class edge_iterator : public boost::iterator_facade<
63  edge_iterator, PolicyGraphEdge, boost::forward_traversal_tag
64  > {
65  public:
66  edge_iterator();
68  PolicyGraphVertex *target() const;
69  private:
71  void increment() {
72  ++iter_;
73  }
74  bool equal(const edge_iterator &rhs) const {
75  if (graph_ == NULL) {
76  return (rhs.graph_ == NULL);
77  }
78  if (rhs.graph_ == NULL) {
79  return iter_ == end_;
80  }
81  return iter_ == rhs.iter_;
82  }
88  };
89 
91  return adjacency_iterator(graph, vertex_id_);
92  }
94  return adjacency_iterator();
95  }
96 
98 
100 
102  return edge_iterator(graph, this);
103  }
105  return edge_iterator();
106  }
107 
108  void set_vertex(const Vertex &vertex_id) {
109  vertex_id_ = vertex_id;
110  }
111 
112  Vertex vertex() const { return vertex_id_; }
113 
114  virtual VertexType Type() const = 0;
115 
116 private:
118 };
119 
120 #endif // ctrlplane_policy_graph_vertex_h
boost::graph_traits< graph_t >::adjacency_iterator adjacency_iterator
boost::graph_traits< graph_t >::vertex_descriptor vertex_descriptor
boost::graph_traits< graph_t >::out_edge_iterator out_edge_iterator
boost::graph_traits< graph_t >::edge_descriptor edge_descriptor
PolicyGraphBase::adjacency_iterator iter_
Definition: policy_vertex.h:58
PolicyGraphVertex & dereference() const
PolicyGraphBase::adjacency_iterator end_
Definition: policy_vertex.h:59
friend class boost::iterator_core_access
Definition: policy_vertex.h:43
bool equal(const adjacency_iterator &rhs) const
Definition: policy_vertex.h:47
PolicyGraphVertex * target() const
bool equal(const edge_iterator &rhs) const
Definition: policy_vertex.h:74
PolicyGraphEdge & dereference() const
PolicyGraphBase::out_edge_iterator iter_
Definition: policy_vertex.h:86
friend class boost::iterator_core_access
Definition: policy_vertex.h:70
PolicyGraphBase::out_edge_iterator end_
Definition: policy_vertex.h:87
adjacency_iterator end(PolicyGraph *graph)
Definition: policy_vertex.h:93
PolicyGraphBase::edge_descriptor Edge
Definition: policy_vertex.h:27
PolicyGraphEdge * in_edge(PolicyGraph *graph)
adjacency_iterator begin(PolicyGraph *graph)
Definition: policy_vertex.h:90
boost::intrusive::list_member_hook open_vertex_
Definition: policy_vertex.h:34
PolicyGraphVertex * parent_vertex(PolicyGraph *graph)
Vertex vertex() const
void set_vertex(const Vertex &vertex_id)
edge_iterator edge_list_begin(PolicyGraph *graph)
edge_iterator edge_list_end(PolicyGraph *graph)
PolicyGraphBase::vertex_descriptor Vertex
Definition: policy_vertex.h:26
virtual VertexType Type() const =0