ITK  4.10.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 #if !defined( ITK_LEGACY_FUTURE_REMOVE )
24 # include <vcl_limits.h>
25 #endif
26 #include <limits>
27 #include "itkMacro.h"
28 #include "itkSize.h"
29 #include <fstream>
30 #include "ITKIOCSVExport.h"
31 
32 namespace itk
33 {
67 class ITKIOCSV_EXPORT CSVFileReaderBase:public LightProcessObject
68 {
69 public:
73 
75  itkTypeMacro(Self,Superclass);
76 
78  itkSetStringMacro(FileName);
79 
83  itkSetMacro(FieldDelimiterCharacter,char);
84 
86  itkGetMacro(FieldDelimiterCharacter, char);
87 
90  itkSetMacro(UseStringDelimiterCharacter,bool);
91 
93  itkGetConstMacro(UseStringDelimiterCharacter, bool);
94 
96  itkSetMacro(StringDelimiterCharacter,char);
97 
99  itkGetMacro(StringDelimiterCharacter, char);
100 
103  itkSetMacro(HasRowHeaders,bool);
104 
106  itkGetConstMacro(HasRowHeaders,bool);
107 
110  itkSetMacro(HasColumnHeaders,bool);
111 
113  itkGetConstMacro(HasColumnHeaders, bool);
114 
118  itkBooleanMacro(HasRowHeaders);
119  itkBooleanMacro(HasColumnHeaders);
120  itkBooleanMacro(UseStringDelimiterCharacter);
122 
125  void GetDataDimension(SizeValueType & rows, SizeValueType & columns);
126 
129  void GetNextField(std::string & );
130 
138  template <typename TData>
139  TData ConvertStringToValueType(const std::string str)
140  {
141  TData value;
142  std::istringstream isstream(str);
144 
145  if ((isstream >> value).fail() || !(isstream >> std::ws).eof())
146  {
147  return std::numeric_limits<TData>::quiet_NaN();
148  }
149  else
150  {
151  return value;
152  }
153  }
154 
160  virtual void Parse()=0;
161 
162 protected:
163  std::string m_FileName;
169  std::ifstream m_InputStream;
171  std::string m_Line;
172 
174  virtual ~CSVFileReaderBase() {}
176  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
177 
179  void PrepareForParsing();
180 
181 private:
182  CSVFileReaderBase(const Self &) ITK_DELETE_FUNCTION;
183  void operator=(const Self &) ITK_DELETE_FUNCTION;
184 };
185 
186 } //end namespace itk
187 
188 #endif
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes...
Definition: itkArray.h:30
unsigned long SizeValueType
Definition: itkIntTypes.h:143
LightProcessObject Superclass
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)