Constant.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 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::Constant
26 
27 Description
28  Templated basic entry that holds a constant value.
29 
30  Usage - for entry <entryName> having the value <value>:
31  \verbatim
32  <entryName> constant <value>
33  \endverbatim
34 
35 SourceFiles
36  Constant.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Constant_H
41 #define Constant_H
42 
43 #include "DataEntry.H"
44 #include "dimensionSet.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 template<class Type>
52 class Constant;
53 
54 template<class Type>
55 Ostream& operator<<(Ostream&, const Constant<Type>&);
56 
57 /*---------------------------------------------------------------------------*\
58  Class Constant Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type>
62 class Constant
63 :
64  public DataEntry<Type>
65 {
66  // Private data
67 
68  //- Constant value
69  Type value_;
70 
71  //- The dimension set
72  dimensionSet dimensions_;
73 
74 
75  // Private Member Functions
76 
77  //- Disallow default bitwise assignment
78  void operator=(const Constant<Type>&);
79 
80 
81 public:
82 
83  // Runtime type information
84  TypeName("constant");
85 
86 
87  // Constructors
88 
89  //- Construct from entry name and Istream
90  Constant(const word& entryName, const dictionary& dict);
91 
92  //- Copy constructor
93  Constant(const Constant<Type>& cnst);
94 
95  //- Construct and return a clone
96  virtual tmp<DataEntry<Type> > clone() const
97  {
98  return tmp<DataEntry<Type> >(new Constant<Type>(*this));
99  }
100 
101 
102  //- Destructor
103  virtual ~Constant();
104 
105 
106  // Member Functions
107 
108  //- Return constant value
109  Type value(const scalar) const;
110 
111  //- Integrate between two values
112  Type integrate(const scalar x1, const scalar x2) const;
113 
114  //- Return dimensioned constant value
115  dimensioned<Type> dimValue(const scalar) const;
116 
117  //- Integrate between two values and return dimensioned type
119  (
120  const scalar x1,
121  const scalar x2
122  ) const;
123 
124 
125  // I/O
126 
127  //- Ostream Operator
128  friend Ostream& operator<< <Type>
129  (
130  Ostream& os,
131  const Constant<Type>& cnst
132  );
133 
134  //- Write in dictionary format
135  virtual void writeData(Ostream& os) const;
136 };
137 
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 } // End namespace Foam
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 #ifdef NoRepository
146 # include "Constant.C"
147 #endif
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #endif
152 
153 // ************************************************************************* //
TypeName("constant")
A class for handling words, derived from string.
Definition: word.H:59
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: ConstantIO.C:63
const word const dictionary & dict
Definition: DataEntry.H:93
virtual ~Constant()
Destructor.
Definition: Constant.C:70
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
const word & entryName
Definition: DataEntry.H:93
Generic dimensioned Type class.
Constant(const word &entryName, const dictionary &dict)
Construct from entry name and Istream.
Definition: Constant.C:31
Templated basic entry that holds a constant value.
Definition: Constant.H:51
Dimension set for the base types.
Definition: dimensionSet.H:116
virtual tmp< DataEntry< Type > > clone() const
Construct and return a clone.
Definition: Constant.H:95
Type integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: Constant.C:84
Type value(const scalar) const
Return constant value.
Definition: Constant.C:77
dimensioned< Type > dimValue(const scalar) const
Return dimensioned constant value.
Definition: Constant.C:91
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
dimensioned< Type > dimIntegrate(const scalar x1, const scalar x2) const
Integrate between two values and return dimensioned type.
Definition: Constant.C:99
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: DataEntry.H:52
A class for managing temporary objects.
Definition: PtrList.H:118