DoorKeeper/include/implem/tilestream.inl
2014-12-22 16:56:17 +01:00

40 lines
1.3 KiB
C++

namespace dk {
template <typename T, size_t D>
TileStreamer<T, D>::TileStreamer (StreamPtr&& parStream) :
m_stream(std::move(parStream))
{
//TODO: this loader /only/ works with 2D tilesets, remove it asap
typedef std::istream_iterator<char> DataIterator;
typedef boost::spirit::multi_pass<DataIterator> WrappedIterator;
*m_stream >> std::noskipws;
auto first = WrappedIterator(DataIterator(*m_stream));
auto last = WrappedIterator(DataIterator());
implem::AsciiMapGrammar<WrappedIterator, T> grammar(first);
const bool p = boost::spirit::qi::parse(
first,
last,
grammar,
m_wholedata
);
if (not p or last != first) {
throw std::runtime_error("Invalid data: can't parse file");
}
//Only look at the front. Besides a bug in spirit makes the other counts
//invalid, see
//http://boost.2283326.n4.nabble.com/Possible-bug-in-line-pos-iterator-td4636592.html
m_count.x() = grammar.lengths.front();
m_count.y() = m_wholedata.size() / m_count.x();
}
template <typename T, size_t D>
void TileStreamer<T, D>::copy (std::vector<T>& parDest, const coords& /*parFrom*/, const coords& /*parTo*/) {
parDest.clear();
parDest.reserve(m_wholedata.size());
std::copy(m_wholedata.begin(), m_wholedata.end(), std::back_inserter(parDest));
}
} //namespace dk