VectorSpace.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-2013 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 Class
25  Foam::VectorSpace
26 
27 Description
28  Templated vector space.
29 
30  Template arguments are the Form the vector space will be used to create,
31  the type of the elements and the number of elements.
32 
33 SourceFiles
34  VectorSpaceI.H
35  VectorSpace.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef VectorSpace_H
40 #define VectorSpace_H
41 
42 #include "direction.H"
43 #include "scalar.H"
44 #include "word.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of friend functions and operators
52 
53 template<class Form, class Cmpt, int nCmpt> class VectorSpace;
54 
55 template<class Form, class Cmpt, int nCmpt>
56 Istream& operator>>
57 (
58  Istream&,
60 );
61 
62 template<class Form, class Cmpt, int nCmpt>
63 Ostream& operator<<
64 (
65  Ostream&,
67 );
68 
69 
70 /*---------------------------------------------------------------------------*\
71  Class VectorSpace Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 template<class Form, class Cmpt, int nCmpt>
75 class VectorSpace
76 {
77 
78 public:
79 
80  //- Component type
81  typedef Cmpt cmptType;
82 
83 
84  // Member constants
85 
86  enum
87  {
88  dim = 3,
89  nComponents = nCmpt
90  };
91 
92 
93  // Static data members
94 
95  //- The components of this vector space
96  Cmpt v_[nCmpt];
97 
98 
99  // Constructors
100 
101  //- Construct null
102  inline VectorSpace();
103 
104  //- Construct from Istream
106 
107  //- Construct as copy
109 
110  //- Construct as copy of another VectorSpace type of the same rank
111  template<class Form2, class Cmpt2>
113 
114 
115  // Member Functions
116 
117  //- Return the number of elements in the VectorSpace = nCmpt.
118  inline label size() const;
119 
120  inline const Cmpt& component(const direction) const;
121  inline Cmpt& component(const direction);
122 
123  inline void component(Cmpt&, const direction) const;
124  inline void replace(const direction, const Cmpt&);
125 
126 
127  // Member Operators
128 
129  inline const Cmpt& operator[](const direction) const;
130  inline Cmpt& operator[](const direction);
131 
132  inline void operator=(const VectorSpace<Form, Cmpt, nCmpt>&);
133  inline void operator+=(const VectorSpace<Form, Cmpt, nCmpt>&);
134  inline void operator-=(const VectorSpace<Form, Cmpt, nCmpt>&);
135 
136  inline void operator*=(const scalar);
137  inline void operator/=(const scalar);
138 
139 
140  // IOstream Operators
141 
142  friend Istream& operator>> <Form, Cmpt, nCmpt>
143  (
144  Istream&,
146  );
147 
148  friend Ostream& operator<< <Form, Cmpt, nCmpt>
149  (
150  Ostream&,
152  );
153 };
154 
155 
156 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
157 
158 //- Return a string representation of a VectorSpace
159 template<class Form, class Cmpt, int nCmpt>
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #include "VectorSpaceI.H"
169 
170 #ifdef NoRepository
171 # include "VectorSpace.C"
172 #endif
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #endif
177 
178 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::VectorSpace::operator[]
const Cmpt & operator[](const direction) const
Foam::VectorSpace::operator-=
void operator-=(const VectorSpace< Form, Cmpt, nCmpt > &)
Definition: VectorSpaceI.H:213
Foam::VectorSpace::size
label size() const
Return the number of elements in the VectorSpace = nCmpt.
Definition: VectorSpaceI.H:67
Foam::VectorSpace::operator*=
void operator*=(const scalar)
Definition: VectorSpaceI.H:223
Foam::VectorSpace::nComponents
@ nComponents
Number of components in this vector space.
Definition: VectorSpace.H:88
Foam::VectorSpace::component
const Cmpt & component(const direction) const
Foam::VectorSpace::cmptType
Cmpt cmptType
Component type.
Definition: VectorSpace.H:80
Foam::VectorSpace
Templated vector space.
Definition: VectorSpace.H:52
Foam::label
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
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::VectorSpace::VectorSpace
VectorSpace()
Construct null.
Definition: VectorSpaceI.H:39
Foam::VectorSpace::operator/=
void operator/=(const scalar)
Definition: VectorSpaceI.H:233
VectorSpaceI.H
Foam::VectorSpace::v_
Cmpt v_[nCmpt]
The components of this vector space.
Definition: VectorSpace.H:95
Foam::VectorSpace::replace
void replace(const direction, const Cmpt &)
Definition: VectorSpaceI.H:133
scalar.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
direction.H
Direction is an integer type used to represent the Cartesian directions etc. Currently it is a typede...
Foam::VectorSpace::operator=
void operator=(const VectorSpace< Form, Cmpt, nCmpt > &)
Definition: VectorSpaceI.H:193
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::VectorSpace::dim
@ dim
Dimensionality of space.
Definition: VectorSpace.H:87
Foam::VectorSpace::operator+=
void operator+=(const VectorSpace< Form, Cmpt, nCmpt > &)
Definition: VectorSpaceI.H:203
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
word.H
VectorSpace.C
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47