2014-12-09 21:30:06 +00:00
|
|
|
namespace dk {
|
|
|
|
template <typename T, size_t D>
|
|
|
|
TileStreamer<T, D>::TileStreamer (StreamPtr&& parStream) :
|
|
|
|
m_stream(std::move(parStream))
|
|
|
|
{
|
2014-12-13 03:50:23 +00:00
|
|
|
//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));
|
2014-12-09 21:30:06 +00:00
|
|
|
}
|
|
|
|
} //namespace dk
|