| OpenMS 2.5.0

Public Member Functions | Private Attributes | List of all members
CsvFile Class Reference
Format » File IO

This class handles csv files. Currently only loading is implemented. More...

`#include <OpenMS/FORMAT/CsvFile.h>`

Inheritance diagram for CsvFile:

## Public Member Functions

| CsvFile ()
| Default constructor. More...
| ~CsvFile () override
| destructor More...
| CsvFile (const String &filename, char is=',', bool ie=false, Int first_n=-1)
| Constructor with filename. More...
void | load (const String &filename, char is=',', bool ie=false, Int first_n=-1)
| Loads data from a text file. More...
void | store (const String &filename)
| Stores the buffer's content into a file. More...
void | addRow (const StringList &list)
| Add a row to the buffer. More...
void | clear ()
| Clears the buffer. More...
bool | getRow (Size row, StringList &list)
| writes all items from a row to list More...
std::vector< String >::size_type | rowCount () const
| Returns the number of rows that were loaded from the file. More...

## Private Attributes

char | itemseperator_
bool | itemenclosed_
Private Attributes inherited from TextFile
std::vector< String > | buffer_
| Internal buffer storing the lines before writing them to the file. More...

## Additional Inherited Members

Private Types inherited from TextFile
typedef std::vector< String >::iterator | Iterator
| Mutable iterator. More...
typedef std::vector< String >::const_iterator | ConstIterator
| Non-mutable iterator. More...
typedef std::vector< String >::reverse_iterator | ReverseIterator
| Mutable reverse iterator. More...
typedef std::vector< String >::const_reverse_iterator | ConstReverseIterator
| Non-mutable reverse iterator. More...
Private Member Functions inherited from TextFile
| TextFile ()
| Default constructor. More...
virtual | ~TextFile ()
| destructor More...
| TextFile (const String &filename, bool trim_lines=false, Int first_n=-1, bool skip_empty_lines=false)
| Constructor with filename. More...
void | load (const String &filename, bool trim_lines=false, Int first_n=-1, bool skip_empty_lines=false)
| Loads data from a text file. More...
void | store (const String &filename)
| Writes the data to a file. More...
template<typename StringType >
TextFile & | operator<< (const StringType &string)
| Operator for appending entries with less code. More...
template<typename StringType >
void | addLine (const StringType &line)
ConstIterator | begin () const
| Gives access to the underlying text buffer. More...
Iterator | begin ()
ConstIterator | end () const
| Gives access to the underlying text buffer. More...
Iterator | end ()
Static Private Member Functions inherited from TextFile
static std::istream & | getLine (std::istream &is, std::string &t)
| Platform-agnostic getline() which can deal with all line endings (, , ) More...

## Detailed Description

This class handles csv files. Currently only loading is implemented.

Note
  items are allowed to be enclosed by only one character e.g. "item" where " is enclosing character

## Constructor & Destructor Documentation

## ◆ CsvFile() [1/2]

CsvFile | ( |  | ) |

Default constructor.

## ◆ ~CsvFile()

~CsvFile | ( |  | ) |

override

destructor

## ◆ CsvFile() [2/2]

CsvFile | ( | const String & | filename,
|  | char | is = `','`,
|  | bool | ie = `false`,
|  | Int | first_n = `-1`
| ) |  |

Constructor with filename.

Parameters

  filename | The input file name.
  is | character which separates the items.
  ie | Whether or not every item is enclosed.
  first_n | Only the given number of lines are read, starting from the beginning of the file.

Exceptions

  Exception::FileNotFound | is thrown if the file could not be opened.

## Member Function Documentation

## ◆ addRow()

void addRow | ( | const StringList & | list | ) |

Add a row to the buffer.

Parameters

  list | StringList which will contain all items of the row to add

## ◆ clear()

void clear | ( |  | ) |

Clears the buffer.

Clears TextFile::buffer_

## ◆ getRow()

bool getRow | ( | Size | row,
|  | StringList & | list
| ) |  |

writes all items from a row to list

Parameters

  row | the row which will be read
  list | StringList which will contain all items of the row

Exceptions

  Exception::InvalidIterator | is thrown if the row is not existing

Returns
  returns false if the given row could not be separated into items

## ◆ load()

void load | ( | const String & | filename,
|  | char | is = `','`,
|  | bool | ie = `false`,
|  | Int | first_n = `-1`
| ) |  |

Loads data from a text file.

Parameters

  filename | The input file name.
  is | character which separates the items.
  ie | Whether or not every item is enclosed.
  first_n | Only the given number of lines are read, starting from the beginning of the file.

Exceptions

  Exception::FileNotFound | is thrown if the file could not be opened.

## ◆ rowCount()

std::vector<String>::size_type rowCount | ( |  | ) | const

Returns the number of rows that were loaded from the file.

Returns
  The number of loaded rows.

## ◆ store()

void store | ( | const String & | filename | ) |

Stores the buffer's content into a file.

Parameters

  filename | The output filename.

## Member Data Documentation

## ◆ itemenclosed_

bool itemenclosed_

private

## ◆ itemseperator_

char itemseperator_

private