ITK  5.4.0
Insight Toolkit
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
itk::CSVFileReaderBase Class Referenceabstract

#include <itkCSVFileReaderBase.h>

Detailed Description

A base class that contains common methods used for parsing csv files.

CSVFileReaderBase is a base abstract class for reading csv files. It contains the methods GetDataDimension() which is used to count the number of rows and columns in the file data set. Only after this method is called should calls to the GetNextField() method be made. The method ConvertStringToValueType() can be used to convert a string obtained from GetNextField() to some desired numeric type. The Parse() method is what is used to do the full processing, that is, reading the file and parsing the data into some object. It is pure virtual as a different parsing method would be needed for parsing into different types of objects.

The user would need to specify if there are row and column headers in the file using the HasRowHeaders and HasColumnHeaders flags. Also, if row and/or column headers are enclosed in "" or any other string delimiter character being used, the user can set the option of turning the string delimiter character on with the UseStringDelimiterCharacter flag. This is also especially useful if headers such as "This,Header" contain commas or other field delimiter characters within them.

If the csv file has row and column headers, they do not necessarily need to be enclosed in "" or other string delimiter characters as long as you specify that row and/or column headers exist in the file. Turning on the HasRowHeaders or HasColumnHeaders flags will tell the reader to recognize them as headers.

The PrepareForParsing() method does not need to be called explicitly as it is called in the GetDataDimension() method.

Definition at line 65 of file itkCSVFileReaderBase.h.

+ Inheritance diagram for itk::CSVFileReaderBase:
+ Collaboration diagram for itk::CSVFileReaderBase:

Public Types

using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = CSVFileReaderBase
 
using Superclass = LightProcessObject
 
- Public Types inherited from itk::LightProcessObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightProcessObject
 
using Superclass = Object
 
- Public Types inherited from itk::Object
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = Object
 
using Superclass = LightObject
 
- Public Types inherited from itk::LightObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightObject
 

Public Member Functions

void GetDataDimension (SizeValueType &rows, SizeValueType &cols)
 
virtual char GetFieldDelimiterCharacter ()
 
virtual bool GetHasColumnHeaders () const
 
virtual bool GetHasRowHeaders () const
 
const char * GetNameOfClass () const override
 
void GetNextField (std::string &)
 
virtual char GetStringDelimiterCharacter ()
 
virtual bool GetUseStringDelimiterCharacter () const
 
virtual void Parse ()=0
 
virtual void SetFieldDelimiterCharacter (char _arg)
 
virtual void SetFileName (const char *_arg)
 
virtual void SetHasColumnHeaders (bool _arg)
 
virtual void SetHasRowHeaders (bool _arg)
 
virtual void SetStringDelimiterCharacter (char _arg)
 
virtual void SetUseStringDelimiterCharacter (bool _arg)
 
virtual void HasRowHeadersOn ()
 
virtual void HasColumnHeadersOn ()
 
virtual void UseStringDelimiterCharacterOn ()
 
template<typename TData >
TData ConvertStringToValueType (const std::string str)
 
- Public Member Functions inherited from itk::LightProcessObject
virtual void AbortGenerateDataOn ()
 
virtual const bool & GetAbortGenerateData () const
 
virtual void SetAbortGenerateData (bool _arg)
 
virtual void UpdateOutputData ()
 
void UpdateProgress (float amount)
 
virtual void SetProgress (float _arg)
 
virtual const float & GetProgress () const
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *)
 
unsigned long AddObserver (const EventObject &event, Command *) const
 
unsigned long AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const
 
LightObject::Pointer CreateAnother () const override
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
virtual ModifiedTimeType GetMTime () const
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag)
 
void SetDebug (bool debugFlag) const
 
void SetReferenceCount (int) override
 
