CXXGraph  0.4.0
CXXGraph is a header only, that manages the Graphs and it's algorithm in C++
UndirectedWeightedEdge.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_UNDIRECTEDWEIGHTEDEDGE_H__
21 #define __CXXGRAPH_UNDIRECTEDWEIGHTEDEDGE_H__
22 
23 #pragma once
24 
25 #include "UndirectedEdge.hpp"
26 #include "Weighted.hpp"
27 
28 namespace CXXGRAPH
29 {
30  //Foward Declaration
31  template <typename T>
32  class DirectedWeightedEdge;
33 
34  template <typename T>
35  class UndirectedWeightedEdge;
36 
37  // ostream operator
38  template <typename T>
39  std::ostream &operator<<(std::ostream &o, const UndirectedWeightedEdge<T> &edge);
40 
41  template <typename T>
43  {
44  public:
45  UndirectedWeightedEdge(const unsigned long id, const Node<T> &node1, const Node<T> &node2, const double weight);
46  UndirectedWeightedEdge(const unsigned long id, const std::pair<const Node<T> *, const Node<T> *> &nodepair, const double weight);
47  UndirectedWeightedEdge(const UndirectedEdge<T> &edge, const double weight);
48  UndirectedWeightedEdge(const Edge<T> &edge, const double weight);
50  UndirectedWeightedEdge(const Edge<T> &edge);
52  virtual ~UndirectedWeightedEdge() = default;
53  const std::optional<bool> isWeighted() const override;
54  //operator
55  explicit operator DirectedWeightedEdge<T>() const { return DirectedWeightedEdge<T>(Edge<T>::getId(), Edge<T>::getNodePair(), Weighted::getWeight()); }
56 
57  friend std::ostream &operator<<<>(std::ostream &os, const UndirectedWeightedEdge<T> &edge);
58  };
59 
60  template <typename T>
61  UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const unsigned long id, const Node<T> &node1, const Node<T> &node2, const double weight) : UndirectedEdge<T>(id, node1, node2), Weighted(weight)
62  {
63  }
64 
65  template <typename T>
66  UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const unsigned long id, const std::pair<const Node<T> *, const Node<T> *> &nodepair, const double weight) : UndirectedEdge<T>(id, nodepair), Weighted(weight)
67  {
68  }
69 
70  template <typename T>
71  UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const UndirectedEdge<T> &edge, const double weight) : UndirectedEdge<T>(edge), Weighted(weight)
72  {
73  }
74 
75  template <typename T>
76  UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const Edge<T> &edge, const double weight) : UndirectedEdge<T>(edge), Weighted(weight)
77  {
78  }
79 
80  template <typename T>
81  UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const UndirectedEdge<T> &edge) : UndirectedEdge<T>(edge), Weighted()
82  {
83  }
84 
85  template <typename T>
86  UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const Edge<T> &edge) : UndirectedEdge<T>(edge), Weighted()
87  {
88  }
89 
90  template <typename T>
91  UndirectedWeightedEdge<T>::UndirectedWeightedEdge(const DirectedWeightedEdge<T> &edge) : UndirectedEdge<T>(edge), Weighted(edge.getWeight())
92  {
93  }
94 
95  template <typename T>
96  const std::optional<bool> UndirectedWeightedEdge<T>::isWeighted() const
97  {
98  return true;
99  }
100 
101  template <typename T>
102  std::ostream &operator<<(std::ostream &os, const UndirectedWeightedEdge<T> &edge)
103  {
104  os << "((Node: " << edge.getNode1().getId() << ")) <----- |Edge: #" << edge.getId() << " W:" << edge.getWeight() << "|-----> ((Node: " << edge.getNode2().getId() << "))";
105  return os;
106  }
107 
108 }
109 
110 #endif // __CXXGRAPH_UNDIRECTEDWEIGHTEDEDGE_H__
Definition: DirectedWeightedEdge.hpp:42
Definition: Edge.hpp:39
Definition: Node.hpp:38
Definition: UndirectedEdge.hpp:39
Definition: UndirectedWeightedEdge.hpp:43
Definition: Weighted.hpp:28