raiigraph
C++ RAII for igraph data structures
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
raiigraph::Matrix< Ns_ > Class Template Reference

Wrapper around igraph_matrix_*_t objects with RAII behavior. More...

#include <Matrix.hpp>

Classes

class  View
 View into a row/column of the matrix. More...
 

Public Types

typedef Ns_::igraph_type igraph_type
 
typedef Ns_::value_type value_type
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef igraph_integer_t size_type
 
typedef igraph_integer_t difference_type
 
typedef value_typeiterator
 
typedef const value_typeconst_iterator
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef std::reverse_iterator< const_iteratorreverse_const_iterator
 
typedef Ns_::vector_type vector_type
 

Public Member Functions

 Matrix ()
 
 Matrix (size_type nr, size_type nc, const value_type &val=value_type())
 
 Matrix (igraph_type &&matrix)
 
 Matrix (const Matrix< Ns_ > &other)
 
Matrix< Ns_ > & operator= (const Matrix< Ns_ > &other)
 
 Matrix (Matrix< Ns_ > &&other)
 
Matrixoperator= (Matrix< Ns_ > &&other)
 
 ~Matrix ()
 
igraph_bool_t empty () const
 
size_type size () const
 
size_type nrow () const
 
size_type ncol () const
 
constexpr size_type max_size () const
 
size_type capacity () const
 
void clear ()
 
void resize (size_type nr, size_type nc, value_type val=value_type())
 
void shrink_to_fit ()
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
reference operator() (size_type r, size_type c)
 
const_reference operator() (size_type r, size_type c) const
 
reference back ()
 
const_reference back () const
 
reference front ()
 
const_reference front () const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
value_typedata ()
 
const value_typedata () const
 
reverse_iterator rbegin ()
 
reverse_iterator rend ()
 
reverse_const_iterator rbegin () const
 
reverse_const_iterator rend () const
 
reverse_const_iterator crbegin () const
 
reverse_const_iterator crend () const
 
View< iterator, referencerow (size_type r)
 
View< const_iterator, const_referencerow (size_type r) const
 
vector_type row_copy (size_type r) const
 
View< iterator, referencecolumn (size_type c)
 
View< const_iterator, const_referencecolumn (size_type c) const
 
vector_type column_copy (size_type c) const
 
 operator igraph_type * ()
 
 operator const igraph_type * () const
 
igraph_typeget ()
 
const igraph_typeget () const
 
void swap (Matrix< Ns_ > &other)
 

Detailed Description

template<class Ns_>
class raiigraph::Matrix< Ns_ >

Wrapper around igraph_matrix_*_t objects with RAII behavior.

Template Parameters
Ns_Structure-based namespace with static methods, internal use only.

This class has ownership of the underlying igraph_matrix_*_t object, handling both its initialization and destruction. Users should only pass instances of this class to igraph functions that accept an already-initialized matrix. Users should not attempt to destroy the matrix manually as this is done automatically when the Matrix goes out of scope.

Member Typedef Documentation

◆ const_iterator

template<class Ns_ >
typedef const value_type* raiigraph::Matrix< Ns_ >::const_iterator

Const iterator for the matrix contents.

◆ const_reference

template<class Ns_ >
typedef const value_type& raiigraph::Matrix< Ns_ >::const_reference

Type of a const reference to values inside the matrix.

◆ difference_type

template<class Ns_ >
typedef igraph_integer_t raiigraph::Matrix< Ns_ >::difference_type

Integer type for differences in positions within the matrix.

◆ igraph_type

template<class Ns_ >
typedef Ns_::igraph_type raiigraph::Matrix< Ns_ >::igraph_type

Type of the underlying igraph matrix.

◆ iterator

template<class Ns_ >
typedef value_type* raiigraph::Matrix< Ns_ >::iterator

Iterator for the matrix contents.

◆ reference

template<class Ns_ >
typedef value_type& raiigraph::Matrix< Ns_ >::reference

