mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
Move IOOpts.h into main tree
Added bin_read function for reading capabilities. Force checking types to arithmetic (int and float)
This commit is contained in:
parent
87472f47fe
commit
f5e936e939
@ -18,18 +18,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
#include "byteswap.h"
|
||||
|
||||
namespace D3 {
|
||||
|
||||
template <class T>
|
||||
static inline std::ostream &bin_write(std::ostream &output, T value, bool is_little_endian = true, size_t n = sizeof(T)) {
|
||||
template <class T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||
static inline std::ostream &bin_write(std::ostream &output, T value, bool is_little_endian = true,
|
||||
size_t n = sizeof(T)) {
|
||||
value = is_little_endian ? convert_le(value) : convert_be(value);
|
||||
output.write(reinterpret_cast<const char *>(&value), n);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
template <class T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
|
||||
static inline std::istream &bin_read(std::istream &input, T &value, bool is_little_endian = true, size_t n = sizeof(T)) {
|
||||
input.read(reinterpret_cast<char *>(&value), n);
|
||||
value = is_little_endian ? convert_le(value) : convert_be(value);
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
} // namespace D3
|
Loading…
Reference in New Issue
Block a user