GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
Edge.hpp
Go to the documentation of this file.
1 #ifndef GL_EDGE_HPP
2 #define GL_EDGE_HPP
3 
4 #include "Color.hpp"
5 
6 namespace gl {
7 
9 // Edge Class declaration
11 
17 template <class SCALAR = int>
18 class Edge
19 {
20 public:
21  using val_t = SCALAR;
23 
31  Edge(const idx_t &src = 0, const idx_t &dest = 0, const val_t &weight = 0, const Color &color = Color("black"), const bool &exists = false) : src_(src), dest_(dest), weight_(weight), exists_(exists), color_(color) {}
32 
33  Edge(const Edge<SCALAR>&) = default;
34  Edge(Edge<SCALAR>&&) noexcept = default;
35  Edge &operator=(const Edge<SCALAR>&) = default;
36  Edge &operator=(Edge<SCALAR>&&) noexcept = default;
37  ~Edge() = default;
38 
39 
44  bool operator== (const Edge& rhs) const;
49  bool operator!= (const Edge& rhs) const;
50 
61  inline bool exists() const;
66  inline void exists(bool exists);
68 
77  inline idx_t source() const;
82  inline void source(idx_t src);
84 
93  inline idx_t dest() const;
98  inline void dest(idx_t dest);
100 
109  inline val_t weight() const;
114  inline void weight(val_t weight);
124  inline Color color() const;
129  inline void color(const Color &color);
131 
132 private:
136  bool exists_;
138 };
139 
141 // Edge function implementations
143 
144 // equality operator
145 template <class SCALAR>
146 bool Edge<SCALAR>::operator== (const Edge<SCALAR>& rhs) const
147 {
148  return src_ == rhs.src_
149  && dest_ == rhs.dest_
150  && weight_ == rhs.weight_
151  && exists_ == rhs.exists_
152  && color_ == rhs.color_;
153 }
154 // inequality operator
155 template <class SCALAR>
157 {
158  return !operator==(rhs);
159 }
160 
161 // getter for exists
162 template <class SCALAR>
163 inline bool Edge<SCALAR>::exists() const {
164  return exists_;
165 }
166 
167 // setter for exists
168 template <class SCALAR>
169 inline void Edge<SCALAR>::exists(bool exists) {
170  exists_ = exists;
171 }
172 
173 // getter for src
174 template <class SCALAR>
175 inline typename Edge<SCALAR>::idx_t Edge<SCALAR>::source() const {
176  return src_;
177 }
178 // setter for src
179 template <class SCALAR>
180 inline void Edge<SCALAR>::source(idx_t src) {
181  src_ = src;
182 }
183 
184 // getter for dest
185 template <class SCALAR>
186 inline typename Edge<SCALAR>::idx_t Edge<SCALAR>::dest() const {
187  return dest_;
188 }
189 // setter for dest
190 template <class SCALAR>
192  dest_ = dest;
193 }
194 
195 // getter for weight
196 template <class SCALAR>
197 inline typename Edge<SCALAR>::val_t Edge<SCALAR>::weight() const {
198  return weight_;
199 }
200 // setter for weight
201 template <class SCALAR>
203  weight_ = weight;
204 }
205 
206 // getter for color object
207 template <class SCALAR>
209  return color_;
210 }
211 // setter for color object
212 template <class SCALAR>
213 inline void Edge<SCALAR>::color(const Color& color) {
214  color_ = color;
215 }
216 
217 } // namespace gl
218 
219 #endif // GL_EDGE_HPP
Stores an RGBA Color.
Definition: Color.hpp:21
idx_t src_
Source index.
Definition: Edge.hpp:133
Color color() const
Gets the edge's color.
Definition: Edge.hpp:208
bool operator!=(const Edge &rhs) const
Check whether two edges are not equal.
Definition: Edge.hpp:156
bool exists_
Edge existance.
Definition: Edge.hpp:136
val_t weight_
Edge weight.
Definition: Edge.hpp:135
std::size_t index_type
Definition: gl_base.hpp:18
Edge(const idx_t &src=0, const idx_t &dest=0, const val_t &weight=0, const Color &color=Color("black"), const bool &exists=false)
Construct Edge from data.
Definition: Edge.hpp:31
idx_t source() const
Gets the index of the source of the edge.
Definition: Edge.hpp:175
Represents an Edge in a Graph.
Definition: Edge.hpp:18
bool exists() const
Checks whether an edge exists.
Definition: Edge.hpp:163
SCALAR val_t
Value type.
Definition: Edge.hpp:21
idx_t dest() const
Gets the index of the destination of the edge.
Definition: Edge.hpp:186
idx_t dest_
Destination index.
Definition: Edge.hpp:134
gl::index_type idx_t
Index type.
Definition: Edge.hpp:22
Color color_
Edge color.
Definition: Edge.hpp:137
val_t weight() const
Gets the weight of the edge.
Definition: Edge.hpp:197
bool operator==(const Edge &rhs) const
Check whether two edges are equal.
Definition: Edge.hpp:146