DoorKeeper/include/doorkeeper/helpers/tylermapsource.hpp

84 lines
2.3 KiB
C++
Raw Normal View History

#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>
2015-06-04 18:59:07 +00:00
#if !defined(NDEBUG) && !defined(WITH_TYLERMAP_WRITER)
# define WITH_TYLERMAP_WRITER
#endif
namespace dkh {
template <uint32_t D>
class TylerMapSource : public dk::BaseMapSource<D> {
public:
typedef dk::Vector<D> coords;
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 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 );
virtual void fetch_raw ( char* parOut, const coords& parFrom, const coords& parTo, std::size_t parSize );
std::unique_ptr<std::istream> m_stream;
};
2015-06-04 18:59:07 +00:00
#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