VTK  9.4.20250402
vtkDelimitedTextCodecIteratorPrivate.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
15#ifndef vtkDelimitedTextCodecIterator_h
16#define vtkDelimitedTextCodecIterator_h
17
18#include "vtkTextCodec.h"
19
20#include <set> //for set
21
22VTK_ABI_NAMESPACE_BEGIN
23
25class vtkDoubleArray;
26class vtkIntArray;
27class vtkStringArray;
28class vtkTable;
29
31{
32public:
34 const std::string& recordDelimiters, const std::string& fieldDelimiters,
35 const std::string& stringDelimiters, const std::string& whitespace, const std::string& comments,
36 const std::string& escape, bool haveHeaders, bool mergConsDelimiters, bool useStringDelimiter,
37 bool detectNumericColumns, bool forceDouble, int defaultInt, double defaultDouble,
38 vtkTable* outputTable);
39
41
46
50 vtkDelimitedTextCodecIteratorPrivate& operator=(const vtkTypeUInt32& value) override;
51
52private:
55
56 template <typename T>
57 static vtkSmartPointer<vtkStringArray> ToStringArray(T* array);
58
63 static vtkSmartPointer<vtkDoubleArray> ToDoubleArray(vtkIntArray* array);
64
71 vtkIntArray* array, vtkIdType index, const std::string& str);
72
79 vtkDoubleArray* array, vtkIdType index, const std::string& str);
80
86 vtkStringArray* array, vtkIdType index, const std::string& str);
87
95 vtkAbstractArray* array, vtkIdType index, const std::string& str);
96
101 void CreateColumn();
102
108 void InsertField();
109
114 struct RecordsCounter
115 {
116 RecordsCounter(bool has, vtkIdType max, vtkIdType start)
117 : HasMax(has)
118 , Max(max)
119 , Start(start)
120 {
121 }
122
123 bool HasMax = false;
124 vtkIdType Max = 0;
125 vtkIdType Start = 0;
126 vtkIdType Skipped = 0;
127 vtkIdType Current = 0;
128
129 // Return true if max records was reached
130 bool MaxReached();
131
132 // Return true if current records is acceptable, based on its index
133 bool AcceptingField();
134
135 // Return true if this is the first acceptable records
136 bool FirstAccepted();
137
138 // Increment current index
139 void Next();
140
141 // Mark current record as skipped.
142 void Skip();
143
144 // Return the current number of read record.
145 vtkIdType GetNumberOfAcceptedRecords();
146 };
147
148 RecordsCounter RecordsCount;
149
150 std::set<vtkTypeUInt32> RecordDelimiters;
151 std::set<vtkTypeUInt32> FieldDelimiters;
152 std::set<vtkTypeUInt32> StringDelimiters;
153 std::set<vtkTypeUInt32> Whitespace;
154 std::set<vtkTypeUInt32> CommentChar = { '#' };
155 std::set<vtkTypeUInt32> EscapeDelimiter;
156
157 bool HaveHeaders = false;
158 bool WhiteSpaceOnlyString = true;
159 vtkTable* OutputTable = nullptr;
160 vtkIdType CurrentFieldIndex = 0;
161 std::string CurrentField;
162 bool RecordAdjacent = true;
163 bool MergeConsDelims = false;
164 bool ProcessEscapeSequence = false;
165 bool UseStringDelimiter = true;
166 bool DetectNumericColumns = false;
167 bool ForceDouble = false;
168 int DefaultIntegerValue = 0;
169 double DefaultDoubleValue = 0.;
170 vtkTypeUInt32 WithinString = 0;
171 bool WithinComment = false;
172};
173
174VTK_ABI_NAMESPACE_END
175#endif
176/* VTK-HeaderTest-Exclude: INCLUDES:CLASSES */
Abstract superclass for all arrays.
Implements vtkTextCodec::OutputIterator to fill a vtkTable from text input.
vtkDelimitedTextCodecIteratorPrivate(vtkIdType startRecords, vtkIdType maxRecords, const std::string &recordDelimiters, const std::string &fieldDelimiters, const std::string &stringDelimiters, const std::string &whitespace, const std::string &comments, const std::string &escape, bool haveHeaders, bool mergConsDelimiters, bool useStringDelimiter, bool detectNumericColumns, bool forceDouble, int defaultInt, double defaultDouble, vtkTable *outputTable)
void ReachedEndOfInput()
Handle windows files that do not have a carriage return line feed on the last line of the file.
vtkDelimitedTextCodecIteratorPrivate & operator=(const vtkTypeUInt32 &value) override
Entry point to parse text.
dynamic, self-adjusting array of double
dynamic, self-adjusting array of int
Hold a reference to a vtkObjectBase instance.
a vtkAbstractArray subclass for strings
A table, which contains similar-typed columns of data.
Definition vtkTable.h:169
a base class that any output iterators need to derive from to use the first signature of to_unicode.
int vtkIdType
Definition vtkType.h:332
#define max(a, b)