-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenizer.h
55 lines (40 loc) · 1.59 KB
/
tokenizer.h
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
#ifndef BLIF_VERIFIER_TOKENIZER_H
#define BLIF_VERIFIER_TOKENIZER_H
#include <iosfwd>
#include <vector>
#include <stack>
#include <string>
namespace Tokenizer {
// Simple class to return lines one at a time as tokens and discard comments
// and empty lines while allowing pushback capability.
class LineTokenReader {
public:
// Default ctor so class can be moved.
LineTokenReader();
// Construct a LineTokenReader bound to an input stream.
explicit LineTokenReader(std::istream& is);
// Read the next line as a token list.
void readLine(std::vector<std::string>& tokens);
std::vector<std::string> readLine();
// Push a vector of tokens back onto the reader. It will then be read before
// subsequent reads from file. Supports move semantics too!
void putBack(const std::vector<std::string>& tokens);
void putBack(std::vector<std::string>&& tokens);
// Return the current raw line number (number of lines read from input
// stream). This will ignore things like putbacks.
int getRawLineNumber() const;
// Query whether data can be read
bool isGood() const;
private:
// All pushed back values to be read back before reading from file.
std::stack<std::vector<std::string>> mPushbacks;
// The bound istream, since istreams are not concrete types and thus cannot
// be moved, the best we can do is hold a pointer to it.
std::istream* mStream;
// Whether data can be read.
bool mGood;
// Number of lines read from input stream.
int mRawLineNumber;
};
} // namespace Tokenizer
#endif // BLIF_VERIFIER_TOKENIZER_H