72 lines
3.5 KiB
Text
72 lines
3.5 KiB
Text
|
namespace dk {
|
||
|
namespace implem {
|
||
|
///---------------------------------------------------------------------
|
||
|
///Only enabled if Device::MapDimensions is defined and is the same
|
||
|
///as D. The function's name is set to give a hint to the user as to
|
||
|
///why the error has occurred (they are trying to construct a
|
||
|
///TileMapData with a set dimension that is different from the one
|
||
|
///hardcoded in the device being passed in). The actual name could be
|
||
|
///something like get_device_dimensions().
|
||
|
///---------------------------------------------------------------------
|
||
|
template <std::size_t D, typename Device>
|
||
|
typename std::enable_if<Device::MapDimensions == D, std::size_t>::type err_mismatching_dimension (const Device*) noexcept {
|
||
|
return Device::MapDimensions;
|
||
|
}
|
||
|
|
||
|
///---------------------------------------------------------------------
|
||
|
///Only enabled if Device::MapDimensions is not defined. The function's
|
||
|
///name is set to give a hint to the user as to why the error has
|
||
|
///occurred (they are trying to construct a TileMapData with a set
|
||
|
///dimension that is different from the one hardcoded in the device
|
||
|
///being passed in). The actual name could be something like
|
||
|
///get_device_dimensions().
|
||
|
///---------------------------------------------------------------------
|
||
|
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 {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
///---------------------------------------------------------------------
|
||
|
///---------------------------------------------------------------------
|
||
|
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) {
|
||
|
return parDevice->mapSize();
|
||
|
}
|
||
|
|
||
|
///---------------------------------------------------------------------
|
||
|
///---------------------------------------------------------------------
|
||
|
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) {
|
||
|
return get_map_size_from_device<D>(parDevice);
|
||
|
}
|
||
|
} //namespace implem
|
||
|
|
||
|
///-------------------------------------------------------------------------
|
||
|
///-------------------------------------------------------------------------
|
||
|
template <typename T, std::size_t D>
|
||
|
template <typename Device>
|
||
|
TileMapData<T, D>::TileMapData (Device& parDevice) :
|
||
|
m_stream(&parDevice),
|
||
|
m_mapSize(implem::retrieve_map_size_from_device<D>(&parDevice)),
|
||
|
m_deviceHasDim(D == implem::err_mismatching_dimension<D>(&parDevice))
|
||
|
{
|
||
|
}
|
||
|
|
||
|
///-------------------------------------------------------------------------
|
||
|
///-------------------------------------------------------------------------
|
||
|
template <typename T, std::size_t D>
|
||
|
void TileMapData<T, D>::fetch (std::vector<T>& parOut, const coords& parFrom, const coords& parTo) {
|
||
|
//TODO: implement
|
||
|
std::cout << "Would fetch data from " << parFrom << " to " << parTo << "\n";
|
||
|
const auto count = implem::area(parTo - parFrom);
|
||
|
std::fill_n(std::back_inserter(parOut), count, T());
|
||
|
}
|
||
|
|
||
|
///-------------------------------------------------------------------------
|
||
|
///-------------------------------------------------------------------------
|
||
|
template <typename T, std::size_t D>
|
||
|
const typename TileMapData<T, D>::coords& TileMapData<T, D>::mapSize() const {
|
||
|
return m_mapSize;
|
||
|
}
|
||
|
} //namespace dk
|