| OpenMS 2.5.0

Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
TextFile Class Reference
Format » File IO

This class provides some basic file handling methods for text files. More...

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

Inheritance diagram for TextFile:

## Public Types

Type definitions
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...

## Public Member Functions

| 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 Public Member Functions

static std::istream & | getLine (std::istream &is, std::string &t)
| Platform-agnostic getline() which can deal with all line endings (, , ) More...

## Protected Attributes

std::vector< String > | buffer_
| Internal buffer storing the lines before writing them to the file. More...

## Detailed Description

This class provides some basic file handling methods for text files.

## Member Typedef Documentation

## ◆ ConstIterator

typedef std::vector<String>::const_iterator ConstIterator

Non-mutable iterator.

## ◆ ConstReverseIterator

typedef std::vector<String>::const_reverse_iterator ConstReverseIterator

Non-mutable reverse iterator.

## ◆ Iterator

typedef std::vector<String>::iterator Iterator

Mutable iterator.

## ◆ ReverseIterator

typedef std::vector<String>::reverse_iterator ReverseIterator

Mutable reverse iterator.

## Constructor & Destructor Documentation

## ◆ TextFile() [1/2]

TextFile | ( |  | ) |

Default constructor.

## ◆ ~TextFile()

virtual ~TextFile | ( |  | ) |

virtual

destructor

## ◆ TextFile() [2/2]

TextFile | ( | const String & | filename,
|  | bool | trim_lines = `false`,
|  | Int | first_n = `-1`,
|  | bool | skip_empty_lines = `false`
| ) |  |

Constructor with filename.

Parameters

  filename |

See also
  load()

Parameters

  trim_lines |

See also
  load()

Parameters

  first_n |

See also
  load()

Parameters

  skip_empty_lines |

See also
  load()

Exceptions

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

## Member Function Documentation

## ◆ addLine()

void addLine | ( | const StringType & | line | ) |

inline

Referenced by RIntegration::checkRDependencies(), MetaProSIPReporting::plotFilteredSpectra(), MetaProSIPReporting::plotHeatMap(), MetaProSIPReporting::plotScoresAndWeights(), and MetaProSIPReporting::writeHTML().

## ◆ begin() [1/2]

ConstIterator begin | ( |  | ) | const

Gives access to the underlying text buffer.

Referenced by RIntegration::checkRDependencies(), SpecArrayFile::load(), and MsInspectFile::load().

## ◆ begin() [2/2]

Iterator begin | ( |  | ) |

## ◆ end() [1/2]

ConstIterator end | ( |  | ) | const

Gives access to the underlying text buffer.

Referenced by RIntegration::checkRDependencies(), SpecArrayFile::load(), and MsInspectFile::load().

## ◆ end() [2/2]

Iterator end | ( |  | ) |

## ◆ getLine()

static std::istream& getLine | ( | std::istream & | is,
|  | std::string & | t
| ) |  |

static

Platform-agnostic getline() which can deal with all line endings (,
,
)

Line endings will be removed from the resulting string.

## ◆ load()

void load | ( | const String & | filename,
|  | bool | trim_lines = `false`,
|  | Int | first_n = `-1`,
|  | bool | skip_empty_lines = `false`
| ) |  |

Loads data from a text file.

Parameters

  filename | The input file name
  trim_lines | Whether or not the lines are trimmed when reading them from file
  first_n | If set, only `first_n` lines the lines from the beginning of the file are read
  skip_empty_lines | Should empty lines be skipped? If used in conjunction with `trim_lines`, also lines with only whitespace will be skipped. Skipped lines do not count towards the total number of read lines.

Exceptions

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

## ◆ operator<<()

TextFile& operator<< | ( | const StringType & | string | ) |

inline

Operator for appending entries with less code.

## ◆ store()

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

Writes the data to a file.

Note
  This function uses platform-dependent line breaks

Exceptions

  Exception::UnableToCreateFile | is thrown if the file could not be created

Referenced by RIntegration::checkRDependencies(), MetaProSIPReporting::plotFilteredSpectra(), MetaProSIPReporting::plotHeatMap(), MetaProSIPReporting::plotScoresAndWeights(), and MetaProSIPReporting::writeHTML().

## Member Data Documentation

## ◆ buffer_

std::vector<String> buffer_

protected

Internal buffer storing the lines before writing them to the file.