Missing implementation of BaseMapSource::fetch().
This commit is contained in:
parent
f54da89531
commit
708ae975dc
3 changed files with 75 additions and 0 deletions
|
@ -3,14 +3,23 @@
|
||||||
|
|
||||||
#include "doorkeeper/implem/maptypes.hpp"
|
#include "doorkeeper/implem/maptypes.hpp"
|
||||||
#include "doorkeeper/primitivetypes.hpp"
|
#include "doorkeeper/primitivetypes.hpp"
|
||||||
|
#include "doorkeeper/implem/coords_utils.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace dk {
|
namespace dk {
|
||||||
|
namespace implem {
|
||||||
|
template <typename T, uint32_t D, bool POD=std::is_pod<T>::value>
|
||||||
|
class data_fetcher;
|
||||||
|
} //namespace implem
|
||||||
|
|
||||||
template <uint32_t D>
|
template <uint32_t D>
|
||||||
class BaseMapSource {
|
class BaseMapSource {
|
||||||
|
template <typename T, uint32_t, bool POD>
|
||||||
|
friend class implem::data_fetcher;
|
||||||
public:
|
public:
|
||||||
typedef dk::Vector<D> coords;
|
typedef dk::Vector<D> coords;
|
||||||
BaseMapSource ( void ) = default;
|
BaseMapSource ( void ) = default;
|
||||||
|
@ -30,4 +39,6 @@ namespace dk {
|
||||||
};
|
};
|
||||||
} //namespace dk
|
} //namespace dk
|
||||||
|
|
||||||
|
#include "doorkeeper/implem/basemapsource.inl"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
38
include/doorkeeper/implem/basemapsource.inl
Normal file
38
include/doorkeeper/implem/basemapsource.inl
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
namespace dk {
|
||||||
|
namespace implem {
|
||||||
|
template <typename T, uint32_t D>
|
||||||
|
class data_fetcher<T, D, true> {
|
||||||
|
public:
|
||||||
|
typedef typename BaseMapSource<D>::coords coords;
|
||||||
|
static void fetch ( std::vector<T>& parOut, const coords& parFrom, const coords& parTo, std::size_t parCount, BaseMapSource<D>& parMapSrc ) {
|
||||||
|
parOut.resize(parCount);
|
||||||
|
parMapSrc.fetch_raw(reinterpret_cast<char*>(parOut.data()), parFrom, parTo, sizeof(T) * parCount);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <typename T, uint32_t D>
|
||||||
|
class data_fetcher<T, D, false> {
|
||||||
|
public:
|
||||||
|
typedef typename BaseMapSource<D>::coords coords;
|
||||||
|
static void fetch ( std::vector<T>& parOut, const coords& parFrom, const coords& parTo, std::size_t parCount, BaseMapSource<D>& parMapSrc ) {
|
||||||
|
parOut.reserve(parCount);
|
||||||
|
DK_ASSERT(false); //not implemented
|
||||||
|
(void)parOut;
|
||||||
|
(void)parFrom;
|
||||||
|
(void)parTo;
|
||||||
|
(void)parMapSrc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} //namespace implem
|
||||||
|
|
||||||
|
template <uint32_t D>
|
||||||
|
template <typename T>
|
||||||
|
void BaseMapSource<D>::fetch (std::vector<T>& parOut, const coords& parFrom, const coords& parTo) {
|
||||||
|
const auto tile_count = tile_volume(parFrom, parTo);
|
||||||
|
const std::size_t casted_tile_count = static_cast<std::size_t>(tile_count);
|
||||||
|
DK_ASSERT(static_cast<decltype(tile_count)>(casted_tile_count) == tile_count);
|
||||||
|
|
||||||
|
parOut.reserve(casted_tile_count);
|
||||||
|
parOut.clear();
|
||||||
|
implem::data_fetcher<T, D>::fetch(parOut, parFrom, parTo, casted_tile_count, *this);
|
||||||
|
}
|
||||||
|
} //namespace dk
|
26
include/doorkeeper/implem/coords_utils.hpp
Normal file
26
include/doorkeeper/implem/coords_utils.hpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef id2FC7119D67FA4704B5FE8A9FDA148F46
|
||||||
|
#define id2FC7119D67FA4704B5FE8A9FDA148F46
|
||||||
|
|
||||||
|
#include "doorkeeper/primitivetypes.hpp"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace dk {
|
||||||
|
template <uint32_t D>
|
||||||
|
typename Vector<D>::value_type tile_volume ( const Vector<D>& parFrom, const Vector<D>& parTo ) a_pure;
|
||||||
|
|
||||||
|
template <uint32_t D>
|
||||||
|
inline
|
||||||
|
typename Vector<D>::value_type tile_volume (const Vector<D>& parFrom, const Vector<D>& parTo) {
|
||||||
|
typedef typename Vector<D>::value_type scalar_type;
|
||||||
|
|
||||||
|
scalar_type ret_val((1));
|
||||||
|
|
||||||
|
for (uint32_t z = 0; z < D; ++z) {
|
||||||
|
const auto dist(parTo[z] - parFrom[z] + 1);
|
||||||
|
ret_val *= dist;
|
||||||
|
}
|
||||||
|
return ret_val;
|
||||||
|
}
|
||||||
|
} //namespace dk
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Reference in a new issue