1#ifndef RAIIGRAPH_GRAPH_HPP
2#define RAIIGRAPH_GRAPH_HPP
24 void setup(igraph_integer_t num_vertices, igraph_bool_t directed) {
25 if (igraph_empty(&my_graph, num_vertices, directed)) {
26 throw std::runtime_error(
"failed to initialize an empty igraph graph object");
37 Graph(igraph_integer_t num_vertices = 0, igraph_bool_t directed =
false) {
38 setup(num_vertices, directed);
49 Graph(
const IntVector& edges, igraph_integer_t num_vertices, igraph_bool_t directed) :
Graph(edges.
get(), num_vertices, directed) {}
58 Graph(
const igraph_vector_int_t* edges, igraph_integer_t num_vertices, igraph_bool_t directed) {
59 if (igraph_create(&my_graph, edges, num_vertices, directed)) {
60 throw std::runtime_error(
"failed to initialize an igraph graph object");
67 Graph(igraph_t&& graph) : my_graph(std::move(graph)) {}
73 if (igraph_copy(&my_graph, &(other.my_graph))) {
74 throw std::runtime_error(
"failed to copy-construct an igraph graph object");
83 if (igraph_copy(&my_graph, &(other.my_graph))) {
84 throw std::runtime_error(
"failed to copy-assign an igraph graph object");
96 std::swap(my_graph, other.my_graph);
104 if (
this != &other) {
105 std::swap(my_graph, other.my_graph);
114 igraph_destroy(&my_graph);
122 return igraph_vcount(&my_graph);
129 return igraph_ecount(&my_graph);
140 check_code(igraph_get_edgelist(&my_graph, out.
get(), by_col));
149 return igraph_is_directed(&my_graph);
158 igraph_bool_t
is_connected(igraph_connectedness_t mode = IGRAPH_WEAK)
const {
160 check_code(igraph_is_connected(&my_graph, &res, mode));
169 check_code(igraph_is_simple(&my_graph, &res));
187 check_code(igraph_has_multiple(&my_graph, &res));
195 igraph_bool_t
has_mutual(igraph_bool_t loops =
false)
const {
197 check_code(igraph_has_mutual(&my_graph, &res, loops));
207 bool is_tree(igraph_neimode_t mode = IGRAPH_ALL)
const {
209 check_code(igraph_is_tree(&my_graph, &res, NULL, mode));
217 bool is_forest(igraph_neimode_t mode = IGRAPH_ALL)
const {
219 check_code(igraph_is_forest(&my_graph, &res, NULL, mode));
237 check_code(igraph_is_acyclic(&my_graph, &res));
246 operator igraph_t*() {
254 operator const igraph_t*()
const {
270 const igraph_t*
get()
const {
Wrapper around igraph_vector_*_t objects with RAII behavior.
Wrapper around igraph_t objects with RAII behavior.
Definition Graph.hpp:22
Graph & operator=(const Graph &other)
Definition Graph.hpp:81
IntVector get_edgelist(igraph_bool_t by_col=false) const
Definition Graph.hpp:138
Graph(const Graph &other)
Definition Graph.hpp:72
Graph(const igraph_vector_int_t *edges, igraph_integer_t num_vertices, igraph_bool_t directed)
Definition Graph.hpp:58
Graph(igraph_integer_t num_vertices=0, igraph_bool_t directed=false)
Definition Graph.hpp:37
igraph_t * get()
Definition Graph.hpp:262
Graph(const IntVector &edges, igraph_integer_t num_vertices, igraph_bool_t directed)
Definition Graph.hpp:49
Graph(igraph_t &&graph)
Definition Graph.hpp:67
Graph & operator=(Graph &&other)
Definition Graph.hpp:103
igraph_bool_t has_loop() const
Definition Graph.hpp:176
igraph_bool_t is_directed() const
Definition Graph.hpp:148
const igraph_t * get() const
Definition Graph.hpp:270
bool is_dag() const
Definition Graph.hpp:226
~Graph()
Definition Graph.hpp:113
igraph_bool_t has_mutual(igraph_bool_t loops=false) const
Definition Graph.hpp:195
igraph_bool_t is_simple() const
Definition Graph.hpp:167
igraph_integer_t vcount() const
Definition Graph.hpp:121
bool is_acyclic() const
Definition Graph.hpp:235
bool is_forest(igraph_neimode_t mode=IGRAPH_ALL) const
Definition Graph.hpp:217
igraph_bool_t has_multiple() const
Definition Graph.hpp:185
bool is_tree(igraph_neimode_t mode=IGRAPH_ALL) const
Definition Graph.hpp:207
igraph_integer_t ecount() const
Definition Graph.hpp:128
Graph(Graph &&other)
Definition Graph.hpp:94
igraph_bool_t is_connected(igraph_connectedness_t mode=IGRAPH_WEAK) const
Definition Graph.hpp:158
Wrapper around igraph_vector_*_t objects with RAII behavior.
Definition Vector.hpp:26
igraph_type * get()
Definition Vector.hpp:501
Error handling for raiigraph.
Utilities for manipulating igraph data structures in C++.
Definition error.hpp:11
void check_code(igraph_error_t code)
Definition error.hpp:34