Type of the reference to values inside the matrix.

◆ reverse_const_iterator

template<class Ns_ >
typedef std::reverse_iterator<const_iterator> raiigraph::Matrix< Ns_ >::reverse_const_iterator

Reverse const iterator for the matrix contents.

◆ reverse_iterator

template<class Ns_ >
typedef std::reverse_iterator<iterator> raiigraph::Matrix< Ns_ >::reverse_iterator

Reverse iterator for the matrix contents.

◆ size_type

Integer type for the size of the matrix.

◆ value_type

template<class Ns_ >
typedef Ns_::value_type raiigraph::Matrix< Ns_ >::value_type

Type of the values inside the matrix.

◆ vector_type

template<class Ns_ >
typedef Ns_::vector_type raiigraph::Matrix< Ns_ >::vector_type

The raiigraph vector class with the same value_type as this matrix.

Constructor & Destructor Documentation

◆ Matrix() [1/5]

template<class Ns_ >
raiigraph::Matrix< Ns_ >::Matrix ( )
inline

Default constructor, creates an initialized matrix with no rows or columns.

◆ Matrix() [2/5]

template<class Ns_ >
raiigraph::Matrix< Ns_ >::Matrix ( size_type  nr,
size_type  nc,
const value_type val = value_type() 
)
inline
Parameters
nrNumber of rows in the matrix.
ncNumber of columns in the matrix.
valValue to use to fill the matrix.

◆ Matrix() [3/5]

template<class Ns_ >
raiigraph::Matrix< Ns_ >::Matrix ( igraph_type &&  matrix)
inline
Parameters
matrixAn initialized matrix to take ownership of.

◆ Matrix() [4/5]

template<class Ns_ >
raiigraph::Matrix< Ns_ >::Matrix ( const Matrix< Ns_ > &  other)
inline
Parameters
otherMatrix to be copy-constructed from. This constructor will make a deep copy.

◆ Matrix() [5/5]

template<class Ns_ >
raiigraph::Matrix< Ns_ >::Matrix ( Matrix< Ns_ > &&  other)
inline
Parameters
otherMatrix to be move-constructed from. This constructor will leave other in a valid but unspecified state.

◆ ~Matrix()

template<class Ns_ >
raiigraph::Matrix< Ns_ >::~Matrix ( )
inline

Destructor.

Member Function Documentation

◆ back() [1/2]

template<class Ns_ >
reference raiigraph::Matrix< Ns_ >::back ( )
inline
Returns
Reference to the last element in the matrix.

◆ back() [2/2]

template<class Ns_ >
const_reference raiigraph::Matrix< Ns_ >::back ( ) const
inline
Returns
Const reference to the last element in the matrix.

◆ begin() [1/2]

template<class Ns_ >
iterator raiigraph::Matrix< Ns_ >::begin ( )
inline
Returns
Iterator to the start of this matrix.

◆ begin() [2/2]

template<class Ns_ >
const_iterator raiigraph::Matrix< Ns_ >::begin ( ) const
inline
Returns
Const iterator to the start of this matrix.

◆ capacity()

template<class Ns_ >
size_type raiigraph::Matrix< Ns_ >::capacity ( ) const
inline
Returns
Capacity of this matrix.

◆ cbegin()

template<class Ns_ >
const_iterator raiigraph::Matrix< Ns_ >::cbegin ( ) const
inline
Returns
Const iterator to the start of this matrix.

◆ cend()

template<class Ns_ >
const_iterator raiigraph::Matrix< Ns_ >::cend ( ) const
inline
Returns
Const iterator to the end of this matrix.

◆ clear()

template<class Ns_ >
void raiigraph::Matrix< Ns_ >::clear ( )
inline

Clear this matrix, leaving it with a size of zero.

◆ column() [1/2]

template<class Ns_ >
View< iterator, reference > raiigraph::Matrix< Ns_ >::column ( size_type  c)
inline
Parameters
cColumn of interest.
Returns
A view on the column.

