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