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-2024 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 Type>
51 class TableReader
52 {
53 protected:
54 
55  // Protected Member Functions
56 
57  //- Do unit conversions on input data
58  void convertRead
59  (
62  ) const;
63 
64  //- Do unit conversions on input data
66  (
68  const List<Tuple2<scalar, Type>>& table
69  ) const;
70 
71  //- Do unit conversions in order to output data
73  (
75  const List<Tuple2<scalar, Type>>& table
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,
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<Type>> clone() const = 0;
108 
109 
110  // Selector
112  (
113  const word& name,
115  const dictionary& dict
116  );
117 
118 
119  //- Destructor
120  virtual ~TableReader();
121 
122 
123  // Member Functions
124 
125  //- Read values
127  (
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,
138  const List<Tuple2<scalar, Type>>& table,
139  const word& valuesKeyword="values"
140  ) const = 0;
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #define defineTableReader(Type) \
151  \
152  defineNamedTemplateTypeNameAndDebug(TableReader<Type>, 0); \
153  \
154  defineTemplateRunTimeSelectionTable(TableReader<Type>, dictionary);
155 
156 
157 #define addTableReader(SS, Type) \
158  \
159  defineNamedTemplateTypeNameAndDebug(TableReaders::SS<Type>, 0); \
160  \
161  addTemplatedToRunTimeSelectionTable(TableReader, SS, Type, dictionary)
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #ifdef NoRepository
167  #include "TableReader.C"
168  #include "TableReaderNew.C"
169 #endif
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 
173 #endif
174 
175 // ************************************************************************* //
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
virtual List< Tuple2< scalar, Type > > read(const Function1s::unitConversions &units, const dictionary &dict, const word &valuesKeyword="values") const =0
Read values.
TableReader()
Default construct.
Definition: TableReader.C:82
virtual void write(Ostream &os, const Function1s::unitConversions &units, const List< Tuple2< scalar, Type >> &table, const word &valuesKeyword="values") const =0
Write settings and values.
TypeName("TableReader")
Runtime type information.
declareRunTimeSelectionTable(autoPtr, TableReader, dictionary,(const word &name, const Function1s::unitConversions &units, const dictionary &dict),(name, units, dict))
static autoPtr< TableReader< Type > > New(const word &name, const Function1s::unitConversions &units, const dictionary &dict)
virtual ~TableReader()
Destructor.
Definition: TableReader.C:89
virtual autoPtr< TableReader< Type > > clone() const =0
Construct and return a clone.
List< Tuple2< scalar, Type > > convertWrite(const Function1s::unitConversions &units, const List< Tuple2< scalar, Type >> &table) const
Do unit conversions in order to output data.
Definition: TableReader.C:62
void convertRead(const Function1s::unitConversions &units, List< Tuple2< scalar, Type >> &table) const
Do unit conversions on input data.
Definition: TableReader.C:32
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:62
Namespace for OpenFOAM.
const HashTable< unitConversion > & units()
Get the table of unit conversions.
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