CXXGraph  0.4.0
CXXGraph is a header only, that manages the Graphs and it's algorithm in C++
UndirectedEdge.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: AGPL v3.0 ***/
18 /***********************************************************/
19 
20 #ifndef __CXXGRAPH_UNDIRECTEDEDGE_H__
21 #define __CXXGRAPH_UNDIRECTEDEDGE_H__
22 
23 #pragma once
24 
25 #include "Edge.hpp"
26 
27 namespace CXXGRAPH
28 {
29 
30  template <typename T>
31  class UndirectedEdge;
32 
33  // ostream operator
34  template <typename T>
35  std::ostream &operator<<(std::ostream &o, const UndirectedEdge<T> &edge);
36 
37  template <typename T>
38  class UndirectedEdge : public Edge<T>
39  {
40  public:
41  UndirectedEdge(const unsigned long id, const Node<T> &node1, const Node<T> &node2);
42  UndirectedEdge(const unsigned long id, const std::pair<const Node<T> *, const Node<T> *> &nodepair);
43  UndirectedEdge(const Edge<T> &edge);
44  virtual ~UndirectedEdge() = default;
45  const Node<T> &getNode1() const;
46  const Node<T> &getNode2() const;
47  const std::optional<bool> isDirected() const override;
48  const std::optional<bool> isWeighted() const override;
49  //operator
50  explicit operator DirectedEdge<T>() const { return DirectedEdge<T>(Edge<T>::getId(), Edge<T>::getNodePair()); }
51 
52  friend std::ostream &operator<<<>(std::ostream &os, const UndirectedEdge<T> &edge);
53  };
54 
55  template <typename T>
56  UndirectedEdge<T>::UndirectedEdge(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  UndirectedEdge<T>::UndirectedEdge(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  UndirectedEdge<T>::UndirectedEdge(const Edge<T> &edge) : UndirectedEdge(edge.getId(), *(edge.getNodePair().first), *(edge.getNodePair().second))
67  {
68  }
69 
70  template <typename T>
71  const Node<T> &UndirectedEdge<T>::getNode1() const
72  {
73  return *(Edge<T>::getNodePair().first);
74  }
75 
76  template <typename T>
77  const Node<T> &UndirectedEdge<T>::getNode2() const
78  {
79  return *(Edge<T>::getNodePair().second);
80  }
81 
82  template <typename T>
83  const std::optional<bool> UndirectedEdge<T>::isDirected() const
84  {
85  return false;
86  }
87 
88  template <typename T>
89  const std::optional<bool> UndirectedEdge<T>::isWeighted() const
90  {
91  return false;
92  }
93 
94  template <typename T>
95  std::ostream &operator<<(std::ostream &os, const UndirectedEdge<T> &edge)
96  {
97  os << "((Node: " << edge.getNode1().getId() << ")) <----- |Edge: #" << edge.getId() << "|-----> ((Node: " << edge.getNode2().getId() << "))";
98  return os;
99  }
100 }
101 
102 
103 #endif // __CXXGRAPH_UNDIRECTEDEDGE_H__
Definition: DirectedEdge.hpp:39
Definition: Edge.hpp:39
Definition: Node.hpp:38
Definition: UndirectedEdge.hpp:39