DoorKeeper/include/doorkeeper/implem/basemapsource.inl

56 lines
2.1 KiB
C++

/* Copyright 2015, Michele Santullo
* This file is part of DoorKeeper.
*
* DoorKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DoorKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DoorKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
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<D>(parTo - parFrom);
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