2015-11-16 18:14:37 +00:00
|
|
|
#include <Grid.h>
|
|
|
|
|
2015-11-29 11:14:44 +00:00
|
|
|
namespace Grid {
|
2015-11-16 18:14:37 +00:00
|
|
|
// Writer implementation ///////////////////////////////////////////////////////
|
2015-11-29 11:14:44 +00:00
|
|
|
TextWriter::TextWriter(const std::string &fileName)
|
|
|
|
: file_(fileName, std::ios::out)
|
2015-11-16 18:14:37 +00:00
|
|
|
{}
|
|
|
|
|
2015-11-29 11:14:44 +00:00
|
|
|
void TextWriter::push(const std::string &s)
|
2015-11-16 18:14:37 +00:00
|
|
|
{
|
|
|
|
level_++;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TextWriter::pop(void)
|
|
|
|
{
|
|
|
|
level_--;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TextWriter::indent(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < level_; ++i)
|
|
|
|
{
|
|
|
|
file_ << '\t';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Reader implementation ///////////////////////////////////////////////////////
|
2015-11-29 11:14:44 +00:00
|
|
|
TextReader::TextReader(const std::string &fileName)
|
|
|
|
: file_(fileName, std::ios::in)
|
2015-11-16 18:14:37 +00:00
|
|
|
{}
|
|
|
|
|
2015-11-29 11:14:44 +00:00
|
|
|
void TextReader::push(const std::string &s)
|
2015-11-16 18:14:37 +00:00
|
|
|
{
|
|
|
|
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')
|
|
|
|
{
|
2015-11-29 11:14:44 +00:00
|
|
|
std::cerr << "mismatch on tab " << c << " level " << level_;
|
|
|
|
std::cerr << " i "<< i <<std::endl;
|
|
|
|
std::abort();
|
2015-11-16 18:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2015-11-29 11:14:44 +00:00
|
|
|
void TextReader::readDefault(const std::string &s, std::string &output)
|
2015-11-16 18:14:37 +00:00
|
|
|
{
|
|
|
|
checkIndent();
|
|
|
|
output.clear();
|
|
|
|
getline(file_, output);
|
|
|
|
}
|
2015-11-29 11:14:44 +00:00
|
|
|
}
|