Matrix.hpp
1 #ifndef OPALS_MATRIX_HPP_INCLUDED
2 #define OPALS_MATRIX_HPP_INCLUDED
3 
4 #include <opals/fwd.hpp>
5 
6 #include <cstddef>
7 
8 namespace opals {
9 
10  /**
11  \class Matrix
12  \tparam T element type
13  \tparam M number of rows
14  \tparam N number of columns
15 
16  \brief A template class for storing a two-dimensional array of constant size.
17 
18  Symbols for Matrix are exported to opals DLLs as required by their modules' interfaces,
19  meaning that DLL users are able to instantiate Matrix<T,M,N> only with the corresponding template arguments.
20  The interface is based on boost::numeric::ublas::c_matrix
21 
22  \author wk
23  \date 06.02.2011
24 
25  \internal
26  opals::Matrix features a constant size, because otherwise, parsing would become more difficult
27  ( we would need to define a syntax for row/column breaks).
28  Note, however, that the template parameters M and N merely define an upper limit to the extents of the underlying ublas::c_matrix,
29  which may be smaller when the according ublas-functions have been applied.
30  Conversion constructors and operators for boost::numeric::ublas::c_matrix<T,M,N> are provided for internal use only.
31  If T is another interface class (e.g. opals::String),
32  then use function toInternal() to convert to boost::numeric::ublas::c_matrix<std::string,M,N>.
33  opals::Matrix encapsulates boost::ublas::c_matrix, whose implementation it hides from the
34  interface in order to provide self-contained code.
35  As ublas provides highly optimized template expressions, users are expected
36  to use opals::Matrix only when communicating with the interface, why no further operators are exposed.
37  */
38 
39  template< class T, std::size_t M, std::size_t N >
40  class Matrix
41  {
42  class Impl;
43  Impl *pimpl_;
44 
45  public:
46 
47  typedef T value_type;
48  typedef T* pointer;
49  typedef T& reference;
50  typedef T const& const_reference;
51  typedef std::size_t size_type;
52 
53  static const size_type _nRows = M;
54  static const size_type _nCols = N;
55 
56  /// \name construction / destruction
57  /// n.b.: use clear() to initialize the Matrix
58  ///@{
59  Matrix();
60 
61  Matrix( const Matrix& other );
62 
63  ~Matrix();
64  ///}@
65 
66  /// \name initialization
67  ///@{
68  /// all elements are set to T()
69  void clear();
70  ///}@
71 
72  /// \name assignment, swapping
73  ///@{
74  Matrix& operator=( const Matrix& other );
75  void swap( Matrix& other );
76  ///}@
77 
78  /// \name direct data access
79  /// zero-based indexing
80  ///@{
81  reference operator()( size_type r, size_type c );
82  const_reference operator()( size_type r, size_type c ) const;
83  ///}@
84 
85  /// \name size
86  ///@{
87  size_type nRows() const;
88  size_type nCols() const;
89  ///}@
90 
91  };
92 
93 }
94 
95 #endif