void UnRegister () const noexcept override
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
void SetMetaDataDictionary (MetaDataDictionary &&rrhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
Pointer Clone () const
 
virtual void Delete ()
 
virtual int GetReferenceCount () const
 
void Print (std::ostream &os, Indent indent=0) const
 

Protected Member Functions

 CSVFileReaderBase ()
 
void PrepareForParsing ()
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
 ~CSVFileReaderBase () override=default
 
- Protected Member Functions inherited from itk::LightProcessObject
virtual void GenerateData ()
 
 LightProcessObject ()
 
 ~LightProcessObject () override
 
- Protected Member Functions inherited from itk::Object
 Object ()
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
virtual void SetTimeStamp (const TimeStamp &timeStamp)
 
 ~Object () override
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 

Protected Attributes

int m_EndOfColumnHeadersLine {}
 
char m_FieldDelimiterCharacter {}
 
std::string m_FileName {}
 
bool m_HasColumnHeaders {}
 
bool m_HasRowHeaders {}
 
std::ifstream m_InputStream {}
 
std::string m_Line {}
 
char m_StringDelimiterCharacter {}
 
bool m_UseStringDelimiterCharacter {}
 
- Protected Attributes inherited from itk::LightObject
std::atomic< int > m_ReferenceCount {}
 

Additional Inherited Members

- Static Public Member Functions inherited from itk::LightProcessObject
static Pointer New ()
 
- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool val)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 

Member Typedef Documentation

◆ ConstPointer

Definition at line 74 of file itkCSVFileReaderBase.h.

◆ Pointer

Definition at line 73 of file itkCSVFileReaderBase.h.

◆ Self

Standard class type aliases

Definition at line 71 of file itkCSVFileReaderBase.h.

◆ Superclass

Definition at line 72 of file itkCSVFileReaderBase.h.

Constructor & Destructor Documentation

◆ CSVFileReaderBase()

itk::CSVFileReaderBase::CSVFileReaderBase ( )
protected

◆ ~CSVFileReaderBase()

itk::CSVFileReaderBase::~CSVFileReaderBase ( )
overrideprotecteddefault

Member Function Documentation

◆ ConvertStringToValueType()

template<typename TData >
TData itk::CSVFileReaderBase::ConvertStringToValueType ( const std::string  str)
inline

Converting a string to other numeric value types. This is a template method in a non-templated class so it needs to be defined within the .h. The only way it would be possible to have the definition in the .cxx source file would be either to include the .cxx file or to use the export keyword, which will be removed from the c++ language.

Definition at line 144 of file itkCSVFileReaderBase.h.

◆ GetDataDimension()

void itk::CSVFileReaderBase::GetDataDimension ( SizeValueType rows,
SizeValueType cols 
)

Counts the number of rows and columns in a file and prepares the file for iterative reading using the GetNextField() method.

◆ GetFieldDelimiterCharacter()

virtual char itk::CSVFileReaderBase::GetFieldDelimiterCharacter ( )
virtual

Get the field delimiter character.

◆ GetHasColumnHeaders()

virtual bool itk::CSVFileReaderBase::GetHasColumnHeaders ( ) const
virtual

Get the value of the HasColumnHeaders flag.

◆ GetHasRowHeaders()

virtual bool itk::CSVFileReaderBase::GetHasRowHeaders ( ) const
virtual

Get the value of the HasRowHeaders flag.

◆ GetNameOfClass()

const char* itk::CSVFileReaderBase::GetNameOfClass ( ) const
overridevirtual

◆ GetNextField()

void itk::CSVFileReaderBase::GetNextField ( std::string &  )

Gets the next entry in the file. Returns a string. This function must always only be called after GetDataDimension().

◆ GetStringDelimiterCharacter()

virtual char itk::CSVFileReaderBase::GetStringDelimiterCharacter ( )
virtual

Get the string delimiter character.

◆ GetUseStringDelimiterCharacter()

virtual bool itk::CSVFileReaderBase::GetUseStringDelimiterCharacter ( ) const
virtual

Get the value of the UseStringDelimiterCharacter flag.

◆ HasColumnHeadersOn()

virtual void itk::CSVFileReaderBase::HasColumnHeadersOn ( )
virtual

Boolean macros for setting HasRowHeaders, HasColumnHeaders and UseStringDelimiterCharacter. They can conveniently be set by appending On() or Off() to each of the variable names.

◆ HasRowHeadersOn()

virtual void itk::CSVFileReaderBase::HasRowHeadersOn ( )
virtual

