1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 09:23:53 +00:00

Replace comment by static assert

This commit is contained in:
elsid 2021-05-04 13:21:47 +02:00
parent bf2f15342b
commit d9e7c2fb42
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40

View file

@ -8,6 +8,7 @@
#include <stdexcept> #include <stdexcept>
#include <vector> #include <vector>
#include <typeinfo> #include <typeinfo>
#include <type_traits>
#include <components/files/constrainedfilestream.hpp> #include <components/files/constrainedfilestream.hpp>
#include <components/misc/endianness.hpp> #include <components/misc/endianness.hpp>
@ -23,11 +24,9 @@ namespace Nif
class NIFFile; class NIFFile;
/*
readLittleEndianBufferOfType: This template should only be used with arithmetic types
*/
template <std::size_t numInstances, typename T> inline void readLittleEndianBufferOfType(Files::IStreamPtr &pIStream, T* dest) template <std::size_t numInstances, typename T> inline void readLittleEndianBufferOfType(Files::IStreamPtr &pIStream, T* dest)
{ {
static_assert(std::is_arithmetic_v<T>, "Buffer element type is not arithmetic");
pIStream->read((char*)dest, numInstances * sizeof(T)); pIStream->read((char*)dest, numInstances * sizeof(T));
if (pIStream->bad()) if (pIStream->bad())
throw std::runtime_error("Failed to read little endian typed (" + std::string(typeid(T).name()) + ") buffer of " throw std::runtime_error("Failed to read little endian typed (" + std::string(typeid(T).name()) + ") buffer of "
@ -37,11 +36,9 @@ template <std::size_t numInstances, typename T> inline void readLittleEndianBuff
Misc::swapEndiannessInplace(dest[i]); Misc::swapEndiannessInplace(dest[i]);
} }
/*
readLittleEndianDynamicBufferOfType: This template should only be used with arithmetic types
*/
template <typename T> inline void readLittleEndianDynamicBufferOfType(Files::IStreamPtr &pIStream, T* dest, std::size_t numInstances) template <typename T> inline void readLittleEndianDynamicBufferOfType(Files::IStreamPtr &pIStream, T* dest, std::size_t numInstances)
{ {
static_assert(std::is_arithmetic_v<T>, "Buffer element type is not arithmetic");
pIStream->read((char*)dest, numInstances * sizeof(T)); pIStream->read((char*)dest, numInstances * sizeof(T));
if (pIStream->bad()) if (pIStream->bad())
throw std::runtime_error("Failed to read little endian dynamic buffer of " + std::to_string(numInstances) + " instances"); throw std::runtime_error("Failed to read little endian dynamic buffer of " + std::to_string(numInstances) + " instances");