GraphLibrary  0.0.1
A simple library that implements various graph algorithms.
 All Classes Namespaces Files Functions Variables Typedefs Macros
Node.hpp
Go to the documentation of this file.
1 #ifndef GL_NODE_HPP
2 #define GL_NODE_HPP
3 
4 #include "Color.hpp"
5 
6 namespace gl {
7 
9 // Node Class declaration
11 
17 template <class SCALAR>
18 class Node
19 {
20 public:
21  using val_t = SCALAR;
23 
24  Node(const idx_t &id = 0, const val_t &capacity = 1, const gl::Color& color = Color("white"), const std::string &label = "", const float& x = 0., const float& y = 0.) : id_(id), label_(label), capacity_(capacity),
26  position_(std::make_pair(x,y)) {}
27 
28  Node(const Node<SCALAR>&) = default;
29  Node(Node<SCALAR>&&) noexcept = default;
30  Node &operator=(const Node<SCALAR>&) = default;
31  Node &operator=(Node<SCALAR>&&) noexcept = default;
32  ~Node() = default;
33 
38  bool operator== (const Node& rhs) const;
43  bool operator!= (const Node& rhs) const;
44 
54  inline idx_t id() const;
59  inline void id(const idx_t &id);
61 
70  inline std::string label() const;
75  inline void label(const std::string &label);
77 
86  inline val_t capacity() const;
91  inline void capacity(const val_t &capacity);
93 
102  inline Color color() const;
107  inline void color(const Color &color);
109 
118  inline idx_t inDegree() const;
123  inline void inDegreeIncrement(const idx_t &increment = 1);
128  inline void inDegreeDecrement(const idx_t &decrement = 1);
130 
139  inline idx_t outDegree() const;
144  inline void outDegreeIncrement(const idx_t &increment = 1);
149  inline void outDegreeDecrement(const idx_t &decrement = 1);
151 
152 
160  inline std::pair<float, float> position() const;
165  inline void position(const std::pair<float, float> &pos);
167 
168 private:
170  std::string label_;
175  std::pair<float, float> position_;
176 };
177 
179 // Node function implementations
181 
182 // equality operator
183 template <class SCALAR>
184 bool Node<SCALAR>::operator== (const Node<SCALAR>& rhs) const
185 {
186  return id_ == rhs.id_
187  && label_ == rhs.label_
188  && capacity_ == rhs.capacity_
189  && color_ == rhs.color_
190  && inDegree_ == rhs.inDegree_
191  && outDegree_ == rhs.outDegree_
192  && position_ == rhs.position_;
193 }
194 // inequality operator
195 template <class SCALAR>
197 {
198  return !operator==(rhs);
199 }
200 
201 // getter for id
202 template <class SCALAR>
203 inline typename Node<SCALAR>::idx_t Node<SCALAR>::id() const
204 {
205  return id_;
206 }
207 // setter for id
208 template <class SCALAR>
209 inline void Node<SCALAR>::id(const idx_t &id)
210 {
211  id_ = id;
212 }
213 
214 // getter for label
215 template <class SCALAR>
216 inline std::string Node<SCALAR>::label() const
217 {
218  return label_;
219 }
220 // setter for label
221 template <class SCALAR>
222 inline void Node<SCALAR>::label(const std::string &label)
223 {
224  label_ = label;
225 }
226 
227 // getter for capacity
228 template <class SCALAR>
230 {
231  return capacity_;
232 }
233 // setter for capacity
234 template <class SCALAR>
236 {
238 }
239 
240 // getter for inDegree
241 template <class SCALAR>
243 {
244  return inDegree_;
245 }
246 // increment for inDegree
247 template <class SCALAR>
248 inline void Node<SCALAR>::inDegreeIncrement(const idx_t &increment)
249 {
250  inDegree_ += increment;
251 }
252 // decrement for inDegree
253 template <class SCALAR>
254 inline void Node<SCALAR>::inDegreeDecrement(const idx_t &decrement)
255 {
256  GL_ASSERT(decrement <= inDegree_,"Node::inDegreeDecrement | Decrement results in negative inDegree")
257  inDegree_ -= decrement;
258 }
259 
260 // getter for outDegree
261 template <class SCALAR>
263 {
264  return outDegree_;
265 }
266 // increment for outDegree
267 template <class SCALAR>
268 inline void Node<SCALAR>::outDegreeIncrement(const idx_t &increment)
269 {
270  outDegree_ += increment;
271 }
272 // decrement for outDegree
273 template <class SCALAR>
274 inline void Node<SCALAR>::outDegreeDecrement(const idx_t &decrement)
275 {
276  GL_ASSERT(decrement <= outDegree_,"Node::outDegreeDecrement | Decrement results in negative outDegree")
277  outDegree_ -= decrement;
278 }
279 
280 // getter for color object
281 template <class SCALAR>
283 {
284  return color_;
285 }
286 // setter for color object
287 template <class SCALAR>
288 inline void Node<SCALAR>::color(const Color &color)
289 {
290  color_ = color;
291 }
292 
293 // getter for position
294 template <class SCALAR>
295 inline std::pair<float, float> Node<SCALAR>::position() const
296 {
297  return position_;
298 }
299 // setter for position
300 template <class SCALAR>
301 inline void Node<SCALAR>::position(const std::pair<float, float> &pos)
302 {
303  position_ = pos;
304 }
305 
306 } // namespace gl
307 
308 #endif // GL_NODE_HPP
idx_t inDegree() const
Gets the in-degree of a node.
Definition: Node.hpp:242
Node(const idx_t &id=0, const val_t &capacity=1, const gl::Color &color=Color("white"), const std::string &label="", const float &x=0., const float &y=0.)
Definition: Node.hpp:24
bool operator!=(const Node &rhs) const
Check whether two nodes are not equal.
Definition: Node.hpp:196
std::pair< float, float > position() const
Get Position of this node.
Definition: Node.hpp:295
Stores an RGBA Color.
Definition: Color.hpp:21
idx_t inDegree_
In-degree */.
Definition: Node.hpp:173
val_t capacity_
Node capacity */.
Definition: Node.hpp:171
bool operator==(const Node &rhs) const
Check whether two nodes are equal.
Definition: Node.hpp:184
idx_t id_
Node ID */.
Definition: Node.hpp:169
void inDegreeDecrement(const idx_t &decrement=1)
Decrements the node in-degree.
Definition: Node.hpp:254
idx_t outDegree() const
Gets the out-degree of a node.
Definition: Node.hpp:262
Represents a Node in a Graph.
Definition: Node.hpp:18
Color color() const
Gets the edge's color.
Definition: Node.hpp:282
std::string label_
Node label */.
Definition: Node.hpp:170
SCALAR val_t
Value type.
Definition: Node.hpp:21
#define GL_ASSERT(EXPR, ERROR_MSG)
Custom assert that supports attaching a message.
Definition: gl_assert.hpp:14
val_t capacity() const
Gets the capacity of the node.
Definition: Node.hpp:229
void outDegreeDecrement(const idx_t &decrement=1)
Decrements the node out-degree.
Definition: Node.hpp:274
std::size_t index_type
Definition: gl_base.hpp:18
idx_t id() const
Checks whether an edge exists.
Definition: Node.hpp:203
std::pair< float, float > position_
Position of node.
Definition: Node.hpp:175
void outDegreeIncrement(const idx_t &increment=1)
Increments the node out-degree.
Definition: Node.hpp:268
idx_t outDegree_
Out-degree */.
Definition: Node.hpp:174
Color color_
Node color */.
Definition: Node.hpp:172
std::string label() const
Gets the label of a node.
Definition: Node.hpp:216
gl::index_type idx_t
Index type.
Definition: Node.hpp:22
void inDegreeIncrement(const idx_t &increment=1)
Increments the node in-degree.
Definition: Node.hpp:248