Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Matrix_Base class definition file. -*- C++ -*-
/* Copyright 2008 Mike Williams (mwill@jlab.org)
*
* This file is part of qft++.
*
* qft++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* qft++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qft++. If not, see <http://www.gnu.org/licenses/>.
*/
// Author: Mike Williams
#ifndef _Matrix_Base_H
#define _Matrix_Base_H
#include <cassert>
#include "qft++/c++-template-utils/Conversion.hh"
//_____________________________________________________________________________
/** @file Matrix_Base.h
* @brief Matrix_Base class definition file (also defines IsMatrix macro).
*/
//_____________________________________________________________________________
using namespace std;
//_____________________________________________________________________________
/** @class Matrix_Base
* @author Mike Williams
*
* @brief Base class for all Matrix template classes.
*
* This is the base class for all Matrix instantiations. It is thru inheritance
* from this class that the Matrix template classes are able to correctly
* implement multiplication.
*/
//_____________________________________________________________________________
class Matrix_Base {
protected:
// attributes:
int _num_rows; ///< Number of rows in the Matrix
int _num_cols; ///< Number of columns in the Matrix
// protected functions:
/// Copy @a mbase data members
void _Copy(const Matrix_Base &__mbase){
_num_rows = __mbase._num_rows;
_num_cols = __mbase._num_cols;
}
/// Assert that @a mbase and @a this have the same size
void _SizeAssert(const Matrix_Base &__mbase) const {
assert(this->_num_rows == __mbase._num_rows
&& this->_num_cols == __mbase._num_cols);
}
public:
// create/copy/destroy:
/// Default Constructor (0x0)
Matrix_Base(){
_num_rows = 0;
_num_cols = 0;
}
/** Constructor
* @param rows Number of rows
* @param cols Number of columns
*/
Matrix_Base(int __rows,int __cols){
_num_rows = __rows;
_num_cols = __cols;
}
/// Copy Constructor
Matrix_Base(const Matrix_Base &__mbase){
this->_Copy(__mbase);
}
/** Destructor */
virtual ~Matrix_Base(){}
// Getters:
/** Returns the number of rows */
int NumRows() const {return _num_rows;}
/** Returns the number of columns */
int NumCols() const {return _num_cols;}
/** Returns the number of elements */
int Size() const {
return _num_rows * _num_cols;
}
// functions:
/// Is @a mbase the same size as this?
bool SizeCheck(const Matrix_Base &__mbase) const {
return (__mbase._num_rows == this->_num_rows
&& __mbase._num_cols == this->_num_cols);
}
};
//_____________________________________________________________________________
/// Is T a Matrix? (does it inherit from Matrix_Base?)
#define IsMatrix(__T) IsDerived(__T,Matrix_Base)
//_____________________________________________________________________________
#endif /* _Matrix_Base_H */