2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-05 08:25:16 +00:00

[2369] Make InputSource manage opening files internally

This commit is contained in:
Mukund Sivaraman
2012-10-30 12:39:38 +05:30
parent 2c8d3ac2d8
commit b5ca6ac342
3 changed files with 55 additions and 16 deletions

View File

@@ -14,10 +14,44 @@
#include <dns/inputsource.h>
#include <cstdio>
using namespace std;
namespace isc {
namespace dns {
namespace master_lexer_internal {
InputSource::InputSource(std::istream& input_stream) :
at_eof_(false),
line_(1),
saved_line_(line_),
buffer_pos_(buffer_.size()),
input_(input_stream)
{
char buf[FILENAME_MAX];
snprintf(buf, sizeof(buf), "stream-%p", &input_stream);
name_ = buf;
}
InputSource::InputSource(const char* filename) :
at_eof_(false),
line_(1),
saved_line_(line_),
buffer_pos_(buffer_.size()),
name_(filename),
input_(file_stream_)
{
file_stream_.open(filename, fstream::in);
}
InputSource::~InputSource()
{
if (file_stream_.is_open()) {
file_stream_.close();
}
}
int
InputSource::getChar() {
if (buffer_pos_ == buffer_.size()) {