DoorKeeper/include/doorkeeper/helpers/tylermapsource.hpp

84 lines
2.4 KiB
C++

#ifndef id3F4AB2FAA29D4A0FA87760E61F0762C0
#define id3F4AB2FAA29D4A0FA87760E61F0762C0
#include "doorkeeper/primitivetypes.hpp"
#include "doorkeeper/implem/vector.hpp"
#include "doorkeeper/components/basemapsource.hpp"
#include <fstream>
#include <cstdint>
#include <memory>
#include <map>
#include <string>
#include <ciso646>
#include <exception>
#if !defined(NDEBUG) && !defined(WITH_TYLERMAP_WRITER)
# define WITH_TYLERMAP_WRITER
#endif
namespace dkh {
template <typename T, uint32_t D>
class TylerMapSource : public dk::BaseMapSource<T, D> {
public:
typedef dk::Vector<dk::CoordinateScalarType, 2> coords;
typedef T MapTileType;
enum {
MapDimensions = D
};
TylerMapSource ( void ) = delete;
TylerMapSource ( const TylerMapSource& ) = delete;
TylerMapSource ( TylerMapSource&& ) = default;
explicit TylerMapSource ( const char* parFilename );
explicit TylerMapSource ( const std::string& parFilename );
explicit TylerMapSource ( std::istream* parData );
virtual ~TylerMapSource ( void ) noexcept = default;
virtual const coords& mapSize ( void ) const;
virtual const coords& tileSize ( void ) const;
virtual void fetch ( std::vector<MapTileType>& parOut, const coords& parFrom, const coords& parTo );
virtual dk::MapTypes mapType ( void ) const;
virtual int layersCount ( void ) const;
virtual void chainedMaps ( std::vector<std::string>& parOut ) const;
private:
void parse_map_data ( std::istream& parSrc );
std::unique_ptr<std::istream> m_stream;
};
#if defined(WITH_TYLERMAP_WRITER)
class TylerMapWriter {
public:
TylerMapWriter ( void ) = delete;
TylerMapWriter ( const TylerMapWriter& ) = delete;
TylerMapWriter ( TylerMapWriter&& ) = default;
private:
std::unique_ptr<std::ostream> m_stream;
};
#endif
class InvalidMapFileException : public std::exception {
};
namespace implem {
struct TylerMapHeader {
uint32_t signature;
uint32_t file_size;
uint16_t version_major;
uint16_t version_minor;
uint8_t layer_count;
uint8_t map_type;
uint8_t map_info_type;
uint8_t dimensions;
} __attribute__((packed, aligned(__alignof__(uint32_t))));
typedef std::map<std::string, std::string> CommentMap;
void read_header ( std::istream& parStream, TylerMapHeader& parHeader );
void read_comments ( std::istream& parStream, std::string& parVendor, CommentMap& parComments );
} //namespace implem
} //namespace dkh
#endif