OpenMS
TextFile.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Chris Bielow $
6 // $Authors: Marc Sturm, Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 
13 namespace OpenMS
14 {
20  class OPENMS_DLLAPI TextFile
21  {
22 
23 public:
28  typedef std::vector<String>::iterator Iterator;
30  typedef std::vector<String>::const_iterator ConstIterator;
32  typedef std::vector<String>::reverse_iterator ReverseIterator;
34  typedef std::vector<String>::const_reverse_iterator ConstReverseIterator;
36 
37 
40 
42  virtual ~TextFile();
43 
54  TextFile(const String& filename, bool trim_lines = false, Int first_n = -1, bool skip_empty_lines = false, const String& comment_symbol = "");
55 
69  void load(const String& filename, bool trim_lines = false, Int first_n = -1, bool skip_empty_lines = false, const String& comment_symbol = "");
70 
78  void store(const String& filename);
79 
81  template <typename StringType>
82  TextFile& operator<<(const StringType& string)
83  {
84  buffer_.push_back(static_cast<String>(string));
85  return *this;
86  }
87 
88  template <typename StringType>
89  void addLine(const StringType& line)
90  {
91  buffer_.push_back(static_cast<String>(line));
92  }
93 
100  static std::istream& getLine(std::istream& is, std::string& t);
101 
106 
112 
114 
115 protected:
117  std::vector<String> buffer_;
118  };
119 
120 } // namespace OpenMS
121 
A more convenient string class.
Definition: String.h:34
Definition: TextFile.h:21
Iterator begin()
std::vector< String >::reverse_iterator ReverseIterator
Mutable reverse iterator.
Definition: TextFile.h:32
std::vector< String >::const_iterator ConstIterator
Non-mutable iterator.
Definition: TextFile.h:30
void addLine(const StringType &line)
Definition: TextFile.h:89
void store(const String &filename)
Writes the data to a file.
TextFile & operator<<(const StringType &string)
Operator for appending entries with less code.
Definition: TextFile.h:82
virtual ~TextFile()
destructor
TextFile()
Default constructor.
ConstIterator end() const
Gives access to the underlying text buffer.
TextFile(const String &filename, bool trim_lines=false, Int first_n=-1, bool skip_empty_lines=false, const String &comment_symbol="")
Constructor with filename.
std::vector< String >::const_reverse_iterator ConstReverseIterator
Non-mutable reverse iterator.
Definition: TextFile.h:34
static std::istream & getLine(std::istream &is, std::string &t)
Platform-agnostic getline() which can deal with all line endings (\r, \r\n, \n)
Iterator end()
void load(const String &filename, bool trim_lines=false, Int first_n=-1, bool skip_empty_lines=false, const String &comment_symbol="")
Loads data from a text file into the internal buffer.
std::vector< String >::iterator Iterator
Mutable iterator.
Definition: TextFile.h:28
ConstIterator begin() const
Gives access to the underlying text buffer.
std::vector< String > buffer_
Internal buffer storing the lines before writing them to the file.
Definition: TextFile.h:117
int Int
Signed integer type.
Definition: Types.h:72
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19