-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipar_common.h
More file actions
90 lines (71 loc) · 2.31 KB
/
Copy pathipar_common.h
File metadata and controls
90 lines (71 loc) · 2.31 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
////////////////////////////////////////////////////////
// Common logic for several programs are featured here.
////////////////////////////////////////////////////////
#ifndef IPAR_COMMON_H_ // {
#define IPAR_COMMON_H_
#include <fstream>
#include <istream>
#include <sstream>
#include <string>
#include "ipar_iplist.h"
namespace IPAR {
// Handle user request for output format
enum OutputStyle {
Sunknown,
Scidr,
Sdashes,
Shex
};
OutputStyle o_style (const std::string& arg);
// This class handles text input in a common style for the IPAR programs:
// * All text from character # to end of line is ignored.
// * Text is broken down into a stream of words, delimited by spaces.
// * Current line number can be queried.
// * Full content of current line of text can be queried.
class TextReader
{
public:
// The automatic methods
TextReader() = delete;
~TextReader() = default;
TextReader(TextReader const& other) = delete;
TextReader& operator=(TextReader const& other) = delete;
TextReader(TextReader&& other) = default;
TextReader& operator=(TextReader&& other) = delete;
TextReader(std::istream& ist);
TextReader& operator>> (std::string& word);
operator bool() const;
std::string current_line() const;
unsigned int line_no() const;
private:
std::istream& mIst;
std::istringstream mSst;
std::string mLine;
unsigned int mLineNo;
bool mLineOk;
bool mFileOk;
}; // class TextReader
class FileReader
{
public:
// The automatic methods
FileReader() = delete;
~FileReader() = default;
FileReader(FileReader const& other) = delete;
FileReader& operator=(FileReader const& other) = delete;
FileReader(FileReader&& other) = default;
FileReader& operator=(FileReader&& other) = delete;
FileReader(const std::string& filename);
FileReader& operator>> (std::string& word) { mTr >> word; return *this; }
operator bool() const { return bool(mTr); }
std::string current_line() const { return mTr.current_line(); }
unsigned int line_no() const { return mTr.line_no(); }
private:
std::ifstream mIfs;
TextReader mTr;
};
// This method does a batch-read of interval specifiers from an
// istream into an IPAR list.
int common_read (std::istream& ist, List& iplist);
} // namespace IPAR
#endif // } IPAR_COMMON_H_