This class handles csv files. Currently only loading is implemented.
More...
#include <OpenMS/FORMAT/CsvFile.h>
|
| | CsvFile () |
| | Default constructor.
|
| |
| | ~CsvFile () override |
| | destructor
|
| |
| | CsvFile (const std::string &filename, char is=',', bool ie=false, Int first_n=-1) |
| | Constructor with filename.
|
| |
| void | load (const std::string &filename, char is=',', bool ie=false, Int first_n=-1) |
| | Loads data from a text file.
|
| |
| void | store (const std::string &filename) |
| | Stores the buffer's content into a file.
|
| |
| void | addRow (const StringList &list) |
| | Add a row to the buffer.
|
| |
| void | clear () |
| | Clears the buffer.
|
| |
| bool | getRow (Size row, StringList &list) const |
| | writes all items from a row to list
|
| |
| std::vector< std::string >::size_type | rowCount () const |
| | Returns the number of rows that were loaded from the file.
|
| |
|
| typedef std::vector< std::string >::iterator | Iterator |
| | Mutable iterator.
|
| |
| typedef std::vector< std::string >::const_iterator | ConstIterator |
| | Non-mutable iterator.
|
| |
| typedef std::vector< std::string >::reverse_iterator | ReverseIterator |
| | Mutable reverse iterator.
|
| |
| typedef std::vector< std::string >::const_reverse_iterator | ConstReverseIterator |
| | Non-mutable reverse iterator.
|
| |
| | TextFile () |
| | Default constructor.
|
| |
| virtual | ~TextFile () |
| | destructor
|
| |
| | TextFile (const std::string &filename, bool trim_lines=false, Int first_n=-1, bool skip_empty_lines=false, const std::string &comment_symbol="") |
| | Constructor with filename.
|
| |
| void | load (const std::string &filename, bool trim_lines=false, Int first_n=-1, bool skip_empty_lines=false, const std::string &comment_symbol="") |
| | Loads data from a text file into the internal buffer.
|
| |
| void | store (const std::string &filename) |
| | Writes the data to a file.
|
| |
| template<typename StringType > |
| TextFile & | operator<< (const StringType &string) |
| | Operator for appending entries with less code.
|
| |
| template<typename StringType > |
| void | addLine (const StringType &line) |
| |
| ConstIterator | begin () const |
| | Gives access to the underlying text buffer.
|
| |
| Iterator | begin () |
| |
| ConstIterator | end () const |
| | Gives access to the underlying text buffer.
|
| |
| Iterator | end () |
| |
| static std::istream & | getLine (std::istream &is, std::string &t) |
| | Platform-agnostic getline() which can deal with all line endings (\r, \r\n, \n)
|
| |
This class handles csv files. Currently only loading is implemented.
- Note
- Lines whose first character is '#' are unconditionally treated as comments and silently skipped on load (they are not stored and are not counted by rowCount()). The load() method strips leading whitespace before this test (so " #x" is also skipped), whereas the CsvFile(filename, ...) constructor tests the raw, untrimmed line. This comment symbol is hardcoded and cannot be disabled, so a CSV whose first field legitimately starts with '#' will lose those rows.
-
items are allowed to be enclosed by only one character e.g. "item" where " is enclosing character
◆ CsvFile() [1/2]
◆ ~CsvFile()
◆ CsvFile() [2/2]
| CsvFile |
( |
const std::string & |
filename, |
|
|
char |
is = ',', |
|
|
bool |
ie = false, |
|
|
Int |
first_n = -1 |
|
) |
| |
Constructor with filename.
- Parameters
-
| [in] | filename | The input file name. |
| [in] | is | character which separates the items. |
| [in] | ie | Whether or not every item is enclosed. |
| [in] | first_n | Only the given number of lines are read, starting from the beginning of the file. |
- Exceptions
-
◆ addRow()
Add a row to the buffer.
- Parameters
-
| [in] | list | StringList which will contain all items of the row to add |
◆ clear()
◆ getRow()
writes all items from a row to list
- Parameters
-
| [in] | row | the row which will be read |
| [out] | list | StringList which will contain all items of the row |
- Exceptions
-
- Returns
- returns false if the given row could not be separated into items
◆ load()
| void load |
( |
const std::string & |
filename, |
|
|
char |
is = ',', |
|
|
bool |
ie = false, |
|
|
Int |
first_n = -1 |
|
) |
| |
Loads data from a text file.
- Parameters
-
| [in] | filename | The input file name. |
| [in] | is | character which separates the items. |
| [in] | ie | Whether or not every item is enclosed. |
| [in] | first_n | Only the given number of lines are read, starting from the beginning of the file. |
- Exceptions
-
◆ rowCount()
| std::vector< std::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 std::string & |
filename | ) |
|
Stores the buffer's content into a file.
- Parameters
-
| [in] | filename | The output filename. |
◆ itemenclosed_
◆ itemseperator_