MatrixI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class Form, class Type>
30 :
31  n_(0),
32  m_(0),
33  v_(NULL)
34 {}
35 
36 
37 template<class Form, class Type>
39 clone() const
40 {
42 }
43 
44 
45 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
46 
47 template<class Form, class Type>
49 {
50  return NullObjectRef<Matrix<Form, Type> >();
51 }
52 
53 
54 //- Return the number of rows
55 template<class Form, class Type>
57 {
58  return n_;
59 }
60 
61 
62 template<class Form, class Type>
64 {
65  return m_;
66 }
67 
68 
69 template<class Form, class Type>
71 {
72  return n_*m_;
73 }
74 
75 
76 template<class Form, class Type>
77 inline void Foam::Matrix<Form, Type>::checki(const label i) const
78 {
79  if (!n_)
80  {
81  FatalErrorIn("Matrix<Form, Type>::checki(const label)")
82  << "attempt to access element from zero sized row"
83  << abort(FatalError);
84  }
85  else if (i<0 || i>=n_)
86  {
87  FatalErrorIn("Matrix<Form, Type>::checki(const label)")
88  << "index " << i << " out of range 0 ... " << n_-1
89  << abort(FatalError);
90  }
91 }
92 
93 
94 template<class Form, class Type>
95 inline void Foam::Matrix<Form, Type>::checkj(const label j) const
96 {
97  if (!m_)
98  {
99  FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
100  << "attempt to access element from zero sized column"
101  << abort(FatalError);
102  }
103  else if (j<0 || j>=m_)
104  {
105  FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
106  << "index " << j << " out of range 0 ... " << m_-1
107  << abort(FatalError);
108  }
109 }
110 
111 
112 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
113 
114 template<class Form, class Type>
116 {
117 # ifdef FULLDEBUG
118  checki(i);
119 # endif
120  return v_[i];
121 }
122 
123 
124 template<class Form, class Type>
125 inline const Type* Foam::Matrix<Form, Type>::operator[](const label i) const
126 {
127 # ifdef FULLDEBUG
128  checki(i);
129 # endif
130  return v_[i];
131 }
132 
133 
134 // ************************************************************************* //
A templated 2D matrix of objects of <T>, where the n x m matrix dimensions are known and used for sub...
Matrix()
Null constructor.
Definition: MatrixI.H:29
label size() const
Return the number of elements in matrix (n*m)
Definition: MatrixI.H:70
Type * operator[](const label)
Return subscript-checked row of Matrix.
Definition: MatrixI.H:115
label n() const
Return the number of rows.
Definition: MatrixI.H:56
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
static const Matrix< Form, Type > & null()
Return a null Matrix.
Definition: MatrixI.H:48
autoPtr< Matrix< Form, Type > > clone() const
Clone.
Definition: MatrixI.H:39
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
void checkj(const label j) const
Check index j is within valid range (0 ... m-1).
Definition: MatrixI.H:95
error FatalError
void checki(const label i) const
Check index i is within valid range (0 ... n-1).
Definition: MatrixI.H:77
label m() const
Return the number of columns.
Definition: MatrixI.H:63
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117