CSVReader Class Reference
[IO]

CSVReader interface. More...

Inheritance diagram for CSVReader:

Inheritance graph
Collaboration diagram for CSVReader:

Collaboration graph

List of all members.

Public Member Functions

 CSVReader ()
 Constructs CSVReader.
void SetSeparator (const std::wstring &sep) throw (dex::gdb::Error)
 Sets the character used to separate fields in the file.
void SetQuotes (const std::wstring &quotes) throw (dex::gdb::Error)
 Sets the character used to quote fields.
void SetMultilines (dex::gdb::int32_t numExtralines)
 Allows the use of fields with more than one line.
void SetSingleLine ()
 Only allows single line fields.
void SetStartLine (dex::gdb::int32_t startLine)
 Sets the number of lines to be skiped from the beginning.
void SetNumLines (dex::gdb::int32_t numLines)
 Used to limit the number of lines that will be read.
void SetLocale (const std::wstring &localeStr)
 Sets the locale that will be used to read the file.
void Open (const std::wstring &f) throw (dex::gdb::IOException)
 Opens the source file path.
dex::gdb::bool_t Reset () throw (dex::gdb::IOException)
 Moves the reader to the beginning.
dex::gdb::bool_t Read (dex::gdb::StringList &row) throw (dex::gdb::IOException)
 Reads the next row as a string array.
dex::gdb::int32_t GetRow () throw (dex::gdb::IOException)
 The row number for the current row.
void Close () throw (dex::gdb::IOException)
 Closes the reader.
virtual ~CSVReader ()
 Destructor.


Detailed Description

CSVReader interface.

A very simple CSV reader.

It works as any other RowReader, but open must be called once before the first read operation.

Using the format RFC 4180.
Except: leading and trailing spaces, adjacent to CSV separator character, are trimmed.

You can use your own separators and quote characters. By default the separator is the comma (,) and the quote character is the double quotes (").

Fields with multiple lines can be allowed (and the maximum lines specified), but the default is a single line.

The locale string can be used to set the language, country and the file encoding. The format must be "[language_territory][.codeset]". But only the file encoding is being used in the current version.

The languages supported are: "en_US", "es_ES" and "ca_ES".
The file encodings supported are: "utf8" and "iso88591".

For example:

To don't change the default locales, use an empty string: "".
To read a file in utf8 with the default language settings use ".utf8".
To read a file in iso88591 with English language use: "en_US.iso88591".

Check out the 'Data import' section in the DEX User Manual for more details on this.

Author:
Sparsity Technologies http://www.sparsity-technologies.com

Member Function Documentation

void CSVReader::SetSeparator ( const std::wstring &  sep  )  throw (dex::gdb::Error)

Sets the character used to separate fields in the file.

Parameters:
sep [in] Separator character.

void CSVReader::SetQuotes ( const std::wstring &  quotes  )  throw (dex::gdb::Error)

Sets the character used to quote fields.

Parameters:
quotes [in] Quote character.

void CSVReader::SetMultilines ( dex::gdb::int32_t  numExtralines  ) 

Allows the use of fields with more than one line.

Parameters:
numExtralines [in] Maximum number of extra lines for each column (0==unlimited, N==N+1 total rows).

void CSVReader::SetStartLine ( dex::gdb::int32_t  startLine  ) 

Sets the number of lines to be skiped from the beginning.

Parameters:
startLine [in] The line number to skip for start reading

void CSVReader::SetNumLines ( dex::gdb::int32_t  numLines  ) 

Used to limit the number of lines that will be read.

Parameters:
numLines [in] The maximum number of lines to read (0 == unlimited)

void CSVReader::SetLocale ( const std::wstring &  localeStr  ) 

Sets the locale that will be used to read the file.

Parameters:
localeStr [in] The locale string for the file encoding.

void CSVReader::Open ( const std::wstring &  f  )  throw (dex::gdb::IOException)

Opens the source file path.

Parameters:
f [in] CSV file path.
Exceptions:
IOException If bad things happen opening the file.

dex::gdb::bool_t CSVReader::Reset (  )  throw (dex::gdb::IOException) [virtual]

Moves the reader to the beginning.

Restarts the reader.

Returns:
true if the reader can be restarted, false otherwise.
Exceptions:
IOException If bad things happen during the restart.

Implements RowReader.

dex::gdb::bool_t CSVReader::Read ( dex::gdb::StringList &  row  )  throw (dex::gdb::IOException) [virtual]

Reads the next row as a string array.

Parameters:
row [out] A string list with each comma-separated element as a separate entry.
Returns:
Returns true if a row had been read or false otherwise.
Exceptions:
IOException If bad things happen during the read.

Implements RowReader.

dex::gdb::int32_t CSVReader::GetRow (  )  throw (dex::gdb::IOException) [virtual]

The row number for the current row.

Returns:
The current row number; 0 if there is no current row.
Exceptions:
IOException If it fails.

Implements RowReader.

void CSVReader::Close (  )  throw (dex::gdb::IOException) [virtual]

Closes the reader.

Exceptions:
IOException If the close fails.

Implements RowReader.


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

Generated on Tue Jul 16 12:10:12 2013 for Dex by  doxygen 1.5.6