Graph Cpp
Helper Graph class for C++ with CMake support
Loading...
Searching...
No Matches
Graph< vert_t, weight_t >::Edge Class Reference

Public Member Functions

 Edge ()=delete
 
 Edge (const std::pair< vert_t, vert_t > &edge_pair)
 
 Edge (const std::pair< vert_t, vert_t > &edge_pair, weight_t weight)
 
 Edge (const std::tuple< vert_t, vert_t, weight_t > &edge_tuple)
 
 Edge (const vert_t &start_vert, vert_t end_vert, weight_t weight)
 
 Edge (const vert_t start_vert, const vert_t &end_vert)
 
vert_t EndVert () const
 
bool IsWeighted () const
 
const std::string & Name () const
 
bool operator!= (const Edge &rhs) const
 
auto operator<=> (const Edge &rhs) const
 
bool operator== (const Edge &rhs) const
 
void SetWeight (weight_t new_weight)
 
vert_t StartVert () const
 
weight_t Weight () const
 

Private Attributes

vert_t end_vert_
 
vert_t start_vert_
 
weight_t weight_ = 0
 

Constructor & Destructor Documentation

◆ Edge() [1/6]

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
Graph< vert_t, weight_t >::Edge::Edge ( )
delete

◆ Edge() [2/6]

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
Graph< vert_t, weight_t >::Edge::Edge ( const vert_t start_vert,
const vert_t & end_vert )
inline
vert_t start_vert_
Definition graph.hpp:731
vert_t end_vert_
Definition graph.hpp:732
weight_t weight_
Definition graph.hpp:733

◆ Edge() [3/6]

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
Graph< vert_t, weight_t >::Edge::Edge ( const vert_t & start_vert,
vert_t end_vert,
weight_t weight )
inline

◆ Edge() [4/6]

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
Graph< vert_t, weight_t >::Edge::Edge ( const std::pair< vert_t, vert_t > & edge_pair)
inline
669 : start_vert_{edge_pair.first}, end_vert_{edge_pair.second} {}

◆ Edge() [5/6]

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
Graph< vert_t, weight_t >::Edge::Edge ( const std::pair< vert_t, vert_t > & edge_pair,
weight_t weight )
inline
672 : start_vert_{edge_pair.first},
673 end_vert_{edge_pair.second},
674 weight_{weight} {}

◆ Edge() [6/6]

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
Graph< vert_t, weight_t >::Edge::Edge ( const std::tuple< vert_t, vert_t, weight_t > & edge_tuple)
inline
vert_t EndVertFromTuple(const std::tuple< vert_t, vert_t, weight_t > &edge)
Definition graph.hpp:23
weight_t WeightFromTuple(const std::tuple< vert_t, vert_t, weight_t > &edge)
Definition graph.hpp:29
vert_t StartVertFromTuple(const std::tuple< vert_t, vert_t, weight_t > &edge)
Definition graph.hpp:17

Member Function Documentation

◆ EndVert()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
vert_t Graph< vert_t, weight_t >::Edge::EndVert ( ) const
inline
684{ return end_vert_; }
Here is the caller graph for this function:

◆ IsWeighted()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
bool Graph< vert_t, weight_t >::Edge::IsWeighted ( ) const
inline
681{ return weight_ != 0; }
Here is the caller graph for this function:

◆ Name()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
const std::string & Graph< vert_t, weight_t >::Edge::Name ( ) const
inline
703 {
704 static std::string name;
705
706 if constexpr (std::is_arithmetic_v<vert_t>) {
707 if (IsWeighted())
708 name = "[" + std::to_string(StartVert()) + "->" +
709 std::to_string(EndVert()) +
710 ", w: " + std::to_string(Weight()) + "]";
711 else
712 name = "[" + std::to_string(StartVert()) + "->" +
713 std::to_string(EndVert()) + "]";
714
715 // example: "[4->5]"
716
717 } else if constexpr (std::is_same_v<vert_t, std::string>) {
718 if (IsWeighted())
719 name = "['" + StartVert() + "'->'" + EndVert() +
720 "', w: " + std::to_string(Weight()) + "]";
721 else
722 name = "['" + StartVert() + "'->'" + EndVert() + "']";
723
724 // example: "["Paris"->"Berlin"]"
725 }
726
727 return name;
728 }
bool IsWeighted() const
Definition graph.hpp:681
weight_t Weight() const
Definition graph.hpp:686
vert_t StartVert() const
Definition graph.hpp:683
vert_t EndVert() const
Definition graph.hpp:684
Here is the call graph for this function:

◆ operator!=()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
bool Graph< vert_t, weight_t >::Edge::operator!= ( const Edge & rhs) const
inline
699{ return !(*this == rhs); }

◆ operator<=>()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
auto Graph< vert_t, weight_t >::Edge::operator<=> ( const Edge & rhs) const
inline
701{ return weight_ <=> rhs.Weight(); }

◆ operator==()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
bool Graph< vert_t, weight_t >::Edge::operator== ( const Edge & rhs) const
inline
690 {
691 if (StartVert() != rhs.StartVert() || EndVert() != rhs.EndVert())
692 return false;
693
694 if (IsWeighted() && rhs.IsWeighted()) return Weight() == rhs.Weight();
695
696 return true;
697 }
Here is the call graph for this function:

◆ SetWeight()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
void Graph< vert_t, weight_t >::Edge::SetWeight ( weight_t new_weight)
inline
688{ weight_ = new_weight; }

◆ StartVert()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
vert_t Graph< vert_t, weight_t >::Edge::StartVert ( ) const
inline
683{ return start_vert_; }
Here is the caller graph for this function:

◆ Weight()

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
weight_t Graph< vert_t, weight_t >::Edge::Weight ( ) const
inline
686{ return weight_; }
Here is the caller graph for this function:

Member Data Documentation

◆ end_vert_

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
vert_t Graph< vert_t, weight_t >::Edge::end_vert_
private

◆ start_vert_

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
vert_t Graph< vert_t, weight_t >::Edge::start_vert_
private

◆ weight_

template<AllowedVertType vert_t = std::string, AllowedWeightType weight_t = size_t>
weight_t Graph< vert_t, weight_t >::Edge::weight_ = 0
private

The documentation for this class was generated from the following file: