VTK  9.4.20250130
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
89#ifndef vtkDelimitedTextReader_h
90#define vtkDelimitedTextReader_h
91
92#include "vtkIOInfovisModule.h" // For export macro
93#include "vtkStdString.h" // Needed for vtkStdString
94#include "vtkTableAlgorithm.h"
95
96#include <memory>
97#include <string>
98
99VTK_ABI_NAMESPACE_BEGIN
100
101class vtkTextCodec;
102
103class VTKIOINFOVIS_EXPORT vtkDelimitedTextReader : public vtkTableAlgorithm
104{
105public:
108 void PrintSelf(ostream& os, vtkIndent indent) override;
109
111
117
119
125 void SetInputString(const char* in);
126 vtkGetStringMacro(InputString);
127 void SetInputString(const char* in, int len);
128 vtkGetMacro(InputStringLength, int);
129 void SetInputString(const vtkStdString& input)
130 {
131 this->SetInputString(input.c_str(), static_cast<int>(input.length()));
132 }
134
136
140 vtkSetMacro(ReadFromInputString, vtkTypeBool);
141 vtkGetMacro(ReadFromInputString, vtkTypeBool);
142 vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
144
146
157 vtkGetStringMacro(UnicodeCharacterSet);
158 vtkSetStringMacro(UnicodeCharacterSet);
160
162
167 void SetUTF8RecordDelimiters(const char* delimiters);
170
172
179 vtkSetStringMacro(FieldDelimiterCharacters);
180 vtkGetStringMacro(FieldDelimiterCharacters);
182
183 void SetUTF8FieldDelimiters(const char* delimiters);
185
187
196 vtkGetMacro(StringDelimiter, char);
197 vtkSetMacro(StringDelimiter, char);
199
200 void SetUTF8StringDelimiters(const char* delimiters);
202
204
207 vtkSetMacro(UseStringDelimiter, bool);
208 vtkGetMacro(UseStringDelimiter, bool);
209 vtkBooleanMacro(UseStringDelimiter, bool);
211
213
217 vtkGetMacro(HaveHeaders, bool);
218 vtkSetMacro(HaveHeaders, bool);
220
222
227 vtkSetMacro(MergeConsecutiveDelimiters, bool);
228 vtkGetMacro(MergeConsecutiveDelimiters, bool);
229 vtkBooleanMacro(MergeConsecutiveDelimiters, bool);
231
233
238 vtkGetMacro(MaxRecords, vtkIdType);
239 vtkSetMacro(MaxRecords, vtkIdType);
241
243
247 vtkGetMacro(SkippedRecords, vtkIdType);
248 vtkSetMacro(SkippedRecords, vtkIdType);
250
252
261 vtkSetMacro(DetectNumericColumns, bool);
262 vtkGetMacro(DetectNumericColumns, bool);
263 vtkBooleanMacro(DetectNumericColumns, bool);
265
267
272 vtkSetMacro(ForceDouble, bool);
273 vtkGetMacro(ForceDouble, bool);
274 vtkBooleanMacro(ForceDouble, bool);
276
278
293 vtkSetMacro(TrimWhitespacePriorToNumericConversion, bool);
294 vtkGetMacro(TrimWhitespacePriorToNumericConversion, bool);
295 vtkBooleanMacro(TrimWhitespacePriorToNumericConversion, bool);
297
299
303 vtkSetMacro(DefaultIntegerValue, int);
304 vtkGetMacro(DefaultIntegerValue, int);
306
308
312 vtkSetMacro(DefaultDoubleValue, double);
313 vtkGetMacro(DefaultDoubleValue, double);
315
317
321 vtkSetStringMacro(PedigreeIdArrayName);
322 vtkGetStringMacro(PedigreeIdArrayName);
324
326
330 vtkSetMacro(GeneratePedigreeIds, bool);
331 vtkGetMacro(GeneratePedigreeIds, bool);
332 vtkBooleanMacro(GeneratePedigreeIds, bool);
334
336
339 vtkSetMacro(OutputPedigreeIds, bool);
340 vtkGetMacro(OutputPedigreeIds, bool);
341 vtkBooleanMacro(OutputPedigreeIds, bool);
343
345
350 vtkSetMacro(AddTabFieldDelimiter, bool);
351 vtkGetMacro(AddTabFieldDelimiter, bool);
352 vtkBooleanMacro(AddTabFieldDelimiter, bool);
354
361
363
368 vtkSetMacro(ReplacementCharacter, vtkTypeUInt32);
369 vtkGetMacro(ReplacementCharacter, vtkTypeUInt32);
371
378 vtkGetMacro(Preview, std::string);
379
381
385 vtkSetMacro(PreviewNumberOfLines, vtkIdType);
386 vtkGetMacro(PreviewNumberOfLines, vtkIdType);
388
390
396 vtkGetMacro(CommentCharacters, std::string);
397 vtkSetMacro(CommentCharacters, std::string);
399
400protected:
403
406
407 // Read the content of the input file.
408 int ReadData(vtkTable* output_table);
409
410 char* FileName = nullptr;
411 vtkTypeBool ReadFromInputString = 0;
412 char* InputString = nullptr;
413 int InputStringLength = 0;
414 char* UnicodeCharacterSet = nullptr;
415 vtkIdType SkippedRecords = 0;
416 vtkIdType MaxRecords = 0;
417 std::string UnicodeRecordDelimiters = "\r\n";
418 std::string UnicodeFieldDelimiters = ",";
419 std::string UnicodeStringDelimiters = "\"";
420 std::string UnicodeWhitespace = " \t\r\n\v\f";
421 std::string UnicodeEscapeCharacter = "\\";
422 std::string CommentCharacters = "#";
423 bool DetectNumericColumns = false;
424 bool ForceDouble = false;
425 bool TrimWhitespacePriorToNumericConversion = false;
426 int DefaultIntegerValue = 0;
427 double DefaultDoubleValue = 0.;
428 char* FieldDelimiterCharacters = nullptr;
429 char StringDelimiter = '"';
430 bool UseStringDelimiter = true;
431 bool HaveHeaders = false;
432 bool MergeConsecutiveDelimiters = false;
433 char* PedigreeIdArrayName = nullptr;
434 bool GeneratePedigreeIds = true;
435 bool OutputPedigreeIds = false;
436 bool AddTabFieldDelimiter = false;
437 vtkStdString LastError = "";
438 vtkTypeUInt32 ReplacementCharacter = 'x';
439
440 std::string Preview;
441 vtkIdType PreviewNumberOfLines = 0;
442
443private:
448 std::unique_ptr<std::istream> OpenStream();
449
454 void ReadBOM(std::istream* stream);
455
460 vtkTextCodec* CreateTextCodec(std::istream* input_stream);
461
463 void operator=(const vtkDelimitedTextReader&) = delete;
464};
465
466VTK_ABI_NAMESPACE_END
467#endif
reads in delimited ascii or unicode text files and outputs a vtkTable data structure.
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.
int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
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:108
Store zero or more vtkInformation instances.
Store vtkAlgorithm input/output information.
Wrapper around std::string to keep symbols short.
Superclass for algorithms that produce only vtkTables as output.
A table, which contains similar-typed columns of data.
Definition vtkTable.h:169
Virtual class to act as an interface for all text codecs.
int vtkTypeBool
Definition vtkABI.h:64
int vtkIdType
Definition vtkType.h:315