ITK  4.6.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 
28 namespace itk
29 {
64 {
65 public:
69 
71  itkTypeMacro(Self,Superclass);
72 
74  itkSetStringMacro(FileName);
75 
79  itkSetMacro(FieldDelimiterCharacter,char);
80 
82  itkGetMacro(FieldDelimiterCharacter, char);
83 
86  itkSetMacro(UseStringDelimiterCharacter,bool);
87 
89  itkGetConstMacro(UseStringDelimiterCharacter, bool);
90 
92  itkSetMacro(StringDelimiterCharacter,char);
93 
95  itkGetMacro(StringDelimiterCharacter, char);
96 
99  itkSetMacro(HasRowHeaders,bool);
100 
102  itkGetConstMacro(HasRowHeaders,bool);
103 
106  itkSetMacro(HasColumnHeaders,bool);
107 
109  itkGetConstMacro(HasColumnHeaders, bool);
110 
114  itkBooleanMacro(HasRowHeaders);
115  itkBooleanMacro(HasColumnHeaders);
116  itkBooleanMacro(UseStringDelimiterCharacter);
118 
121  void GetDataDimension(SizeValueType & rows, SizeValueType & columns);
122 
125  void GetNextField(std::string & );
126 
134  template <typename TData>
135  TData ConvertStringToValueType(const std::string str)
136  {
137  TData value;
138  std::istringstream isstream(str);
140 
141  if ((isstream >> value).fail() || !(isstream >> std::ws).eof())
142  {
143  return std::numeric_limits<TData>::quiet_NaN();
144  }
145  else
146  {
147  return value;
148  }
149  }
150 
156  virtual void Parse()=0;
157 
158 protected:
159  std::string m_FileName;
165  std::ifstream m_InputStream;
167  std::string m_Line;
168 
170  virtual ~CSVFileReaderBase() {}
172  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
173 
175  void PrepareForParsing();
176 
177 private:
178  CSVFileReaderBase(const Self &); //purposely not implemented
179  void operator=(const Self &); //purposely not implemented
180 };
181 
182 } //end namespace itk
183 
184 #endif
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
Light weight base class for most itk classes.
void operator=(const Self &)
unsigned long SizeValueType
Definition: itkIntTypes.h:143
void GetDataDimension(SizeValueType &rows, SizeValueType &columns)
void GetNextField(std::string &)
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
virtual void Parse()=0