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 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 csvTableReader_H
39 #define 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 List<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 // Template specialisations
137 template<>
138 label csvTableReader<label>::readValue(const List<string>& strings) const;
139 
140 template<>
141 scalar csvTableReader<scalar>::readValue(const List<string>& strings) const;
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace Foam
147 
148 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149 
150 #ifdef NoRepository
151  #include "csvTableReader.C"
152 #endif
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 #endif
157 
158 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::tableReader
Base class to read table data for the interpolationTable.
Definition: tableReader.H:60
Foam::csvTableReader::csvTableReader
csvTableReader(const dictionary &dict)
Construct from dictionary.
Definition: csvTableReader.C:113
Foam::csvTableReader::write
virtual void write(Ostream &os) const
Write the remaining parameters.
Definition: csvTableReader.C:220
labelList.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::csvTableReader
Reads an interpolation table from a file - CSV-format.
Definition: csvTableReader.H:53
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::csvTableReader::~csvTableReader
virtual ~csvTableReader()=default
Destructor.
Foam::csvTableReader::clone
virtual autoPtr< tableReader< Type > > clone() const
Construct and return a copy.
Definition: csvTableReader.H:98
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::csvTableReader::TypeName
TypeName("csv")
Declare type-name, virtual type (with debug switch)
Foam::List< label >
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
csvTableReader.C
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
tableReader.H