Simpatico  v1.10
Matrix.h
1 #ifndef UTIL_MATRIX_H
2 #define UTIL_MATRIX_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/global.h>
12 
13 namespace Util
14 {
15 
29  template <typename Data>
30  class Matrix
31  {
32 
33  public:
34 
35  // Protected default constructor, to prohibit direct instantiation.
36 
37  // Private copy constructor, to prohibit copy construction.
38 
42  virtual ~Matrix();
43 
47  int capacity1() const;
48 
52  int capacity2() const;
53 
60  const Data& operator() (int i, int j) const;
61 
68  Data& operator() (int i, int j);
69 
70  protected:
71 
73  Data* data_;
74 
77 
80 
86  Matrix();
87 
88  private:
89 
93  Matrix(const Matrix<Data>& other);
94 
98  Matrix<Data>& operator = (const Matrix<Data>& other);
99 
100  };
101 
102  // Method definitions
103 
107  template <typename Data>
109  : data_(0),
110  capacity1_(0),
111  capacity2_(0)
112  {}
113 
114  /*
115  * Destructor.
116  */
117  template <typename Data>
119  {}
120 
121  /*
122  * Get number of rows.
123  */
124  template <typename Data>
125  inline int Matrix<Data>::capacity1() const
126  { return capacity1_; }
127 
128  /*
129  * Get number of columns.
130  */
131  template <typename Data>
132  inline int Matrix<Data>::capacity2() const
133  { return capacity2_; }
134 
135  /*
136  * Return element (i,j) of matrix by const reference.
137  */
138  template <typename Data>
139  inline const Data& Matrix<Data>::operator() (int i, int j) const
140  {
141  assert(data_ != 0);
142  assert(i >= 0);
143  assert(i < capacity1_);
144  assert(j >= 0);
145  assert(j < capacity2_);
146  return *(data_ + i*capacity2_ + j);
147  }
148 
149  /*
150  * Return element (i,j) of matrix by reference.
151  */
152  template <typename Data>
153  inline Data& Matrix<Data>::operator() (int i, int j)
154  {
155  assert(data_ != 0);
156  assert(i >= 0);
157  assert(i < capacity1_);
158  assert(j >= 0);
159  assert(j < capacity2_);
160  return *(data_ + i*capacity2_ + j);
161  }
162 
163 }
164 #endif
int capacity2_
Number of columns (range of first index).
Definition: Matrix.h:79
File containing preprocessor macros for error handling.
int capacity2() const
Get number of columns (range of the second array index).
Definition: Matrix.h:132
int capacity1_
Number of rows (range of first index).
Definition: Matrix.h:76
Utility classes for scientific computation.
Definition: accumulators.mod:1
const Data & operator()(int i, int j) const
Return element (i,j) of matrix by const reference.
Definition: Matrix.h:139
Matrix()
Default constructor.
Definition: Matrix.h:108
int capacity1() const
Get number of rows (range of the first array index).
Definition: Matrix.h:125
Two-dimensional array container template (abstract).
Definition: Matrix.h:30
virtual ~Matrix()
Destructor.
Definition: Matrix.h:118
Data * data_
Pointer to 1D C array of all elements.
Definition: Matrix.h:73