DoorKeeper/include/components/tilemapdata.hpp

68 lines
2.2 KiB
C++
Raw Normal View History

#ifndef id8F5106DFABC14263ADF235C56E434207
#define id8F5106DFABC14263ADF235C56E434207
#include "primitivetypes.hpp"
#include "implem/compatibility.h"
#include "implem/vector.hpp"
#include "implem/helpers.hpp"
#include <cstddef>
#include <type_traits>
#include <iterator>
namespace dk {
namespace implem {
template <typename T>
class HasMapDimensions {
class yes { char m; };
class nope { yes m[2]; };
static yes deduce ( int a, int b = T::MapDimensions );
static nope deduce ( ... );
public:
enum {
result = (sizeof(yes) == sizeof(deduce(1)))
};
};
template <std::size_t D, typename Device>
typename std::enable_if<Device::MapDimensions == D, std::size_t>::type err_mismatching_dimension ( const Device* ) noexcept a_pure;
template <std::size_t D, typename Device>
typename std::enable_if<HasMapDimensions<Device>::result == false, std::size_t>::type err_mismatching_dimension ( const Device* ) noexcept a_pure;
template <std::size_t D, typename Device>
typename std::enable_if<Device::MapDimensions == D, Vector<CoordinateScalarType, D>>::type retrieve_map_size_from_device ( Device* parDevice );
template <std::size_t D, typename Device>
typename std::enable_if<HasMapDimensions<Device>::result == false, Vector<CoordinateScalarType, D>>::type retrieve_map_size_from_device ( Device* parDevice );
} //namespace implem
//Customization point - specialize to enable map size retrieval for Device
template <std::size_t D, typename Device>
typename Device::coords get_map_size_from_device ( const Device* parDevice );
template <typename T, std::size_t D>
class TileMapData {
public:
typedef Vector<CoordinateScalarType, D> coords;
TileMapData ( void ) = delete;
template <typename Device>
explicit TileMapData ( Device& parDevice );
//TODO: add an overload to initialize a TileMapData from a universal reference to std::istream
~TileMapData ( void ) noexcept = default;
bool streamHasDimensionInfo ( void ) const { return m_deviceHasDim; }
void fetch ( std::vector<T>& parOut, const coords& parFrom, const coords& parTo );
const coords& mapSize ( void ) const;
private:
std::istream m_stream;
const coords m_mapSize;
const bool m_deviceHasDim;
};
} //namespace dk
#include "implem/tilemapdata.inl"
#endif