BALL 1.5.0
Loading...
Searching...
No Matches
lineBasedFile.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4
5#ifndef BALL_FORMAT_LINEBASEDFILE_H
6#define BALL_FORMAT_LINEBASEDFILE_H
7
8#ifndef BALL_SYSTEM_FILE_H
9# include <BALL/SYSTEM/file.h>
10#endif
11
12#include <vector>
13
14namespace BALL
15{
21 : public File
22 {
23 public:
24
28
31
38 LineBasedFile(const String& filename, File::OpenMode open_mode = std::ios::in, bool trim_whitespaces = false);
39
42 void clear();
43
45
48
51 bool operator == (const LineBasedFile& f);
52
55 bool operator != (const LineBasedFile& f);
57
61
66 const LineBasedFile& operator = (const LineBasedFile& file);
67
69
72
75
77 const String& getLine() const;
78
81
83
86
91 bool readLine();
92
97 bool skipLines(Size number = 1);
98
105 bool search(const String& text, bool return_to_start = false);
106
107 /* Search for a line starting with a given string, abort at a stop tag.
108 * @throw Exception::ParseError if a syntax error was encountered
109 */
110 bool search(const String& text, const String& stop, bool return_to_start = false);
111
116 bool gotoLine(Position line_number);
117
121 void rewind();
122
135 void test(const char* file, int line, bool condition, const String& msg) const;
136
141 String getField(Index pos = 0, const String& quotes = "",
142 const String& delimiters = String::CHARACTER_CLASS__WHITESPACE) const;
143
145 bool startsWith(const String& text) const;
146
148 bool has(const String& text) const;
149
153 Index switchString(const std::vector<String>& data) const;
154
159 bool parseColumnFormat(const char* format, Position index, Size length, void* arg);
160
162 void enableTrimWhitespaces(bool state);
163
166
167 protected:
169 /* @name Protected Attributes
170 */
171 //_@{
174
177
179
181 vector<char> col_buffer_;
182
183 //_@}
184 };
185
186
187# ifndef BALL_NO_INLINE_FUNCTIONS
188# include <BALL/FORMAT/lineBasedFile.iC>
189# endif
190} // namespace BALL
191
192#endif // BALL_FORMAT_LINEBASEDFILE_H
Position getLineNumber() const
Get the last line number in the file.
bool gotoLine(Position line_number)
String getField(Index pos=0, const String &quotes="", const String &delimiters=String::CHARACTER_CLASS__WHITESPACE) const
bool startsWith(const String &text) const
Test if the current line starts with text.
void enableTrimWhitespaces(bool state)
Set wheter leading and trailing whitespaces in lines shall be removed.
String line_
buffer for the line in use
LineBasedFile()
Default constructor.
bool parseColumnFormat(const char *format, Position index, Size length, void *arg)
LineBasedFile(const String &filename, File::OpenMode open_mode=std::ios::in, bool trim_whitespaces=false)
vector< char > col_buffer_
buffer for column parsing
bool trimWhiteSpacesEnabled() const
String & getLine()
Return the current line.
Index switchString(const std::vector< String > &data) const
void test(const char *file, int line, bool condition, const String &msg) const
bool skipLines(Size number=1)
bool search(const String &text, bool return_to_start=false)
bool search(const String &text, const String &stop, bool return_to_start=false)
Position line_number_
line number in the file
const String & getLine() const
Return the current line.
bool has(const String &text) const
Return true if the current line contains text.
std::ios::openmode OpenMode
Definition file.h:165
#define BALL_EXPORT