◆ column() [2/2]

template<class Ns_ >
View< const_iterator, const_reference > raiigraph::Matrix< Ns_ >::column ( size_type  c) const
inline
Parameters
cColumn of interest.
Returns
A const view on the column.

◆ column_copy()

template<class Ns_ >
vector_type raiigraph::Matrix< Ns_ >::column_copy ( size_type  c) const
inline
Parameters
cColumn of interest.
Returns
An igraph vector containing a copy of the column contents.

◆ crbegin()

template<class Ns_ >
reverse_const_iterator raiigraph::Matrix< Ns_ >::crbegin ( ) const
inline
Returns
Reverse const iterator to the last element of this matrix.

◆ crend()

template<class Ns_ >
reverse_const_iterator raiigraph::Matrix< Ns_ >::crend ( ) const
inline
Returns
Reverse const iterator to a location before the start of this matrix.

◆ data() [1/2]

template<class Ns_ >
value_type * raiigraph::Matrix< Ns_ >::data ( )
inline
Returns
Pointer to the start of this matrix.

◆ data() [2/2]

template<class Ns_ >
const value_type * raiigraph::Matrix< Ns_ >::data ( ) const
inline
Returns
Const pointer to the start of this matrix.

◆ empty()

template<class Ns_ >
igraph_bool_t raiigraph::Matrix< Ns_ >::empty ( ) const
inline
Returns
Whether the matrix is empty.

◆ end() [1/2]

template<class Ns_ >
iterator raiigraph::Matrix< Ns_ >::end ( )
inline
Returns
Iterator to the end of this matrix.

◆ end() [2/2]

template<class Ns_ >
const_iterator raiigraph::Matrix< Ns_ >::end ( ) const
inline
Returns
Const iterator to the end of this matrix.

◆ front() [1/2]

template<class Ns_ >
reference raiigraph::Matrix< Ns_ >::front ( )
inline
Returns
Reference to the last element in the matrix.

◆ front() [2/2]

template<class Ns_ >
const_reference raiigraph::Matrix< Ns_ >::front ( ) const
inline
Returns
Const reference to the last element in the matrix.

◆ get() [1/2]

template<class Ns_ >
igraph_type * raiigraph::Matrix< Ns_ >::get ( )
inline
Returns
Pointer to the underlying igraph matrix object. This is guaranteed to be non-NULL and initialized.

◆ get() [2/2]

template<class Ns_ >
const igraph_type * raiigraph::Matrix< Ns_ >::get ( ) const
inline
Returns
Const pointer to the underlying igraph matrix object. This is guaranteed to be non-NULL and initialized.

◆ max_size()

template<class Ns_ >
constexpr size_type raiigraph::Matrix< Ns_ >::max_size ( ) const
inlineconstexpr
Returns
Maximum size of this matrix.

◆ ncol()

template<class Ns_ >
size_type raiigraph::Matrix< Ns_ >::ncol ( ) const
inline
Returns
Number of columns in the matrix.

◆ nrow()

template<class Ns_ >
size_type raiigraph::Matrix< Ns_ >::nrow ( ) const
inline
Returns
Number of rows in the matrix.

◆ operator const igraph_type *()

template<class Ns_ >
raiigraph::Matrix< Ns_ >::operator const igraph_type * ( ) const
inline
Returns
Const pointer to the underlying igraph matrix object. This is guaranteed to be non-NULL and initialized.

◆ operator igraph_type *()

template<class Ns_ >
raiigraph::Matrix< Ns_ >::operator igraph_type * ( )
inline
Returns
Pointer to the underlying igraph matrix object. This is guaranteed to be non-NULL and initialized.

◆ operator()() [1/2]

template<class Ns_ >
reference raiigraph::Matrix< Ns_ >::operator() ( size_type  r,
size_type  c 
)
inline
Parameters
rRow of interest.
cColumn of interest.
Returns
Reference to the value at (r, c).

