ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkCSVFileReaderBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 {
64 class ITKIOCSV_EXPORT CSVFileReaderBase:public LightProcessObject
65 {
66 public:
67  ITK_DISALLOW_COPY_AND_ASSIGN(CSVFileReaderBase);
68 
74 
77 
79  itkSetStringMacro(FileName);
80 
84  itkSetMacro(FieldDelimiterCharacter,char);
85 
87  itkGetMacro(FieldDelimiterCharacter, char);
88 
91  itkSetMacro(UseStringDelimiterCharacter,bool);
92 
94  itkGetConstMacro(UseStringDelimiterCharacter, bool);
95 
97  itkSetMacro(StringDelimiterCharacter,char);
98 
100  itkGetMacro(StringDelimiterCharacter, char);
101 
104  itkSetMacro(HasRowHeaders,bool);
105 
107  itkGetConstMacro(HasRowHeaders,bool);
108 
111  itkSetMacro(HasColumnHeaders,bool);
112 
114  itkGetConstMacro(HasColumnHeaders, bool);
115 
119  itkBooleanMacro(HasRowHeaders);
120  itkBooleanMacro(HasColumnHeaders);
121  itkBooleanMacro(UseStringDelimiterCharacter);
123 
126  void GetDataDimension(SizeValueType & rows, SizeValueType & columns);
127 
130  void GetNextField(std::string & );
131 
139  template <typename TData>
140  TData ConvertStringToValueType(const std::string str)
141  {
142  TData value;
143  std::istringstream isstream(str);
145 
146  if ((isstream >> value).fail() || !(isstream >> std::ws).eof())
147  {
148  return std::numeric_limits<TData>::quiet_NaN();
149  }
150  else
151  {
152  return value;
153  }
154  }
155 
161  virtual void Parse()=0;
162 
163 protected:
164  std::string m_FileName;
170  std::ifstream m_InputStream;
172  std::string m_Line;
173 
175  ~CSVFileReaderBase() override = default;
177  void PrintSelf(std::ostream & os, Indent indent) const override;
178 
180  void PrepareForParsing();
181 };
182 
183 } //end namespace itk
184 
185 #endif
Light weight base class for most itk classes.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
LightProcessObject is the base class for all process objects (source, filters, mappers) in the Insigh...
Control indentation during Print() invocation.
Definition: itkIndent.h:49
A base class that contains common methods used for parsing csv files.
TData ConvertStringToValueType(const std::string str)
Base class for most ITK classes.
Definition: itkObject.h:60