VTK  9.7.1
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 
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 
60 VTK_ABI_NAMESPACE_BEGIN
61 
62 class vtkTextCodec;
63 
64 class VTKIOINFOVIS_EXPORT vtkDelimitedTextReader : public vtkTableAlgorithm
65 {
66 public:
67  static vtkDelimitedTextReader* New();
69  void PrintSelf(ostream& os, vtkIndent indent) override;
70 
72 
75  vtkGetFilePathMacro(FileName);
76  vtkSetFilePathMacro(FileName);
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  }
95 
97 
101  vtkSetMacro(ReadFromInputString, vtkTypeBool);
102  vtkGetMacro(ReadFromInputString, vtkTypeBool);
103  vtkBooleanMacro(ReadFromInputString, vtkTypeBool);
105 
107 
118  vtkGetStringMacro(UnicodeCharacterSet);
119  vtkSetStringMacro(UnicodeCharacterSet);
121 
123 
128  void SetUTF8RecordDelimiters(const char* delimiters);
129  const char* GetUTF8RecordDelimiters();
131 
133 
140  vtkSetStringMacro(FieldDelimiterCharacters);
141  vtkGetStringMacro(FieldDelimiterCharacters);
143 
144  void SetUTF8FieldDelimiters(const char* delimiters);
145  const char* GetUTF8FieldDelimiters();
146 
148 
157  vtkGetMacro(StringDelimiter, char);
158  vtkSetMacro(StringDelimiter, char);
160 
161  void SetUTF8StringDelimiters(const char* delimiters);
162  const char* GetUTF8StringDelimiters();
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 
199  vtkGetMacro(MaxRecords, vtkIdType);
200  vtkSetMacro(MaxRecords, vtkIdType);
202 
204 
208  vtkGetMacro(SkippedRecords, vtkIdType);
209  vtkSetMacro(SkippedRecords, vtkIdType);
211 
213 
222  vtkSetMacro(DetectNumericColumns, bool);
223  vtkGetMacro(DetectNumericColumns, bool);
224  vtkBooleanMacro(DetectNumericColumns, bool);
226 
228 
233  vtkSetMacro(ForceDouble, bool);
234  vtkGetMacro(ForceDouble, bool);
235  vtkBooleanMacro(ForceDouble, bool);
237 
239 
254  vtkSetMacro(TrimWhitespacePriorToNumericConversion, bool);
255  vtkGetMacro(TrimWhitespacePriorToNumericConversion, bool);
256  vtkBooleanMacro(TrimWhitespacePriorToNumericConversion, bool);
258 
260 
264  vtkSetMacro(DefaultIntegerValue, int);
265  vtkGetMacro(DefaultIntegerValue, int);
267 
269 
273  vtkSetMacro(DefaultDoubleValue, double);
274  vtkGetMacro(DefaultDoubleValue, double);
276 
278 
282  vtkSetStringMacro(PedigreeIdArrayName);
283  vtkGetStringMacro(PedigreeIdArrayName);
285 
287 
291  vtkSetMacro(GeneratePedigreeIds, bool);
292  vtkGetMacro(GeneratePedigreeIds, bool);
293  vtkBooleanMacro(GeneratePedigreeIds, bool);
295 
297 
300  vtkSetMacro(OutputPedigreeIds, bool);
301  vtkGetMacro(OutputPedigreeIds, bool);
302  vtkBooleanMacro(OutputPedigreeIds, bool);
304 
306 
311  vtkSetMacro(AddTabFieldDelimiter, bool);
312  vtkGetMacro(AddTabFieldDelimiter, bool);
313  vtkBooleanMacro(AddTabFieldDelimiter, bool);
315 
321  vtkStdString GetLastError();
322 
324 
329  vtkSetMacro(ReplacementCharacter, vtkTypeUInt32);
330  vtkGetMacro(ReplacementCharacter, vtkTypeUInt32);
332 
339  vtkGetMacro(Preview, std::string);
340 
342 
346  vtkSetMacro(PreviewNumberOfLines, vtkIdType);
347  vtkGetMacro(PreviewNumberOfLines, vtkIdType);
349 
351 
357  vtkGetMacro(CommentCharacters, std::string);
358  vtkSetMacro(CommentCharacters, std::string);
360 
361 protected:
363  ~vtkDelimitedTextReader() override;
364 
367 
368  // Read the content of the input file.
369  int ReadData(vtkTable* output_table);
370 
371  char* FileName = nullptr;
372  vtkTypeBool ReadFromInputString = 0;
373  char* InputString = nullptr;
374  int InputStringLength = 0;
375  char* UnicodeCharacterSet = nullptr;
376  vtkIdType SkippedRecords = 0;
377  vtkIdType MaxRecords = 0;
378  std::string UnicodeRecordDelimiters = "\r\n";
379  std::string UnicodeFieldDelimiters = ",";
380  std::string UnicodeStringDelimiters = "\"";
381  std::string UnicodeWhitespace = " \t\r\n\v\f";
382  std::string UnicodeEscapeCharacter = "\\";
383  std::string CommentCharacters = "#";
384  bool DetectNumericColumns = false;
385  bool ForceDouble = false;
386  bool TrimWhitespacePriorToNumericConversion = false;
387  int DefaultIntegerValue = 0;
388  double DefaultDoubleValue = 0.;
389  char* FieldDelimiterCharacters = nullptr;
390  char StringDelimiter = '"';
391  bool UseStringDelimiter = true;
392  bool HaveHeaders = false;
393  bool MergeConsecutiveDelimiters = false;
394  char* PedigreeIdArrayName = nullptr;
395  bool GeneratePedigreeIds = true;
396  bool OutputPedigreeIds = false;
397  bool AddTabFieldDelimiter = false;
398  vtkStdString LastError = "";
399  vtkTypeUInt32 ReplacementCharacter = 'x';
400 
402  vtkIdType PreviewNumberOfLines = 0;
403 
404 private:
409  std::unique_ptr<std::istream> OpenStream();
410 
415  void ReadBOM(std::istream* stream);
416 
421  vtkTextCodec* CreateTextCodec(std::istream* input_stream);
422 
424  void operator=(const vtkDelimitedTextReader&) = delete;
425 };
426 
427 VTK_ABI_NAMESPACE_END
428 #endif
void SetInputString(const vtkStdString &input)
Specify the InputString for use when reading from a character array.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkTableAlgorithm * New()
Store vtkAlgorithm input/output information.
virtual int RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
Virtual class to act as an interface for all text codecs.
Definition: vtkTextCodec.h:28
int vtkIdType
Definition: vtkType.h:363
int vtkTypeBool
Definition: vtkABI.h:64
reads in delimited ascii or unicode text files and outputs a vtkTable data structure.
a simple class to control print indentation
Definition: vtkIndent.h:28
A table, which contains similar-typed columns of data.
Definition: vtkTable.h:59
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
This is called by the superclass.
Superclass for algorithms that produce only vtkTables as output.
Store zero or more vtkInformation instances.