CXXGraph  0.4.0
CXXGraph is a header only, that manages the Graphs and it's algorithm in C++
DirectedEdge.hpp
1 /***********************************************************/
2 /*** ______ ____ ______ _ ***/
3 /*** / ___\ \/ /\ \/ / ___|_ __ __ _ _ __ | |__ ***/
4 /*** | | \ / \ / | _| '__/ _` | '_ \| '_ \ ***/
5 /*** | |___ / \ / \ |_| | | | (_| | |_) | | | | ***/
6 /*** \____/_/\_\/_/\_\____|_| \__,_| .__/|_| |_| ***/
7 /*** |_| ***/
8 /***********************************************************/
9 /*** Header-Only C++ Library for Graph ***/
10 /*** Representation and Algorithms ***/
11 /***********************************************************/
12 /*** Author: ZigRazor ***/
13 /*** E-Mail: zigrazor@gmail.com ***/
14 /***********************************************************/
15 /*** Collaboration: ----------- ***/
16 /***********************************************************/
17 /*** License: MPL v2.0 ***/
18 /***********************************************************/
19 
20 #ifndef __CXXGRAPH_DIRECTEDEDGE_H__
21 #define __CXXGRAPH_DIRECTEDEDGE_H__
22 
23 #pragma once
24 
25 #include "Edge.hpp"
26 
27 namespace CXXGRAPH
28 {
29  template <typename T>
30  class UndirectedEdge;
31 
32  template <typename T>
33  class DirectedEdge;
34  // ostream operator
35  template <typename T>
36  std::ostream &operator<<(std::ostream &o, const DirectedEdge<T> &edge);
37  template <typename T>
38  class DirectedEdge : public Edge<T>
39  {
40  public:
41  DirectedEdge(const unsigned long id, const Node<T> &node1, const Node<T> &node2);
42  DirectedEdge(const unsigned long id, const std::pair<const Node<T> *, const Node<T> *> &nodepair);
43  DirectedEdge(const Edge<T> &edge);
44  virtual ~DirectedEdge() = default;
45  const Node<T> &getFrom() const;
46  const Node<T> &getTo() const;
47  const std::optional<bool> isDirected() const override;
48  const std::optional<bool> isWeighted() const override;
49  //operator
50  explicit operator UndirectedEdge<T>() const { return UndirectedEdge<T>(Edge<T>::getId(), Edge<T>::getNodePair()); }
51 
52  friend std::ostream &operator<<<>(std::ostream &os, const DirectedEdge<T> &edge);
53  };
54 
55  template <typename T>
56  DirectedEdge<T>::DirectedEdge(const unsigned long id, const Node<T> &node1, const Node<T> &node2) : Edge<T>(id, node1, node2)
57  {
58  }
59 
60  template <typename T>
61  DirectedEdge<T>::DirectedEdge(const unsigned long id, const std::pair<const Node<T> *, const Node<T> *> &nodepair) : Edge<T>(id, nodepair)
62  {
63  }
64 
65  template <typename T>
66  DirectedEdge<T>::DirectedEdge(const Edge<T> &edge) : DirectedEdge(edge.getId(), *(edge.getNodePair().first), *(edge.getNodePair().second))
67  {
68  }
69 
70  template <typename T>
71  const Node<T> &DirectedEdge<T>::getFrom() const
72  {
73  return *(Edge<T>::getNodePair().first);
74  }
75 
76  template <typename T>
77  const Node<T> &DirectedEdge<T>::getTo() const
78  {
79  return *(Edge<T>::getNodePair().second);
80  }
81 
82  template <typename T>
83  const std::optional<bool> DirectedEdge<T>::isDirected() const
84  {
85  return true;
86  }
87 
88  template <typename T>
89  const std::optional<bool> DirectedEdge<T>::isWeighted() const
90  {
91  return false;
92  }
93 
94 
95 
96  template <typename T>
97  std::ostream &operator<<(std::ostream &os, const DirectedEdge<T> &edge)
98  {
99  os << "((Node: " << edge.getFrom().getId() << ")) +----- |Edge: #" << edge.getId() << "|-----> ((Node: " << edge.getTo().getId() << "))";
100  return os;
101  }
102 }
103 
104 #endif // __CXXGRAPH_DIRECTEDEDGE_H__
Definition: DirectedEdge.hpp:39
Definition: Edge.hpp:39
Definition: Node.hpp:38
Definition: UndirectedEdge.hpp:39