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 = 0;
131 
132  //- Write settings and values
133  virtual void write
134  (
135  Ostream& os,
137  const List<Tuple2<scalar, Type>>& table
138  ) const;
139 };
140 
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 } // End namespace Foam
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #define defineTableReader(Type) \
149  \
150  defineNamedTemplateTypeNameAndDebug(TableReader<Type>, 0); \
151  \
152  defineTemplateRunTimeSelectionTable(TableReader<Type>, dictionary);
153 
154 
155 #define addTableReader(SS, Type) \
156  \
157  defineNamedTemplateTypeNameAndDebug(TableReaders::SS<Type>, 0); \
158  \
159  addTemplatedToRunTimeSelectionTable(TableReader, SS, Type, dictionary)
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #ifdef NoRepository
165  #include "TableReader.C"
166  #include "TableReaderNew.C"
167 #endif
168 
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 
171 #endif
172 
173 // ************************************************************************* //
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
Macros for creating standard TableReader-s.
Definition: TableReader.H:51
TableReader()
Default construct.
Definition: TableReader.C:82
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
virtual void write(Ostream &os, const Function1s::unitConversions &units, const List< Tuple2< scalar, Type >> &table) const
Write settings and values.
Definition: TableReader.C:97
virtual List< Tuple2< scalar, Type > > read(const Function1s::unitConversions &units, const dictionary &dict) const =0
Read values.
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 keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const HashTable< unitConversion > & units()
Get the table of unit conversions.
Macros to ease declaration of run-time selection tables.
dictionary dict