CSV.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 | Copyright (C) 2011-2015 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::CSV
26 
27 Description
28  Templated CSV container data entry. Reference column is always a scalar,
29  e.g. time
30 
31  \verbatim
32  <entryName> csvFile;
33  <entryName>Coeffs
34  {
35  nHeaderLine 4; // number of header lines
36  refColumn 0; // reference column index
37  componentColumns (1 2 3); // component column indices
38  separator ","; // optional (defaults to ",")
39  mergeSeparators no; // merge multiple separators
40  fileName "fileXYZ"; // name of csv data file
41  outOfBounds clamp; // optional out-of-bounds handling
42  interpolationScheme linear; // optional interpolation scheme
43  }
44  \endverbatim
45 
46 SourceFiles
47  CSV.C
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #ifndef CSV_H
52 #define CSV_H
53 
54 #include "DataEntry.H"
55 #include "TableBase.H"
56 #include "Tuple2.H"
57 #include "labelList.H"
58 #include "ISstream.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 template<class Type>
66 class CSV;
67 
68 template<class Type>
69 Ostream& operator<<
70 (
71  Ostream&,
72  const CSV<Type>&
73 );
74 
75 /*---------------------------------------------------------------------------*\
76  Class CSV Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type>
80 class CSV
81 :
82  public TableBase<Type>
83 {
84  // Private data
85 
86  //- Coefficients dictionary (for convenience on reading)
88 
89  //- Number header lines
91 
92  //- Column of the time
94 
95  //- Labels of the components
97 
98  //- Separator character
99  char separator_;
100 
101  //- Merge separators flag, e.g. ',,,' becomes ','
102  bool mergeSeparators_;
103 
104  //- File name for csv table
106 
107 
108  // Private Member Functions
109 
110  //- Read csv data table
111  void read();
112 
113  //- Read the next value from the splitted string
114  Type readValue(const List<string>&);
115 
116  //- Disallow default bitwise assignment
117  void operator=(const CSV<Type>&);
118 
119 
120 public:
121 
122  //- Runtime type information
123  TypeName("csvFile");
124 
125 
126  // Constructors
127 
128  //- Construct from entry name and dictionary
129  CSV
130  (
131  const word& entryName,
132  const dictionary& dict,
133  const word& ext = "Coeffs"
134  );
135 
136  //- Copy constructor
137  CSV(const CSV<Type>& tbl);
138 
139  //- Construct and return a clone
140  virtual tmp<DataEntry<Type> > clone() const
141  {
142  return tmp<DataEntry<Type> >(new CSV<Type>(*this));
143  }
144 
145 
146  //- Destructor
147  virtual ~CSV();
148 
149 
150  // Member Functions
151 
152  // Access
153 
154  //- Return const access to the file name
155  virtual const fileName& fName() const;
156 
157 
158  // I/O
159 
160  //- Ostream Operator
161  friend Ostream& operator<< <Type>
162  (
163  Ostream& os,
164  const CSV<Type>& cnst
165  );
166 
167  //- Write in dictionary format
168  virtual void writeData(Ostream& os) const;
169 };
170 
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 } // End namespace Foam
175 
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 
178 #ifdef NoRepository
179 # include "CSV.C"
180 #endif
181 
182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 
184 #endif
185 
186 // ************************************************************************* //
Foam::CSV::~CSV
virtual ~CSV()
Destructor.
Definition: CSV.C:245
Foam::CSV::separator_
char separator_
Separator character.
Definition: CSV.H:98
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Tuple2.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::CSV::clone
virtual tmp< DataEntry< Type > > clone() const
Construct and return a clone.
Definition: CSV.H:139
ISstream.H
Foam::CSV::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: CSVIO.C:60
Foam::CSV::refColumn_
label refColumn_
Column of the time.
Definition: CSV.H:92
Foam::CSV::CSV
CSV(const word &entryName, const dictionary &dict, const word &ext="Coeffs")
Construct from entry name and dictionary.
Foam::CSV::fName_
fileName fName_
File name for csv table.
Definition: CSV.H:104
Foam::CSV
Templated CSV container data entry. Reference column is always a scalar, e.g. time.
Definition: CSV.H:65
DataEntry.H
TableBase.H
Foam::label
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
labelList.H
Foam::CSV::mergeSeparators_
bool mergeSeparators_
Merge separators flag, e.g. ',,,' becomes ','.
Definition: CSV.H:101
Foam::CSV::TypeName
TypeName("csvFile")
Runtime type information.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::CSV::coeffs_
dictionary coeffs_
Coefficients dictionary (for convenience on reading)
Definition: CSV.H:86
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
CSV.C
Foam::CSV::fName
virtual const fileName & fName() const
Return const access to the file name.
Definition: CSV.C:252
Foam::CSV::operator=
void operator=(const CSV< Type > &)
Disallow default bitwise assignment.
Foam::CSV::read
void read()
Read csv data table.
Definition: CSV.C:88
Foam::CSV::componentColumns_
labelList componentColumns_
Labels of the components.
Definition: CSV.H:95
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::CSV::nHeaderLine_
label nHeaderLine_
Number header lines.
Definition: CSV.H:89
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::CSV::readValue
Type readValue(const List< string > &)
Read the next value from the splitted string.
Foam::TableBase
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:47