-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.hpp
51 lines (37 loc) · 940 Bytes
/
file.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef DWMSTATUS_FILE_HPP
#define DWMSTATUS_FILE_HPP
#include "decl.hpp"
namespace dwmstatus {
ifstream open_unbuf(const string& filename);
istream& rewind(istream& f);
//----------------------------------------------------------------------------
optional<string> read_line(istream& f);
template <typename T>
optional<T> read_value(istream& f)
{
T ans;
if (f >> ans) {
return ans;
} else {
return nullopt;
}
}
template <>
optional<string> read_value(istream& f);
istream& skip_line(istream& f, unsigned n = 1);
template <typename T>
istream& skip_value(istream& f, unsigned n = 1)
{
while (n-- && read_value<T>(f)) {
// Skip
}
return f;
}
//----------------------------------------------------------------------------
template <typename T>
optional<T> reread_value(istream& f)
{
return read_value<T>(rewind(f));
}
} // namespace dwmstatus
#endif // DWMSTATUS_FILE_HPP