dyng
DynamicGraphLayout
edge.h
1 /*
2  Copyright 2020 František Bráblík
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 #pragma once
17 
18 #include "coords.h"
19 #include "identifiers.h"
20 #include "container.h"
21 
22 namespace dyng {
23 
33 class edge;
34 
40 template<typename ConnectedNode>
41 class basic_edge {
42 public:
45  : m_one(one)
46  , m_two(two)
47  , m_id(id) {}
48 
50  node_id one_id() const { return m_one; }
51 
53  node_id two_id() const { return m_two; }
54 
55  edge_id id() const { return m_id; }
56 
58  bool is_new() const { return m_newly_added; }
59 
61  void is_new(bool value) { m_newly_added = value; }
62 
64  bool is_old() const { return m_to_be_deleted; }
65 
67  void is_old(bool value) { m_to_be_deleted = value; }
68 
70 
76  float alpha() const { return m_alpha; }
77 
79  void alpha(float value) { m_alpha = value; }
80 
82  ConnectedNode& node_one() { return m_container->at(m_one); }
83 
85  const ConnectedNode& node_one() const { return m_container->at(m_one); }
86 
88  ConnectedNode& node_two() { return m_container->at(m_two); }
89 
91  const ConnectedNode& node_two() const { return m_container->at(m_two); }
92 
94 
104  m_container = cont;
105  }
106 
107 private:
108  node_id m_one;
109  node_id m_two;
110  edge_id m_id;
111  float m_alpha = 1.0;
112  bool m_newly_added = false;
113  bool m_to_be_deleted = false;
114 
115  detail::container<ConnectedNode, node_id>* m_container = nullptr;
116 };
117 
118 
119 class edge : public basic_edge<node> {
120 public:
122  edge(edge_id id, node_id one, node_id two)
123  : basic_edge(id, one, two) {}
124 };
125 
126 } // namespace dyng
dyng::basic_edge::alpha
void alpha(float value)
Sets the current alpha value.
Definition: edge.h:79
dyng::basic_edge::is_new
void is_new(bool value)
Sets if the node is new in its current state.
Definition: edge.h:61
dyng::edge_id
Type used as an identifier for edges.
Definition: identifiers.h:87
dyng::basic_edge::node_one
ConnectedNode & node_one()
Returns a reference to one connected node.
Definition: edge.h:82
dyng::basic_edge::one_id
node_id one_id() const
Returns the id of one connected node.
Definition: edge.h:50
dyng::basic_edge::set_ptr
void set_ptr(detail::container< ConnectedNode, node_id > *cont)
Sets the pointer to the object detail::container.
Definition: edge.h:103
dyng::detail::container
Contains a vector of graph entities and a map to them.
Definition: container.h:34
dyng::basic_edge::basic_edge
basic_edge(edge_id id, node_id one, node_id two)
Sets the id of the edge and ids of two connected nodes.
Definition: edge.h:44
dyng::basic_edge::is_new
bool is_new() const
Returns if the edge is new in its current state.
Definition: edge.h:58
dyng::basic_edge::node_one
const ConnectedNode & node_one() const
Returns a const reference to one connected node.
Definition: edge.h:85
dyng::edge
Definition: edge.h:119
dyng::basic_edge::is_old
void is_old(bool value)
Sets if the node is going to be deleted in the next state.
Definition: edge.h:67
dyng::basic_edge::alpha
float alpha() const
Returns current alpha value.
Definition: edge.h:76
dyng::basic_edge::two_id
node_id two_id() const
Returns the id of the other connected node.
Definition: edge.h:53
dyng::basic_edge::node_two
ConnectedNode & node_two()
Returns a reference to the other connected node.
Definition: edge.h:88
dyng::basic_edge::node_two
const ConnectedNode & node_two() const
Returns a const reference to the other connected node.
Definition: edge.h:91
dyng::basic_edge::is_old
bool is_old() const
Returns if the edge is going to be deleted in the next state.
Definition: edge.h:64
dyng::edge::edge
edge(edge_id id, node_id one, node_id two)
Sets the id of the edge and ids of two connected nodes.
Definition: edge.h:122
dyng::node_id
Type used as an identifier for nodes.
Definition: identifiers.h:77
dyng::basic_edge
Definition: edge.h:41