Line | Branch | Exec | Source |
---|---|---|---|
1 | // This file is part of Bembel, the higher order C++ boundary element library. | ||
2 | // | ||
3 | // Copyright (C) 2022 see <http://www.bembel.eu> | ||
4 | // | ||
5 | // It was written as part of a cooperation of J. Doelz, H. Harbrecht, S. Kurz, | ||
6 | // M. Multerer, S. Schoeps, and F. Wolf at Technische Universitaet Darmstadt, | ||
7 | // Universitaet Basel, and Universita della Svizzera italiana, Lugano. This | ||
8 | // source code is subject to the GNU General Public License version 3 and | ||
9 | // provided WITHOUT ANY WARRANTY, see <http://www.bembel.eu> for further | ||
10 | // information. | ||
11 | #ifndef BEMBEL_SRC_UTIL_GENERICMATRIX_HPP_ | ||
12 | #define BEMBEL_SRC_UTIL_GENERICMATRIX_HPP_ | ||
13 | |||
14 | #include <vector> | ||
15 | |||
16 | namespace Bembel { | ||
17 | template <typename T> | ||
18 | class GenericMatrix { | ||
19 | public: | ||
20 | typedef typename std::vector<std::vector<T> >::size_type colIndex; | ||
21 | typedef typename std::vector<T>::size_type rowIndex; | ||
22 | ////////////////////////////////////////////////////////////////////////////// | ||
23 | // constructors | ||
24 | ////////////////////////////////////////////////////////////////////////////// | ||
25 | 7982 | GenericMatrix() : rows_(0), cols_(0) {} | |
26 | |||
27 | GenericMatrix(rowIndex rows, colIndex cols) { resize(rows, cols); } | ||
28 | |||
29 | 4904 | GenericMatrix(const GenericMatrix& other) { | |
30 | 4904 | rows_ = other.rows_; | |
31 | 4904 | cols_ = other.cols_; | |
32 |
1/2✓ Branch 1 taken 4904 times.
✗ Branch 2 not taken.
|
4904 | m_data_ = other.m_data_; |
33 | 4904 | } | |
34 | |||
35 | 24 | GenericMatrix(GenericMatrix&& other) { | |
36 | 24 | rows_ = other.rows_; | |
37 | 24 | cols_ = other.cols_; | |
38 | 24 | m_data_ = std::move(other.m_data_); | |
39 | 24 | } | |
40 | ////////////////////////////////////////////////////////////////////////////// | ||
41 | // methods | ||
42 | ////////////////////////////////////////////////////////////////////////////// | ||
43 | 190 | void resize(rowIndex rows, colIndex cols) { | |
44 | 190 | m_data_.resize(cols); | |
45 |
3/4✓ Branch 3 taken 756 times.
✗ Branch 4 not taken.
✓ Branch 8 taken 756 times.
✓ Branch 9 taken 190 times.
|
946 | for (auto it = m_data_.begin(); it != m_data_.end(); ++it) it->resize(rows); |
46 | 190 | rows_ = rows; | |
47 | 190 | cols_ = cols; | |
48 | 190 | return; | |
49 | } | ||
50 | |||
51 | 4862 | colIndex cols() const { return cols_; } | |
52 | |||
53 | 19812 | rowIndex rows() const { return rows_; } | |
54 | ////////////////////////////////////////////////////////////////////////////// | ||
55 | // operators | ||
56 | ////////////////////////////////////////////////////////////////////////////// | ||
57 | 748074 | const T& operator()(rowIndex row, colIndex col) const { | |
58 | 748074 | return m_data_[col][row]; | |
59 | } | ||
60 | |||
61 | 34118 | T& operator()(rowIndex row, colIndex col) { return m_data_[col][row]; } | |
62 | |||
63 | 4920 | GenericMatrix& operator=(GenericMatrix other) { | |
64 | 4920 | rows_ = other.rows_; | |
65 | 4920 | cols_ = other.cols_; | |
66 | 4920 | std::swap(m_data_, other.m_data_); | |
67 | 4920 | return *this; | |
68 | } | ||
69 | ////////////////////////////////////////////////////////////////////////////// | ||
70 | // private members | ||
71 | ////////////////////////////////////////////////////////////////////////////// | ||
72 | private: | ||
73 | std::vector<std::vector<T> > m_data_; | ||
74 | colIndex cols_; | ||
75 | rowIndex rows_; | ||
76 | }; | ||
77 | } // namespace Bembel | ||
78 | #endif // BEMBEL_SRC_UTIL_GENERICMATRIX_HPP_ | ||
79 |