csvTableReader.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::csvTableReader
29 
30 Description
31  Reads an interpolation table from a file - CSV-format
32 
33 SourceFiles
34  tableReader.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_csvTableReader_H
39 #define Foam_csvTableReader_H
40 
41 #include "tableReader.H"
42 #include "labelList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class csvTableReader Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 template<class Type>
54 class csvTableReader
55 :
56  public tableReader<Type>
57 {
58  // Private Data
59 
60  //- Does the file have a header line?
61  const bool headerLine_;
62 
63  //- Column for reference (lookup) value
64  const label refColumn_;
65 
66  //- Labels of the components
67  const labelList componentColumns_;
68 
69  //- Separator character
70  const char separator_;
71 
72 
73  // Private Member Functions
74 
75  //- Get component columns entry
76  static labelList getComponentColumns
77  (
78  const word& name,
79  std::initializer_list<std::pair<const char*,int>> compat,
80  const dictionary& dict
81  );
82 
83  //- Read component values from the split string
84  Type readValue(const UList<string>& strings) const;
85 
86 
87 public:
88 
89  //- Declare type-name, virtual type (with debug switch)
90  TypeName("csv");
91 
92 
93  // Constructors
94 
95  //- Construct from dictionary
97 
98  //- Construct and return a copy
99  virtual autoPtr<tableReader<Type>> clone() const
100  {
102  (
104  (
105  *this
106  )
107  );
108  }
109 
110 
111  //- Destructor
112  virtual ~csvTableReader() = default;
113 
114 
115  // Member Functions
116 
117  //- Read 1D table
118  virtual void operator()
119  (
120  const fileName& fName,
122  );
123 
124  //- Read 2D table - NotImplemented
125  virtual void operator()
126  (
127  const fileName& fName,
129  );
130 
131  //- Write the remaining parameters
132  virtual void write(Ostream& os) const;
133 };
134 
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 } // End namespace Foam
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #ifdef NoRepository
143  #include "csvTableReader.C"
144 #endif
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #endif
149 
150 // ************************************************************************* //
Reads an interpolation table from a file - CSV-format.
dictionary dict
A class for handling file names.
Definition: fileName.H:72
virtual ~csvTableReader()=default
Destructor.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
TypeName("csv")
Declare type-name, virtual type (with debug switch)
virtual autoPtr< tableReader< Type > > clone() const
Construct and return a copy.
Base class to read table data for the interpolationTable.
Definition: tableReader.H:56
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
csvTableReader(const dictionary &dict)
Construct from dictionary.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
virtual void write(Ostream &os) const
Write the remaining parameters.
Namespace for OpenFOAM.