◆ operator()() [2/2]

template<class Ns_ >
const_reference raiigraph::Matrix< Ns_ >::operator() ( size_type  r,
size_type  c 
) const
inline
Parameters
rRow of interest.
cColumn of interest.
Returns
Const reference to the value at (r, c).

◆ operator=() [1/2]

template<class Ns_ >
Matrix< Ns_ > & raiigraph::Matrix< Ns_ >::operator= ( const Matrix< Ns_ > &  other)
inline
Parameters
otherMatrix to be copy-assigned from. This constructor will make a deep copy.

◆ operator=() [2/2]

template<class Ns_ >
Matrix & raiigraph::Matrix< Ns_ >::operator= ( Matrix< Ns_ > &&  other)
inline
Parameters
otherMatrix to be move-assigned from. This constructor will leave other in a valid but unspecified state.

◆ operator[]() [1/2]

Parameters
iIndex on the matrix.
Returns
Reference to the value at i.

◆ operator[]() [2/2]

template<class Ns_ >
const_reference raiigraph::Matrix< Ns_ >::operator[] ( size_type  i) const
inline
Parameters
iIndex on the matrix.
Returns
Const reference to the value at i.

◆ rbegin() [1/2]

template<class Ns_ >
reverse_iterator raiigraph::Matrix< Ns_ >::rbegin ( )
inline
Returns
Reverse iterator to the last element of this matrix.

◆ rbegin() [2/2]

template<class Ns_ >
reverse_const_iterator raiigraph::Matrix< Ns_ >::rbegin ( ) const
inline
Returns
Reverse const iterator to the last element of this matrix.

◆ rend() [1/2]

template<class Ns_ >
reverse_iterator raiigraph::Matrix< Ns_ >::rend ( )
inline
Returns
Reverse iterator to a location before the start of this matrix.

◆ rend() [2/2]

template<class Ns_ >
reverse_const_iterator raiigraph::Matrix< Ns_ >::rend ( ) const
inline
Returns
Reverse const iterator to a location before the start of this matrix.

◆ resize()

template<class Ns_ >
void raiigraph::Matrix< Ns_ >::resize ( size_type  nr,
size_type  nc,
value_type  val = value_type() 
)
inline

Resize the matrix to the specified number of rows and columns. Existing values are preserved by considering the original and new matrices as 1-dimensional arrays in column-major order; the contents of the original matrix are simply copied into the first size() entries of the new matrix.

Parameters
nrNew number of rows.
ncNew number of columns.
valValue to use to fill the new elements, if nr * nc is greater than the current size().

◆ row() [1/2]

template<class Ns_ >
View< iterator, reference > raiigraph::Matrix< Ns_ >::row ( size_type  r)
inline
Parameters
rRow of interest.
Returns
A view on the row.

◆ row() [2/2]

template<class Ns_ >
View< const_iterator, const_reference > raiigraph::Matrix< Ns_ >::row ( size_type  r) const
inline
Parameters
rRow of interest.
Returns
A const view on the row.

◆ row_copy()

template<class Ns_ >
vector_type raiigraph::Matrix< Ns_ >::row_copy ( size_type  r) const
inline
Parameters
rRow of interest.
Returns
An igraph vector containing a copy of the row contents.

◆ shrink_to_fit()

template<class Ns_ >
void raiigraph::Matrix< Ns_ >::shrink_to_fit ( )
inline

Shrink the capacity of the matrix to fit the contents.

◆ size()

template<class Ns_ >
size_type raiigraph::Matrix< Ns_ >::size ( ) const
inline
Returns
Size of the matrix.

◆ swap()

template<class Ns_ >
void raiigraph::Matrix< Ns_ >::swap ( Matrix< Ns_ > &  other)
inline

Swap two matrixs, maintaining the validity of existing pointers to each matrix and its elements.

Parameters
otherMatrix to be swapped.

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