CsvTableReader.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-2019 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::TableReaders::Csv
26 
27 Description
28  Reads an interpolation table from a file in CSV-format. Entries govern the
29  layout of the CSV file. The index of the first (x) column of the table is
30  given by the refColumn entry, and is always scalar. The indices of the
31  components of the second (y) column are given by the componentColumns
32  entry.
33 
34  Usage:
35  \verbatim
36  nHeaderLine 4; // number of header lines
37  refColumn 0; // reference column index
38  componentColumns (1 2 3); // component column indices
39  separator ","; // optional (defaults to ",")
40  mergeSeparators no; // merge multiple separators
41  \endverbatim
42 
43 SourceFiles
44  CsvTableReader.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef CsvTableReader_H
49 #define CsvTableReader_H
50 
51 #include "TableReader.H"
52 #include "labelList.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 namespace TableReaders
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class Csv Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class Type>
66 class Csv
67 :
68  public TableReader<Type>
69 {
70  // Private Data
71 
72  //- Number of header lines
73  const label nHeaderLine_;
74 
75  //- Reference column
76  const label refColumn_;
77 
78  //- Labels of the components
79  const labelList componentColumns_;
80 
81  //- Separator character
82  const char separator_;
83 
84  //- Merge separators flag; e.g. ',,,' becomes ','
85  bool mergeSeparators_;
86 
87 
88  // Private Member functions
89 
90  //- Read the next value from the split string
91  Type readValue(const List<string>&) const;
92 
93  //- Read a 1D table
94  virtual void read(ISstream&, List<Tuple2<scalar, Type>>&) const;
95 
96  //- Read a 2D table
97  virtual void read
98  (
99  ISstream&,
101  ) const;
102 
103 
104 public:
105 
106  //- Runtime type information
107  TypeName("csv");
108 
109 
110  // Constructors
111 
112  //- Construct from dictionary
113  Csv(const dictionary& dict);
114 
115  //- Construct and return a copy
116  virtual autoPtr<TableReader<Type>> clone() const
117  {
118  return autoPtr<TableReader<Type>>(new Csv<Type>(*this));
119  }
120 
121 
122  //- Destructor
123  virtual ~Csv();
124 
125 
126  // Member Functions
127 
128  //- Write the remaining parameters
129  virtual void write(Ostream& os) const;
130 };
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace TableReaders
136 } // End namespace Foam
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 #ifdef NoRepository
141  #include "CsvTableReader.C"
142 #endif
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 #endif
147 
148 // ************************************************************************* //
TypeName("csv")
Runtime type information.
Base class to read table data for tables.
Definition: TableReader.H:52
dictionary dict
virtual autoPtr< TableReader< Type > > clone() const
Construct and return a copy.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
virtual void write(Ostream &os) const
Write the remaining parameters.
Reads an interpolation table from a file in CSV-format. Entries govern the layout of the CSV file...
virtual ~Csv()
Destructor.
Csv(const dictionary &dict)
Construct from dictionary.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
Generic input stream.
Definition: ISstream.H:51
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Namespace for OpenFOAM.