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  const dictionary& dict
80  );
81 
82  //- Read component values from the split string
83  Type readValue(const List<string>& strings) const;
84 
85 
86 public:
87 
88  //- Declare type-name, virtual type (with debug switch)
89  TypeName("csv");
90 
91 
92  // Constructors
93 
94  //- Construct from dictionary
96 
97  //- Construct and return a copy
98  virtual autoPtr<tableReader<Type>> clone() const
99  {
101  (
103  (
104  *this
105  )
106  );
107  }
108 
109 
110  //- Destructor
111  virtual ~csvTableReader() = default;
112 
113 
114  // Member Functions
115 
116  //- Read 1D table
117  virtual void operator()
118  (
119  const fileName& fName,
121  );
122 
123  //- Read 2D table - NotImplemented
124  virtual void operator()
125  (
126  const fileName& fName,
128  );
129 
130  //- Write the remaining parameters
131  virtual void write(Ostream& os) const;
132 };
133 
134 
135 // Template specialisations
136 template<>
137 label csvTableReader<label>::readValue(const List<string>& strings) const;
138 
139 template<>
140 scalar csvTableReader<scalar>::readValue(const List<string>& strings) const;
141 
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 } // End namespace Foam
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 #ifdef NoRepository
150  #include "csvTableReader.C"
151 #endif
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #endif
156 
157 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
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:112
Foam::csvTableReader::write
virtual void write(Ostream &os) const
Write the remaining parameters.
Definition: csvTableReader.C:216
labelList.H
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
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:121
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:97
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::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:54
tableReader.H