TableReader.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 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::TableReader
26 
27 Description
28  Base class to read table data for tables
29 
30 SourceFiles
31  TableReader.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef TableReader_H
36 #define TableReader_H
37 
38 #include "Function1.H"
39 #include "runTimeSelectionTables.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class TableReader Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 template<class Coordinate, class Value>
51 class TableReader
52 {
53 protected:
54 
55  // Protected Member Functions
56 
57  //- Do unit conversions on input data
58  void convertRead
59  (
60  const Function1s::unitSets& units,
62  ) const;
63 
64  //- Do unit conversions on input data
66  (
67  const Function1s::unitSets& units,
69  ) const;
70 
71  //- Do unit conversions in order to output data
73  (
74  const Function1s::unitSets& units,
76  ) const;
77 
78 
79 public:
80 
81  //- Runtime type information
82  TypeName("TableReader");
83 
84 
85  // Declare run-time constructor selection table
86 
88  (
89  autoPtr,
91  dictionary,
92  (
93  const word& name,
94  const Function1s::unitSets& units,
95  const dictionary& dict
96  ),
97  (name, units, dict)
98  );
99 
100 
101  // Constructors
102 
103  //- Default construct
104  TableReader();
105 
106  //- Construct and return a clone
107  virtual autoPtr<TableReader<Coordinate, Value>> clone() const = 0;
108 
109 
110  // Selector
112  (
113  const word& name,
114  const Function1s::unitSets& units,
115  const dictionary& dict
116  );
117 
118 
119  //- Destructor
120  virtual ~TableReader();
121 
122 
123  // Member Functions
124 
125  //- Read values
127  (
128  const Function1s::unitSets& units,
129  const dictionary& dict,
130  const word& valuesKeyword="values"
131  ) const = 0;
132 
133  //- Write settings and values
134  virtual void write
135  (
136  Ostream& os,
137  const Function1s::unitSets& units,
139  const word& valuesKeyword="values"
140  ) const = 0;
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #define defineTableReader(Coordinate, Value) \
151  \
152  typedef TableReader<Coordinate, Value> \
153  TableReader##Coordinate##Value; \
154  \
155  defineNamedTemplateTypeNameAndDebug \
156  ( \
157  TableReader##Coordinate##Value, \
158  0 \
159  ); \
160  \
161  defineTemplateRunTimeSelectionTable \
162  ( \
163  TableReader##Coordinate##Value, \
164  dictionary \
165  );
166 
167 
168 #define addTableReader(TableReaderType, Coordinate, Value) \
169  \
170  typedef TableReader<Coordinate, Value> \
171  TableReader##Coordinate##Value; \
172  \
173  namespace TableReaders \
174  { \
175  typedef TableReaderType<Coordinate, Value> \
176  TableReaderType##TableReader##Coordinate##Value; \
177  \
178  defineNamedTemplateTypeNameAndDebug \
179  ( \
180  TableReaderType##TableReader##Coordinate##Value, \
181  0 \
182  ); \
183  \
184  addToRunTimeSelectionTable \
185  ( \
186  TableReader##Coordinate##Value, \
187  TableReaderType##TableReader##Coordinate##Value, \
188  dictionary \
189  ); \
190  }
191 
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #ifdef NoRepository
196  #include "TableReader.C"
197  #include "TableReaderNew.C"
198 #endif
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #endif
203 
204 // ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Base class to read table data for tables.
Definition: TableReader.H:51
void convertRead(const Function1s::unitSets &units, List< Tuple2< Coordinate, Value >> &table) const
Do unit conversions on input data.
Definition: TableReader.C:32
TableReader()
Default construct.
Definition: TableReader.C:82
TypeName("TableReader")
Runtime type information.
static autoPtr< TableReader< Coordinate, Value > > New(const word &name, const Function1s::unitSets &units, const dictionary &dict)
virtual void write(Ostream &os, const Function1s::unitSets &units, const List< Tuple2< Coordinate, Value >> &table, const word &valuesKeyword="values") const =0
Write settings and values.
virtual ~TableReader()
Destructor.
Definition: TableReader.C:89
virtual autoPtr< TableReader< Coordinate, Value > > clone() const =0
Construct and return a clone.
virtual List< Tuple2< Coordinate, Value > > read(const Function1s::unitSets &units, const dictionary &dict, const word &valuesKeyword="values") const =0
Read values.
List< Tuple2< Coordinate, Value > > convertWrite(const Function1s::unitSets &units, const List< Tuple2< Coordinate, Value >> &table) const
Do unit conversions in order to output data.
Definition: TableReader.C:62
declareRunTimeSelectionTable(autoPtr, TableReader, dictionary,(const word &name, const Function1s::unitSets &units, const dictionary &dict),(name, units, dict))
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:63
const HashTable< dimensionSet > table
Table of dimensions.
Definition: dimensions.C:74
Namespace for OpenFOAM.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Macros to ease declaration of run-time selection tables.
dictionary dict
Struct containing two unitSets for use in converting both the argument and the value of a Function1.