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