FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 {
41 }
42 
43 
44 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
45 
46 template<class Form, class Type>
48 {
49  return *reinterpret_cast< Matrix<Form, Type>* >(0);
50 }
51 
52 
53 //- Return the number of rows
54 template<class Form, class Type>
55 inline Foam::label Foam::Matrix<Form, Type>::n() const
56 {
57  return n_;
58 }
59 
60 
61 template<class Form, class Type>
62 inline Foam::label Foam::Matrix<Form, Type>::m() const
63 {
64  return m_;
65 }
66 
67 
68 template<class Form, class Type>
69 inline Foam::label Foam::Matrix<Form, Type>::size() const
70 {
71  return n_*m_;
72 }
73 
74 
75 template<class Form, class Type>
76 inline void Foam::Matrix<Form, Type>::checki(const label i) const
77 {
78  if (!n_)
79  {
80  FatalErrorIn("Matrix<Form, Type>::checki(const label)")
81  << "attempt to access element from zero sized row"
82  << abort(FatalError);
83  }
84  else if (i<0 || i>=n_)
85  {
86  FatalErrorIn("Matrix<Form, Type>::checki(const label)")
87  << "index " << i << " out of range 0 ... " << n_-1
88  << abort(FatalError);
89  }
90 }
91 
92 
93 template<class Form, class Type>
94 inline void Foam::Matrix<Form, Type>::checkj(const label j) const
95 {
96  if (!m_)
97  {
98  FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
99  << "attempt to access element from zero sized column"
100  << abort(FatalError);
101  }
102  else if (j<0 || j>=m_)
103  {
104  FatalErrorIn("Matrix<Form, Type>::checkj(const label)")
105  << "index " << j << " out of range 0 ... " << m_-1
106  << abort(FatalError);
107  }
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
112 
113 template<class Form, class Type>
114 inline Type* Foam::Matrix<Form, Type>::operator[](const label i)
115 {
116 # ifdef FULLDEBUG
117  checki(i);
118 # endif
119  return v_[i];
120 }
121 
122 
123 template<class Form, class Type>
124 inline const Type* Foam::Matrix<Form, Type>::operator[](const label i) const
125 {
126 # ifdef FULLDEBUG
127  checki(i);
128 # endif
129  return v_[i];
130 }
131 
132 
133 // ************************ vim: set sw=4 sts=4 et: ************************ //