Boolean macros for setting HasRowHeaders, HasColumnHeaders and UseStringDelimiterCharacter. They can conveniently be set by appending On() or Off() to each of the variable names.

◆ Parse()

virtual void itk::CSVFileReaderBase::Parse ( )
pure virtual

This method must be defined in derived classes to parse the entire file into some object. The GetNextField() method only gets one string at a time. This method would store those strings or convert them using ConvertStringToValueType() and store the numeric values into the object.

Implemented in itk::CSVArray2DFileReader< TData >.

◆ PrepareForParsing()

void itk::CSVFileReaderBase::PrepareForParsing ( )
protected

Check that all essential components are present and plugged in.

◆ PrintSelf()

void itk::CSVFileReaderBase::PrintSelf ( std::ostream &  os,
Indent  indent 
) const
overrideprotectedvirtual

Print method

Reimplemented from itk::LightProcessObject.

◆ SetFieldDelimiterCharacter()

virtual void itk::CSVFileReaderBase::SetFieldDelimiterCharacter ( char  _arg)
virtual

Set the field delimiter character. It is possible to set another character as a field delimiter character such as ';'. The default delimiter character is ','

◆ SetFileName()

virtual void itk::CSVFileReaderBase::SetFileName ( const char *  _arg)
virtual

Set the name of the file to be read

◆ SetHasColumnHeaders()

virtual void itk::CSVFileReaderBase::SetHasColumnHeaders ( bool  _arg)
virtual

Set the HasColumnHeaders flag to indicate existence of column headers in the file.

◆ SetHasRowHeaders()

virtual void itk::CSVFileReaderBase::SetHasRowHeaders ( bool  _arg)
virtual

Set the HasRowHeaders flag to indicate existence of row headers in the file.

◆ SetStringDelimiterCharacter()

virtual void itk::CSVFileReaderBase::SetStringDelimiterCharacter ( char  _arg)
virtual

Set the string delimiter character if it is in use.

◆ SetUseStringDelimiterCharacter()

virtual void itk::CSVFileReaderBase::SetUseStringDelimiterCharacter ( bool  _arg)
virtual

Set the UseStringDelimiterCharacter flag on if column or row headers in the file are enclosed in "" or other characters.

◆ UseStringDelimiterCharacterOn()

virtual void itk::CSVFileReaderBase::UseStringDelimiterCharacterOn ( )
virtual

Boolean macros for setting HasRowHeaders, HasColumnHeaders and UseStringDelimiterCharacter. They can conveniently be set by appending On() or Off() to each of the variable names.

Member Data Documentation

◆ m_EndOfColumnHeadersLine

int itk::CSVFileReaderBase::m_EndOfColumnHeadersLine {}
protected

Definition at line 176 of file itkCSVFileReaderBase.h.

◆ m_FieldDelimiterCharacter

char itk::CSVFileReaderBase::m_FieldDelimiterCharacter {}
protected

Definition at line 170 of file itkCSVFileReaderBase.h.

◆ m_FileName

std::string itk::CSVFileReaderBase::m_FileName {}
protected

Definition at line 169 of file itkCSVFileReaderBase.h.

◆ m_HasColumnHeaders

bool itk::CSVFileReaderBase::m_HasColumnHeaders {}
protected

Definition at line 174 of file itkCSVFileReaderBase.h.

◆ m_HasRowHeaders

bool itk::CSVFileReaderBase::m_HasRowHeaders {}
protected

Definition at line 173 of file itkCSVFileReaderBase.h.

◆ m_InputStream

std::ifstream itk::CSVFileReaderBase::m_InputStream {}
protected

Definition at line 175 of file itkCSVFileReaderBase.h.

◆ m_Line

std::string itk::CSVFileReaderBase::m_Line {}
protected

Definition at line 177 of file itkCSVFileReaderBase.h.

◆ m_StringDelimiterCharacter

char itk::CSVFileReaderBase::m_StringDelimiterCharacter {}
protected

Definition at line 171 of file itkCSVFileReaderBase.h.

◆ m_UseStringDelimiterCharacter

bool itk::CSVFileReaderBase::m_UseStringDelimiterCharacter {}
protected

Definition at line 172 of file itkCSVFileReaderBase.h.


The documentation for this class was generated from the following file: