MCPcopy Create free account
hub / github.com/Kitware/VTK / RequestData

Method RequestData

IO/Infovis/vtkFixedWidthTextReader.cxx:75–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73//------------------------------------------------------------------------------
74
75int vtkFixedWidthTextReader::RequestData(
76 vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
77{
78 int numLines = 0;
79
80 // Check that the filename has been specified
81 if (!this->FileName)
82 {
83 vtkErrorMacro("vtkFixedWidthTextReader: You must specify a filename!");
84 return 2;
85 }
86
87 vtksys::ifstream infile(this->FileName, ios::in);
88 if (!infile || infile.fail())
89 {
90 vtkErrorMacro(<< "vtkFixedWidthTextReader: Couldn't open file!");
91 return 2;
92 }
93
94 // The first line of the file might contain the headers, so we want
95 // to be a little bit careful about it. If we don't have headers
96 // we'll have to make something up.
97 std::vector<std::string> headers;
98 std::vector<std::string> firstLineFields;
99 std::string firstLine;
100
101 my_getline(infile, firstLine);
102
103 // vtkDebugMacro(<<"First line of file: " << firstLine);
104
105 if (this->HaveHeaders)
106 {
107 splitString(firstLine, this->FieldWidth, this->StripWhiteSpace, headers);
108 }
109 else
110 {
111 splitString(firstLine, this->FieldWidth, this->StripWhiteSpace, firstLineFields);
112
113 for (unsigned int i = 0; i < firstLineFields.size(); ++i)
114 {
115 char fieldName[64];
116 auto result = vtk::format_to_n(fieldName, sizeof(fieldName), "Field {:d}", i);
117 *result.out = '\0';
118 headers.emplace_back(fieldName);
119 }
120 }
121
122 vtkTable* table = vtkTable::GetData(outputVector);
123 if (this->TableErrorObserver)
124 {
125 table->AddObserver(vtkCommand::ErrorEvent, this->TableErrorObserver);
126 }
127
128 // Now we can create the arrays that will hold the data for each
129 // field.
130 std::vector<std::string>::const_iterator fieldIter;
131 for (fieldIter = headers.begin(); fieldIter != headers.end(); ++fieldIter)
132 {

Callers

nothing calls this directly

Calls 15

InsertNextRowMethod · 0.80
InvokeEventMethod · 0.80
my_getlineFunction · 0.70
splitStringFunction · 0.70
vtkVariantClass · 0.70
DeleteMethod · 0.65
format_to_nFunction · 0.50
GetDataFunction · 0.50
NewFunction · 0.50
sizeMethod · 0.45
emplace_backMethod · 0.45
AddObserverMethod · 0.45

Tested by

no test coverage detected