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