GraphLib
Bearbeitung der Aufgabe Mini Graph Library für OOP WiSe 2023/24
Loading...
Searching...
No Matches
abstract_undirected_graph.h
Go to the documentation of this file.
1#ifndef GRAPHLIB_INTERNAL_ABSTRACT_UNDIRECTED_GRAPH_H
2#define GRAPHLIB_INTERNAL_ABSTRACT_UNDIRECTED_GRAPH_H
3
4#include <stdexcept>
5
8
25
26namespace GraphLib::Internal {
27
41template <valid_data_type D, valid_id_type I, valid_edge_type<I> E>
42class UndirectedGraph : public virtual Graph<D, I, E> {
43public:
48 [[nodiscard]] bool is_directed() const override
49 {
50 return false;
51 }
52
63 void remove_edge(I from_id, I to_id) override
64 {
65 if (!this->node_exists(from_id)) {
66 throw std::invalid_argument("Node with ID from_id does not exist");
67 }
68 if (!this->node_exists(to_id)) {
69 throw std::invalid_argument("Node with ID to_id does not exist");
70 }
71 if (!this->adj_list_.has_edge(from_id, to_id) || !this->adj_list_.has_edge(to_id, from_id)) {
72 throw std::invalid_argument("Nodes don't have an edge");
73 }
74
75 this->adj_list_.remove_edge(from_id, to_id);
76 this->adj_list_.remove_edge(to_id, from_id);
77 }
78};
79
80} // namespace GraphLib::Internal
81
82#endif
Defines the generic abstract Graph class template supporting directed/undirected and weighted/unweigh...
Abstract base class for a generic graph structure.
bool node_exists(const id_type id) const
Check if a node with the specified ID exists.
AdjacencyList< id_type, edge_type > adj_list_
Stores edges as adjacency list.
A graph class representing undirected graphs.
void remove_edge(I from_id, I to_id) override
Removes an undirected edge between two nodes.
bool is_directed() const override
Indicates that this graph is undirected.
Defines C++20 concepts used for type constraints in the GraphLib library.