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