GraphLib
Bearbeitung der Aufgabe Mini Graph Library für OOP WiSe 2023/24
Loading...
Searching...
No Matches
abstract_directed_graph.h
Go to the documentation of this file.
1#ifndef GRAPHLIB_INTERNAL_ABSTRACT_DIRECTED_GRAPH_H
2#define GRAPHLIB_INTERNAL_ABSTRACT_DIRECTED_GRAPH_H
3
4#include <stdexcept>
5
8
23
24namespace GraphLib::Internal {
25
40template <valid_data_type D, valid_id_type I, valid_edge_type<I> E>
41class DirectedGraph : public virtual Graph<D, I, E> {
42public:
47 [[nodiscard]] bool is_directed() const override
48 {
49 return true;
50 }
51
60 void remove_edge(I from_id, I to_id) override
61 {
62 if (!this->node_exists(from_id)) {
63 throw std::invalid_argument("Node with ID from_id does not exist");
64 }
65 if (!this->node_exists(to_id)) {
66 throw std::invalid_argument("Node with ID to_id does not exist");
67 }
68 if (!this->adj_list_.has_edge(from_id, to_id)) {
69 throw std::invalid_argument("Nodes don't have an edge");
70 }
71
72 this->adj_list_.remove_edge(from_id, to_id);
73 }
74};
75
76} // namespace GraphLib::Internal
77
78#endif
Defines the generic abstract Graph class template supporting directed/undirected and weighted/unweigh...
A graph class representing directed graphs.
void remove_edge(I from_id, I to_id) override
Removes the directed edge from from_id to to_id.
bool is_directed() const override
Indicates that this graph is directed.
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.
Defines C++20 concepts used for type constraints in the GraphLib library.