DoorKeeper/include/helpers/asciimapsource.hpp
King_DuckZ 436d738620 Refactoring in map reading code - part 1/2
Fixed a bug when iterating over a view that was smaller than the map size
Added a class to abstract map readers
2015-01-05 18:01:28 +01:00

53 lines
1.6 KiB
C++

#ifndef id263B7DAF9A1C40BB8517D5D328DF8A1B
#define id263B7DAF9A1C40BB8517D5D328DF8A1B
#include "primitivetypes.hpp"
#include "implem/vector.hpp"
#include <streambuf>
#include <vector>
#include <boost/iostreams/categories.hpp> // source_tag
namespace dkh {
class AsciiMapSource : public std::streambuf {
public:
typedef dk::Vector<dk::CoordinateScalarType, 2> coords;
typedef int MapTileType;
typedef boost::iostreams::source_tag category;
enum {
MapDimensions = 2
};
AsciiMapSource ( void ) = delete;
AsciiMapSource ( const AsciiMapSource& ) = delete;
AsciiMapSource ( AsciiMapSource&& parOther ) = default;
explicit AsciiMapSource ( const char* parFilename );
explicit AsciiMapSource ( const std::string& parFilename );
explicit AsciiMapSource ( std::istream& parData );
template <typename I>
AsciiMapSource ( I parDataFrom, I parDataTo );
~AsciiMapSource ( void ) noexcept = default;
const coords& mapSize ( void ) const noexcept { return m_mapSize; }
protected:
virtual int_type underflow ( void );
virtual int_type uflow ( void );
virtual int_type pbackfail ( int_type parCh );
virtual std::streamsize showmanyc ( void );
virtual pos_type seekoff ( off_type parOff, std::ios_base::seekdir parDir, std::ios_base::openmode parWhich );
virtual pos_type seekpos( pos_type parPos, std::ios_base::openmode parWhich );
private:
enum {
DataSize = sizeof(MapTileType)
};
void parse_map_data ( std::istream& parSrc );
std::vector<MapTileType> m_wholedata;
coords m_mapSize;
std::size_t m_bytepos;
};
} //namespace dkh
#endif