VTK  9.4.20251007
vtkDelimitedTextReader.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright 2008 Sandia Corporation
3// SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
4
49
50#ifndef vtkDelimitedTextReader_h
51#define vtkDelimitedTextReader_h
52
53#include "vtkIOInfovisModule.h" // For export macro
54#include "vtkStdString.h" // Needed for vtkStdString
55#include "vtkTableAlgorithm.h"
56
57#include <memory>
58#include <string>
59
60VTK_ABI_NAMESPACE_BEGIN
61
62class vtkTextCodec;
63
64class VTKIOINFOVIS_EXPORT vtkDelimitedTextReader : public vtkTableAlgorithm
65{
66public:
69 void PrintSelf(ostream& os, vtkIndent indent) override;
70
72
78
80
86 void SetInputString(const char* in);
87 vtkGetStringMacro(InputString);
88 void SetInputString(const char* in, int len);
89 vtkGetMacro(InputStringLength, int);
90 void SetInputString(const vtkStdString& input)
91 {
92 this->SetInputString(input.c_str(), static_cast<int>(input.length()));
93 }
94
95
97
105
107
118 vtkGetStringMacro(UnicodeCharacterSet);
119 vtkSetStringMacro(UnicodeCharacterSet);
121
123
128 void SetUTF8RecordDelimiters(const char* delimiters);
131
133
140 vtkSetStringMacro(FieldDelimiterCharacters);
141 vtkGetStringMacro(FieldDelimiterCharacters);
143
144 void SetUTF8FieldDelimiters(const char* delimiters);
146
148
157 vtkGetMacro(StringDelimiter, char);
158 vtkSetMacro(StringDelimiter, char);
160
161 void SetUTF8StringDelimiters(const char* delimiters);
163
165
168 vtkSetMacro(UseStringDelimiter, bool);
169 vtkGetMacro(UseStringDelimiter, bool);
170 vtkBooleanMacro(UseStringDelimiter, bool);
172
174
178 vtkGetMacro(HaveHeaders, bool);
179 vtkSetMacro(HaveHeaders, bool);
181
183
188 vtkSetMacro(MergeConsecutiveDelimiters, bool);
189 vtkGetMacro(MergeConsecutiveDelimiters, bool);
190 vtkBooleanMacro(MergeConsecutiveDelimiters, bool);
192
194
198 vtkGetMacro(MaxRecords, vtkIdType);
199 vtkSetMacro(MaxRecords, vtkIdType);
201
203
212 vtkSetMacro(DetectNumericColumns, bool);
213 vtkGetMacro(DetectNumericColumns, bool);
214 vtkBooleanMacro(DetectNumericColumns, bool);
216
218
223 vtkSetMacro(ForceDouble, bool);
224 vtkGetMacro(ForceDouble, bool);
225 vtkBooleanMacro(ForceDouble, bool);
227
229
248
250
254 vtkSetMacro(DefaultIntegerValue, int);
255 vtkGetMacro(DefaultIntegerValue, int);
257
259
263 vtkSetMacro(DefaultDoubleValue, double);
264 vtkGetMacro(DefaultDoubleValue, double);
266
268
272 vtkSetStringMacro(PedigreeIdArrayName);
273 vtkGetStringMacro(PedigreeIdArrayName);
275
277
281 vtkSetMacro(GeneratePedigreeIds, bool);
282 vtkGetMacro(GeneratePedigreeIds, bool);
283 vtkBooleanMacro(GeneratePedigreeIds, bool);
285
287
290 vtkSetMacro(OutputPedigreeIds, bool);
291 vtkGetMacro(OutputPedigreeIds, bool);
292 vtkBooleanMacro(OutputPedigreeIds, bool);
294
296
301 vtkSetMacro(AddTabFieldDelimiter, bool);
302 vtkGetMacro(AddTabFieldDelimiter, bool);
303 vtkBooleanMacro(AddTabFieldDelimiter, bool);
305
312
314
319 vtkSetMacro(ReplacementCharacter, vtkTypeUInt32);
320 vtkGetMacro(ReplacementCharacter, vtkTypeUInt32);
322
323protected:
326
328
329 // Read the content of the input file.
330 int ReadData(vtkTable* output_table);
331
332 char* FileName = nullptr;
334 char* InputString = nullptr;
336 char* UnicodeCharacterSet = nullptr;
338 std::string UnicodeRecordDelimiters = "\r\n";
339 std::string UnicodeFieldDelimiters = ",";
340 std::string UnicodeStringDelimiters = "\"";
341 std::string UnicodeWhitespace = " \t\r\n\v\f";
342 std::string UnicodeEscapeCharacter = "\\";
344 bool ForceDouble = false;
349 char StringDelimiter = '"';
351 bool HaveHeaders = false;
353 char* PedigreeIdArrayName = nullptr;
355 bool OutputPedigreeIds = false;
358 vtkTypeUInt32 ReplacementCharacter = 'x';
359
360private:
365 std::unique_ptr<std::istream> OpenStream();
366
371 void ReadBOM(std::istream* stream);
372
377 vtkTextCodec* CreateTextCodec(std::istream* input_stream);
378
380 void operator=(const vtkDelimitedTextReader&) = delete;
381};
382
383VTK_ABI_NAMESPACE_END
384#endif
void SetInputString(const char *in, int len)
Specify the InputString for use when reading from a character array.
int ReadData(vtkTable *output_table)
~vtkDelimitedTextReader() override
void SetUTF8RecordDelimiters(const char *delimiters)
Specify the character(s) that will be used to separate records.
vtkStdString GetLastError()
Returns a human-readable description of the most recent error, if any.
void SetInputString(const char *in)
Specify the InputString for use when reading from a character array.
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
This is called by the superclass.
void SetUTF8StringDelimiters(const char *delimiters)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkGetFilePathMacro(FileName)
Specifies the delimited text file to be loaded.
const char * GetUTF8StringDelimiters()
vtkSetFilePathMacro(FileName)
Specifies the delimited text file to be loaded.
static vtkDelimitedTextReader * New()
const char * GetUTF8RecordDelimiters()
Specify the character(s) that will be used to separate records.
void SetInputString(const vtkStdString &input)
Specify the InputString for use when reading from a character array.
const char * GetUTF8FieldDelimiters()
void SetUTF8FieldDelimiters(const char *delimiters)
a simple class to control print indentation
Definition vtkIndent.h:29
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Wrapper around std::string to keep symbols short.
A table, which contains similar-typed columns of data.
Definition vtkTable.h:60
Virtual class to act as an interface for all text codecs.
int vtkTypeBool
Definition vtkABI.h:64
int vtkIdType
Definition vtkType.h:315