1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-16 14:57:05 +01:00

new I/O interface

This commit is contained in:
2015-11-16 18:14:37 +00:00
parent 8709117aea
commit af19118113
11 changed files with 650 additions and 510 deletions

View File

@ -0,0 +1,66 @@
#include <Grid.h>
using namespace Grid;
using namespace std;
// Writer implementation ///////////////////////////////////////////////////////
TextWriter::TextWriter(const string &fileName)
: file_(fileName, ios::out)
{}
void TextWriter::push(const string &s)
{
level_++;
};
void TextWriter::pop(void)
{
level_--;
};
void TextWriter::indent(void)
{
for (int i = 0; i < level_; ++i)
{
file_ << '\t';
}
};
// Reader implementation ///////////////////////////////////////////////////////
TextReader::TextReader(const string &fileName)
: file_(fileName, ios::in)
{}
void TextReader::push(const string &s)
{
level_++;
};
void TextReader::pop(void)
{
level_--;
};
void TextReader::checkIndent(void)
{
char c;
for (int i = 0; i < level_; ++i)
{
file_.get(c);
if (c != '\t')
{
cerr << "mismatch on tab " << c << " level " << level_;
cerr << " i "<< i <<endl;
abort();
}
}
}
template <>
void TextReader::readDefault(const string &s, string &output)
{
checkIndent();
output.clear();
getline(file_, output);
}