Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
WeightedEdge.hpp
Go to the documentation of this file.
1
6// Copyright (c) 2017 Czech Technical University in Prague | Faculty of Information Technology. All rights reserved.
7
8#pragma once
9
10#include <ostream>
11#include <alib/pair>
12#include <object/Object.h>
13#include <alib/tuple>
14
15#include <edge/EdgeFeatures.hpp>
16#include <edge/EdgeBase.hpp>
17
18namespace edge {
19
20template<typename TNode, typename TWeight>
21class WeightedEdge : public ext::pair<TNode, TNode>, public EdgeBase {
22// ---------------------------------------------------------------------------------------------------------------------
23 public:
24 using node_type = TNode;
25 using weight_type = TWeight;
27
28// ---------------------------------------------------------------------------------------------------------------------
29
30 protected:
31 TWeight m_weight;
32
33// =====================================================================================================================
34// Constructor, Destructor, Operators
35
36 public:
37 explicit WeightedEdge(TNode _first, TNode _second, TWeight weight);
38
39// ---------------------------------------------------------------------------------------------------------------------
40
41 TWeight weight() const;
42 void weight(TWeight &&weight);
43
44// =====================================================================================================================
45// EdgeBase interface
46
47 public:
48 auto operator <=> (const WeightedEdge &other) const {
49 return ext::tie(this->first, this->second, m_weight) <=> ext::tie(other.first, other.second, other.m_weight);
50 }
51
52 bool operator == (const WeightedEdge &other) const {
53 return ext::tie(this->first, this->second, m_weight) == ext::tie(other.first, other.second, other.m_weight);
54 }
55
56 void operator>>(ext::ostream &ostream) const override;
57
58// =====================================================================================================================
59 public:
60
61 virtual std::string name() const;
62
63// ---------------------------------------------------------------------------------------------------------------------
64};
65// =====================================================================================================================
66
67template<typename TNode, typename TWeight>
68WeightedEdge<TNode, TWeight>::WeightedEdge(TNode _first, TNode _second, TWeight weight)
69 : ext::pair<TNode, TNode>(_first, _second), m_weight(weight) {
70
71}
72
73// ---------------------------------------------------------------------------------------------------------------------
74
75template<typename TNode, typename TWeight>
77 return m_weight;
78}
79
80template<typename TNode, typename TWeight>
82 m_weight = std::forward<TWeight>(weight);
83}
84
85// ---------------------------------------------------------------------------------------------------------------------
86
87template<typename TNode, typename TWeight>
89 return "WeightedEdge";
90}
91
92// ---------------------------------------------------------------------------------------------------------------------
93
94template<typename TNode, typename TWeight>
96 ostream << "(" << name() << "(first=" << this->first << ", second=" << this->second << ", weight="
97 << m_weight << "))";
98}
99
100// ---------------------------------------------------------------------------------------------------------------------
101
102} // namespace edge
103
104// =====================================================================================================================
105
Definition: EdgeBase.hpp:15
Definition: WeightedEdge.hpp:21
TNode node_type
Definition: WeightedEdge.hpp:24
WeightedEdge(TNode _first, TNode _second, TWeight weight)
Definition: WeightedEdge.hpp:68
auto operator<=>(const WeightedEdge &other) const
Definition: WeightedEdge.hpp:48
TWeight m_weight
Definition: WeightedEdge.hpp:31
virtual std::string name() const
Definition: WeightedEdge.hpp:88
void operator>>(ext::ostream &ostream) const override
Definition: WeightedEdge.hpp:95
bool operator==(const WeightedEdge &other) const
Definition: WeightedEdge.hpp:52
TWeight weight_type
Definition: WeightedEdge.hpp:25
TWeight weight() const
Definition: WeightedEdge.hpp:76
Definition: ostream.h:14
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
p second
Definition: ToRegExpAlgebraic.h:126
Definition: CapacityEdge.hpp:18
Definition: sigHandler.cpp:20
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218