Skip to content

Commit

Permalink
expose igraph_type
Browse files Browse the repository at this point in the history
  • Loading branch information
szhorvat committed Jul 28, 2024
1 parent 2df27c2 commit 1f99197
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
2 changes: 2 additions & 0 deletions include/igraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ using ComplexMat = Mat<std::complex<igraph_real_t>>;
class GraphList;

class Graph {
public:
using igraph_type = igraph_t;

private:
igraph_t graph;
igraph_t *ptr = &graph;

Expand Down
20 changes: 11 additions & 9 deletions include/mat_pmt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
#include <igraph_pmt.hpp>

template<> class Mat<OBASE> {
public:
using igraph_type = TYPE(igraph_matrix);

using value_type = OBASE;
using reference = value_type &;
using const_reference = const value_type &;
using iterator = value_type *;
using const_iterator = const value_type *;
using difference_type = igraph_integer_t;
using size_type = igraph_integer_t;

private:
igraph_type mat;
igraph_type *ptr = &mat;

Expand All @@ -12,14 +22,6 @@ template<> class Mat<OBASE> {
friend class MatList<OBASE>;

public:
using value_type = OBASE;
using reference = OBASE &;
using const_reference = const OBASE &;
using iterator = OBASE *;
using const_iterator = const OBASE *;
using difference_type = igraph_integer_t;
using size_type = igraph_integer_t;

explicit Mat(CaptureType<igraph_type> m) : mat(m.obj) { }
explicit Mat(AliasType<igraph_type> m) : ptr(&m.obj) { }

Expand Down Expand Up @@ -62,7 +64,7 @@ template<> class Mat<OBASE> {
return *this;
}

Mat(std::initializer_list<std::initializer_list<OBASE>> values) {
Mat(std::initializer_list<std::initializer_list<value_type>> values) {
size_type n = values.size();
size_type m = n > 0 ? values.begin()->size() : 0;
check(FUNCTION(igraph_matrix, init)(ptr, n, m));
Expand Down
1 change: 0 additions & 1 deletion include/rng_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class RNGScope {

RNGScope() : RNGScope(default_type) { }

public:
// We shouldn't be copying or moving an RNGScope object, as this defeats the logic provided by scoping.
RNGScope(const RNGScope &) = delete;
RNGScope & operator = (const RNGScope&) = delete;
Expand Down
14 changes: 8 additions & 6 deletions include/strvec.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@

class StrVec {
public:
using igraph_type = igraph_strvector_t;

igraph_type vec;
igraph_type *ptr = &vec;

bool is_alias() const { return ptr != &vec; }

public:
using value_type = const char *;
using difference_type = igraph_integer_t;
using size_type = igraph_integer_t;
Expand Down Expand Up @@ -35,6 +30,13 @@ class StrVec {
class iterator;
using const_iterator = iterator;

private:
igraph_type vec;
igraph_type *ptr = &vec;

bool is_alias() const { return ptr != &vec; }

public:
explicit StrVec(CaptureType<igraph_type> v) : vec(v.obj) { }
explicit StrVec(AliasType<igraph_type> v) : ptr(&v.obj) { }

Expand Down
14 changes: 8 additions & 6 deletions include/typed_list_pmt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
template<>
#endif
class LIST_TYPE_TEMPL {
public:
using igraph_type = TYPE;

igraph_type list;
igraph_type *ptr = &list;

bool is_alias() const { return ptr != &list; }

public:
using value_type = ELEM_TYPE;
using reference = value_type;
using const_reference = const reference;
Expand All @@ -23,6 +18,13 @@ class LIST_TYPE_TEMPL {
using iterator = base_iterator<value_type, reference>;
using const_iterator = base_iterator<const value_type, const_reference>;

private:
igraph_type list;
igraph_type *ptr = &list;

bool is_alias() const { return ptr != &list; }

public:
explicit LIST_TYPE(CaptureType<igraph_type> tl) : list(tl.obj) { }
explicit LIST_TYPE(AliasType<igraph_type> tl) : ptr(&tl.obj) { }

Expand Down
20 changes: 11 additions & 9 deletions include/vec_pmt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
// To create a Vec that aliases v, use Vec(Alias(v)). To take over the ownership of
// v's data, use Vec(Capture(v)). In the latter case, v must no longer be used directly.
template<> class Vec<OBASE> {
public:
using igraph_type = TYPE(igraph_vector);

using value_type = OBASE;
using reference = value_type &;
using const_reference = const value_type &;
using iterator = value_type *;
using const_iterator = const value_type *;
using difference_type = igraph_integer_t;
using size_type = igraph_integer_t;

private:
igraph_type vec;
igraph_type *ptr = &vec;

Expand All @@ -20,14 +30,6 @@ template<> class Vec<OBASE> {
friend class VecList<OBASE>;

public:
using value_type = OBASE;
using reference = OBASE &;
using const_reference = const OBASE &;
using iterator = OBASE *;
using const_iterator = const OBASE *;
using difference_type = igraph_integer_t;
using size_type = igraph_integer_t;

explicit Vec(CaptureType<igraph_type> v) : vec(v.obj) { }
explicit Vec(AliasType<igraph_type> v) : ptr(&v.obj) { }

Expand All @@ -52,7 +54,7 @@ template<> class Vec<OBASE> {
check(FUNCTION(igraph_vector, init_copy)(ptr, v));
}

Vec(std::initializer_list<OBASE> list) {
Vec(std::initializer_list<value_type> list) {
check(FUNCTION(igraph_vector, init_array)(ptr, INVPTRCAST(list.begin()), list.size()));
}

Expand Down

0 comments on commit 1f99197

Please sign in to comment.