classPiiConceptualMatrix
#include <PiiConceptualMatrix.h>
A superclass for classes that implement the matrix concept.
Description
The matrix concept is divided into three implementation levels:
-
IterableMatrix(level 0) - the matrix provides at least input iterators for accessing the data. The class must have #begin() and #end() functions for getting the iterators. The iterators may be bi-directional or random-access, but only forward iteration is a requirement. At leastconstversions of the iterators must be provided. The iterators must model the forward iterator concept of the standard library, and must scan the matrix in row-major order: the end of row N is immediately followed by the start of row N+1. A level 0 matrix must also define functions called #rows() and #columns(), for getting the number of rows and columns, respectively. This basic functionality is required by almost all matrix algorithms. -
RandomAccessMatrix(level 1) - the matrix provides iterators for accessing individual rows and columns. See PiiConceptualMatrix<Derived,Pii::RandomAccessMatrix>. This functionality is required by algorithms such as matrix multiplication and transposition.
-
value_typefor the content type. -
referencefor a reference to the content type. -
const_iteratorfor read-only access. -
iteratorfor read-write access.
-
column_iteratorfor read-write column-wise iterators. -
const_column_iteratorfor read-only column-wise iterators. -
row_iteratorfor read-write row-wise iterators. -
const_row_iteratorfor read-only row-wise iterators.
// First declare types related to your matrix implementation. This // needs to come first because PiiConceptualMatrix matrix needs it // when instantiated. We declare the traits as a template wrt to // implementation level so that it will be always used if we later // improve the implementation. Since My3x3Matrix is not declared // yet, a forward declaration is needed. class My3x3Matrix; template <int level> struct PiiMatrixTraits<My3x3Matrix, level> { typedef int value_type; typedef int& reference; typedef int* iterator; typedef const int* const_iterator; }; class My3x3Matrix : public PiiConceptualMatrix<My3x3Matrix> { public: typedef PiiConceptualMatrix<My3x3Matrix> BaseType; const_iterator begin() const { return _data; } const_iterator end() const { return _data + 9; } int rows() const { return 3; } int columns() const { return 3; } // Now we have the minimum functionality. // Other functions may be added to modify the data etc. private: int _data[9]; };
Once you have done this, your matrix class can be used with other matrix classes in arithmetic operations. For example, you can do the following:
PiiMatrix<int> mat(3,3); My3x3Matrix mat2; mat += mat2 / 4 + 5; mat -= mat2 + mat;
Public types
|
enum
|
{ implementationLevel = level }
|
|
typedef Traits::const_iterator
|
|
|
typedef Derived
|
|
|
typedef Traits::iterator
|
|
|
typedef std::iterator_traits< iterator >::reference
|
|
|
typedef PiiMatrixTraits< Derived, level >
|
|
|
typedef std::iterator_traits< iterator >::value_type
|
Public member functions
|
const_iterator
|
( )
|
|
iterator
|
( )
|
|
int
|
( )
|
|
const_iterator
|
( )
|
|
const_iterator
|
( )
|
|
const_iterator
|
( )
|
|
iterator
|
( )
|
|
bool
|
( )
Returns |
|
template<class Matrix>
Derived &
|
|
|
Derived &
|
(
Sets all elements to value and returns a reference to self(). |
|
int
|
( )
|
|
DerivedType *
|
( )
|
|
const DerivedType *
|
( )
|
|
const DerivedType &
|
( )
|
|
DerivedType &
|
( )
|
Enumeration details
-
enum @37
Function details
-
const_iterator begin
()[inline] -
iterator begin
()[inline] -
int columns
()[inline] -
const_iterator constBegin
()[inline] -
const_iterator constEnd
()[inline] -
const_iterator end
()[inline] -
iterator end
()[inline] -
bool isEmpty
()[inline]Returns
trueif the matrix is empty, andfalseotherwise.An empty matrix cannot hold a single element, i.e. there are either zero rows or zero columns. Any access to an element within an empty matrix will reference illegal memory.
-
template<class Matrix>
Derived & operator<<
[inline] -
Derived & operator=
(- value_type value
[inline]Sets all elements to value and returns a reference to self().
-
int rows
()[inline] -
DerivedType * self
()[inline] -
const DerivedType * self
()[inline] -
const DerivedType & selfRef
()[inline] -
DerivedType & selfRef
()[inline]
Add a note
Not a single note added yet. Be the first, add yours.