ITK  4.8.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 <vcl_limits.h>
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:
70 
72  itkTypeMacro(Self,Superclass);
73 
75  itkSetStringMacro(FileName);
76 
80  itkSetMacro(FieldDelimiterCharacter,char);
81 
83  itkGetMacro(FieldDelimiterCharacter, char);
84 
87  itkSetMacro(UseStringDelimiterCharacter,bool);
88 
90  itkGetConstMacro(UseStringDelimiterCharacter, bool);
91 
93  itkSetMacro(StringDelimiterCharacter,char);
94 
96  itkGetMacro(StringDelimiterCharacter, char);
97 
100  itkSetMacro(HasRowHeaders,bool);
101 
103  itkGetConstMacro(HasRowHeaders,bool);
104 
107  itkSetMacro(HasColumnHeaders,bool);
108 
110  itkGetConstMacro(HasColumnHeaders, bool);
111 
115  itkBooleanMacro(HasRowHeaders);
116  itkBooleanMacro(HasColumnHeaders);
117  itkBooleanMacro(UseStringDelimiterCharacter);
119 
122  void GetDataDimension(SizeValueType & rows, SizeValueType & columns);
123 
126  void GetNextField(std::string & );
127 
135  template <typename TData>
136  TData ConvertStringToValueType(const std::string str)
137  {
138  TData value;
139  std::istringstream isstream(str);
141 
142  if ((isstream >> value).fail() || !(isstream >> std::ws).eof())
143  {
144  return std::numeric_limits<TData>::quiet_NaN();
145  }
146  else
147  {
148  return value;
149  }
150  }
151 
157  virtual void Parse()=0;
158 
159 protected:
160  std::string m_FileName;
166  std::ifstream m_InputStream;
168  std::string m_Line;
169 
171  virtual ~CSVFileReaderBase() {}
173  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
174 
176  void PrepareForParsing();
177 
178 private:
179  CSVFileReaderBase(const Self &); //purposely not implemented
180  void operator=(const Self &); //purposely not implemented
181 };
182 
183 } //end namespace itk
184 
185 #endif
Light weight base class for most itk classes.
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)
Base class for most ITK classes.
Definition: itkObject.h:57