forked from cvc5/ethos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.cpp
78 lines (69 loc) · 1.96 KB
/
input.cpp
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
/******************************************************************************
* This file is part of the ethos project.
*
* Copyright (c) 2023-2024 by the authors listed in the file AUTHORS
* in the top-level source directory and their institutional affiliations.
* All rights reserved. See the file COPYING in the top-level source
* directory for licensing information.
******************************************************************************/
#include "input.h"
#include <fstream>
#include <iostream>
#include "base/check.h"
namespace ethos {
/** File input class */
class FileInput : public Input
{
public:
FileInput(const std::string& filename) : Input()
{
d_fs.open(filename, std::fstream::in);
if (!d_fs.is_open())
{
EO_FATAL() << "Couldn't open file: " << filename;
}
}
std::istream* getStream() override { return &d_fs; }
private:
/** File stream */
std::ifstream d_fs;
};
/** Stream reference input class */
class StreamInput : public Input
{
public:
StreamInput(std::istream& input) : Input(), d_input(input) {}
std::istream* getStream() override { return &d_input; }
bool isInteractive() const override { return true; }
private:
/** Reference to stream */
std::istream& d_input;
};
/** String input class */
class StringInput : public Input
{
public:
StringInput(const std::string& input) : Input()
{
d_ss << input;
}
std::istream* getStream() override { return &d_ss; }
private:
/** String stream */
std::stringstream d_ss;
};
Input::Input() {}
bool Input::isInteractive() const { return false; }
std::unique_ptr<Input> Input::mkFileInput(const std::string& filename)
{
return std::unique_ptr<Input>(new FileInput(filename));
}
std::unique_ptr<Input> Input::mkStreamInput(std::istream& input)
{
return std::unique_ptr<Input>(new StreamInput(input));
}
std::unique_ptr<Input> Input::mkStringInput(const std::string& input)
{
return std::unique_ptr<Input>(new StringInput(input));
}
} // namespace ethos