OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
policy_graph.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
6 
7 #include <boost/graph/graphviz.hpp>
8 
11 
12 using namespace std;
13 using namespace boost;
14 
15 void PolicyGraph::WriteDot(const string &fname) const {
16  std::ofstream f(fname.c_str());
17 #if 0
18  write_graphviz(f, root_);
19 #endif
20  f.close();
21 }
22 
24  entry->set_vertex(add_vertex(root_));
25  PolicyGraphBase::VertexProperties &vertex = root_[entry->vertex()];
26  vertex.entry = entry;
27 }
28 
30  remove_vertex(entry->vertex(), root_);
31 }
32 
35  PolicyGraph::Edge edge_id;
36  bool added;
37  boost::tie(edge_id, added) = add_edge(lhs->vertex(), rhs->vertex(), root_);
38  assert(added);
39  return edge_id;
40 }
41 
43  remove_edge(lhs->vertex(), rhs->vertex(), root_);
44 }
45 
47  PolicyGraphBase::EdgeProperties &properties = root_[edge->edge_id()];
48  properties.edge = edge;
49 }
50 
52  const PolicyGraphVertex *tgt) {
53  edge_descriptor edge_id;
54  bool exists;
55  boost::tie(edge_id, exists) = edge(src->vertex(), tgt->vertex(), root_);
56  if (!exists) {
57  return NULL;
58  }
59  return root_[edge_id].edge;
60 }
61 
63  root_.clear();
64 }
65 
66 size_t PolicyGraph::vertex_count() const {
67  return num_vertices(root_);
68 }
69 
70 size_t PolicyGraph::edge_count() const {
71  return num_edges(root_);
72 }
73 
75  return open_vertex_list_.begin();
76 }
77 
79  return open_vertex_list_.end();
80 }
81 
83  open_vertex_list_.push_back(*vertex);
84 }
85 
87  assert(vertex->open_vertex_.is_linked());
88  open_vertex_list_.erase(open_vertex_list_.iterator_to(*vertex));
89 }
90 
92  Vertex v = *(vertices(root_).first);
93  return root_[v].entry;
94 }
95 
97  PolicyGraphEdge *edge = open_->in_edge(graph_);
98  open_ = edge->source(graph_);
99 }
100 
101 bool
103  const open_vertex_reverse_iterator &rhs) const {
104  if (graph_ == NULL) {
105  return (graph_ == rhs.graph_);
106  }
107 
108  if (rhs.graph_ == NULL) {
109  return open_ == graph_->GetRoot();
110  }
111 
112  return open_ == rhs.open_;
113 }
114 
117  if (graph_ == NULL || open_ == NULL) {
118  return make_pair((PolicyGraphVertex *)0, (PolicyGraphEdge *)0);
119  }
120  PolicyGraphVertex *vertex = NULL;
121  PolicyGraphEdge *edge = NULL;
122  edge = open_->in_edge(graph_);
123  vertex = edge->source(graph_);
124  return std::make_pair(vertex, edge);
125 }
boost::intrusive::list_member_hook open_vertex_
Definition: policy_vertex.h:33
PolicyGraphBase::edge_descriptor Edge
Definition: policy_graph.h:19
boost::graph_traits< graph_t >::edge_descriptor edge_descriptor
void RemoveNode(PolicyGraphVertex *entry)
Definition: policy_graph.cc:29
OpenVertexList::iterator OpenVertexIterator
Definition: policy_graph.h:26
PolicyGraphVertex * source(PolicyGraph *graph)
Definition: policy_edge.cc:13
std::pair< PolicyGraphVertex *, PolicyGraphEdge * > OpenVertexPathPair
Definition: policy_graph.h:67
PolicyGraphVertex * GetRoot() const
Definition: policy_graph.cc:91
OpenVertexIterator open_vertex_end()
Definition: policy_graph.cc:78
void AddNode(PolicyGraphVertex *entry)
Definition: policy_graph.cc:23
void SetEdgeProperty(PolicyGraphEdge *edge)
Definition: policy_graph.cc:46
void WriteDot(const std::string &fname) const
Definition: policy_graph.cc:15
PolicyGraphBase::vertex_descriptor Vertex
Definition: policy_graph.h:20
bool equal(const open_vertex_reverse_iterator &rhs) const
Edge Link(PolicyGraphVertex *lhs, PolicyGraphVertex *rhs)
Definition: policy_graph.cc:34
void clear()
Definition: policy_graph.cc:62
void AddOpenVertex(PolicyGraphVertex *vertex)
Definition: policy_graph.cc:82
Vertex vertex() const
OpenVertexPathPair dereference() const
Edge edge_id() const
Definition: policy_edge.h:22
size_t edge_count() const
Definition: policy_graph.cc:70
void Unlink(PolicyGraphVertex *lhs, PolicyGraphVertex *rhs)
Definition: policy_graph.cc:42
size_t vertex_count() const
Definition: policy_graph.cc:66
void RemoveOpenVertex(PolicyGraphVertex *vertex)
Definition: policy_graph.cc:86
void set_vertex(const Vertex &vertex_id)
OpenVertexIterator open_vertex_begin()
Definition: policy_graph.cc:74
PolicyGraphEdge * GetEdge(const PolicyGraphVertex *src, const PolicyGraphVertex *tgt)
Definition: policy_graph.cc:51