From f5e936e9399ead5824196204c20d976300453565 Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Tue, 28 May 2024 01:38:04 +0300 Subject: [PATCH] Move IOOpts.h into main tree Added bin_read function for reading capabilities. Force checking types to arithmetic (int and float) --- {tools/HogMaker => lib}/IOOps.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) rename {tools/HogMaker => lib}/IOOps.h (66%) diff --git a/tools/HogMaker/IOOps.h b/lib/IOOps.h similarity index 66% rename from tools/HogMaker/IOOps.h rename to lib/IOOps.h index 57739270..7efd3bdf 100644 --- a/tools/HogMaker/IOOps.h +++ b/lib/IOOps.h @@ -18,18 +18,28 @@ #pragma once #include +#include #include #include "byteswap.h" namespace D3 { -template -static inline std::ostream &bin_write(std::ostream &output, T value, bool is_little_endian = true, size_t n = sizeof(T)) { +template >> +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(&value), n); return output; } +template >> +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(&value), n); + value = is_little_endian ? convert_le(value) : convert_be(value); + + return input; +} + } // namespace D3