ITK  5.2.0
Insight Toolkit
itkCSVFileReaderBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef itkCSVFileReaderBase_h
20 #define itkCSVFileReaderBase_h
21 
22 #include "itkLightProcessObject.h"
23 #include <limits>
24 #include "itkMacro.h"
25 #include "itkSize.h"
26 #include <fstream>
27 #include "ITKIOCSVExport.h"
28 
29 namespace itk
30 {
65 class ITKIOCSV_EXPORT CSVFileReaderBase : public LightProcessObject
66 {
67 public:
68  ITK_DISALLOW_COPY_AND_MOVE(CSVFileReaderBase);
69 
75 
78 
80  itkSetStringMacro(FileName);
81 
85  itkSetMacro(FieldDelimiterCharacter, char);
86 
88  itkGetMacro(FieldDelimiterCharacter, char);
89 
92  itkSetMacro(UseStringDelimiterCharacter, bool);
93 
95  itkGetConstMacro(UseStringDelimiterCharacter, bool);
96 
98  itkSetMacro(StringDelimiterCharacter, char);
99 
101  itkGetMacro(StringDelimiterCharacter, char);
102 
105  itkSetMacro(HasRowHeaders, bool);
106 
108  itkGetConstMacro(HasRowHeaders, bool);
109 
112  itkSetMacro(HasColumnHeaders, bool);
113 
115  itkGetConstMacro(HasColumnHeaders, bool);
116 
120  itkBooleanMacro(HasRowHeaders);
121  itkBooleanMacro(HasColumnHeaders);
122  itkBooleanMacro(UseStringDelimiterCharacter);
124 
127  void
128  GetDataDimension(SizeValueType & rows, SizeValueType & cols);
129 
132  void
133  GetNextField(std::string &);
134 
142  template <typename TData>
143  TData
144  ConvertStringToValueType(const std::string str)
145  {
146  TData value;
147  std::istringstream isstream(str);
149 
150  if ((isstream >> value).fail() || !(isstream >> std::ws).eof())
151  {
152  return std::numeric_limits<TData>::quiet_NaN();
153  }
154  else
155  {
156  return value;
157  }
158  }
159 
165  virtual void
166  Parse() = 0;
167 
168 protected:
169  std::string m_FileName;
175  std::ifstream m_InputStream;
177  std::string m_Line;
178 
180  ~CSVFileReaderBase() override = default;
182  void
183  PrintSelf(std::ostream & os, Indent indent) const override;
184 
186  void
187  PrepareForParsing();
188 };
189 
190 } // end namespace itk
191 
192 #endif
itk::LightProcessObject
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Definition: itkLightProcessObject.h:72
itk::CSVFileReaderBase::m_Line
std::string m_Line
Definition: itkCSVFileReaderBase.h:177
itk::CSVFileReaderBase::m_HasRowHeaders
bool m_HasRowHeaders
Definition: itkCSVFileReaderBase.h:173
itk::CSVFileReaderBase::m_StringDelimiterCharacter
char m_StringDelimiterCharacter
Definition: itkCSVFileReaderBase.h:171
itkLightProcessObject.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::CSVFileReaderBase
A base class that contains common methods used for parsing csv files.
Definition: itkCSVFileReaderBase.h:65
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::CSVFileReaderBase::m_FileName
std::string m_FileName
Definition: itkCSVFileReaderBase.h:169
itkMacro.h
itk::CSVFileReaderBase::m_InputStream
std::ifstream m_InputStream
Definition: itkCSVFileReaderBase.h:175
itk::CSVFileReaderBase::m_HasColumnHeaders
bool m_HasColumnHeaders
Definition: itkCSVFileReaderBase.h:174
itk::CSVFileReaderBase::m_FieldDelimiterCharacter
char m_FieldDelimiterCharacter
Definition: itkCSVFileReaderBase.h:170
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::CSVFileReaderBase::m_UseStringDelimiterCharacter
bool m_UseStringDelimiterCharacter
Definition: itkCSVFileReaderBase.h:172
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::CSVFileReaderBase::ConvertStringToValueType
TData ConvertStringToValueType(const std::string str)
Definition: itkCSVFileReaderBase.h:144
itk::CSVFileReaderBase::m_EndOfColumnHeadersLine
int m_EndOfColumnHeadersLine
Definition: itkCSVFileReaderBase.h:176
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itkSize.h