From 15f402e5ffcdd79f49dcba6dd9e6fb8b384ef304 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 19 Feb 2020 18:51:39 +0100 Subject: [PATCH] changed spaces to tabs --- byte_order_stuff.cpp | 102 +++++++++++----------- libscio.hpp | 200 +++++++++++++++++++++---------------------- 2 files changed, 151 insertions(+), 151 deletions(-) diff --git a/byte_order_stuff.cpp b/byte_order_stuff.cpp index 31d96a5..6f204d6 100644 --- a/byte_order_stuff.cpp +++ b/byte_order_stuff.cpp @@ -16,92 +16,92 @@ using namespace sc::io; // data_streamer --------------------------------------------------------------- byte_order data_streamer::cur_byte_order() { - uint8_t ch[2] = {0x12, 0x34}; - uint16_t* p = reinterpret_cast(ch); - return *p == 0x1234 ? byte_order::big_endian : byte_order::little_endian; + uint8_t ch[2] = {0x12, 0x34}; + uint16_t* p = reinterpret_cast(ch); + return *p == 0x1234 ? byte_order::big_endian : byte_order::little_endian; } std::string data_streamer::get4chars(std::istream& file) const { - char buf[4]; - file.read(buf, 4); - return std::string(buf, 4); + char buf[4]; + file.read(buf, 4); + return std::string(buf, 4); } uint32_t data_streamer::getui24(std::istream& file) const { - char buf[4] = {0}; - file.read(&buf[1], 3); - if (cur_byte_order() != _target_byte_order) { - char tmp = buf[1]; - buf[1] = buf[3]; - buf[3] = tmp; - } - return *reinterpret_cast(buf); + char buf[4] = {0}; + file.read(&buf[1], 3); + if (cur_byte_order() != _target_byte_order) { + char tmp = buf[1]; + buf[1] = buf[3]; + buf[3] = tmp; + } + return *reinterpret_cast(buf); } int32_t data_streamer::getsi24(std::istream& file) const { - return static_cast(getui24(file)); + return static_cast(getui24(file)); } double data_streamer::getf80(std::istream& file) const { - float_80 val; - file.read(reinterpret_cast(val._val), sizeof(val._val)); - if (_target_byte_order != byte_order::big_endian) { - byte_swap(val._val, sizeof(val._val)); - } - return val; + float_80 val; + file.read(reinterpret_cast(val._val), sizeof(val._val)); + if (_target_byte_order != byte_order::big_endian) { + byte_swap(val._val, sizeof(val._val)); + } + return val; } void data_streamer::put4chars(const std::string& s, std::ostream& file) const { - if (s.size() < 4) { - throw std::runtime_error("data_streamer::put4chars: string too short"); - } - file.write(s.c_str(), 4); + if (s.size() < 4) { + throw std::runtime_error("data_streamer::put4chars: string too short"); + } + file.write(s.c_str(), 4); } void data_streamer::putui24(uint32_t val, std::ostream& file) const { - char* buf = reinterpret_cast(&val); - if (cur_byte_order() != _target_byte_order) { - char tmp = buf[1]; - buf[1] = buf[3]; - buf[3] = tmp; - } - file.write(&buf[1], 3); + char* buf = reinterpret_cast(&val); + if (cur_byte_order() != _target_byte_order) { + char tmp = buf[1]; + buf[1] = buf[3]; + buf[3] = tmp; + } + file.write(&buf[1], 3); } void data_streamer::putsi24(int32_t val, std::ostream& file) const { - putui24(static_cast(val), file); + putui24(static_cast(val), file); } // byte_order_changer ---------------------------------------------------------- byte_order_changer::byte_order_changer(data_streamer* ds, byte_order order) : _data_streamer {ds} { - if (ds == nullptr) { - std::cerr << "byte_order_changer: no data streamer given\n"; - return; - } - _saved_byte_order = _data_streamer->target_byte_order(); - _data_streamer->target_byte_order(order); + if (ds == nullptr) { + std::cerr << "byte_order_changer: no data streamer given\n"; + return; + } + _saved_byte_order = _data_streamer->target_byte_order(); + _data_streamer->target_byte_order(order); } byte_order_changer::~byte_order_changer() { - if (_data_streamer) { - _data_streamer->target_byte_order(_saved_byte_order); - } + if (_data_streamer) { + _data_streamer->target_byte_order(_saved_byte_order); + } } byte_order_changer::byte_order_changer(byte_order_changer&& other) { - _data_streamer = other._data_streamer; - _saved_byte_order = other._saved_byte_order; - other._data_streamer = nullptr; + _data_streamer = other._data_streamer; + _saved_byte_order = other._saved_byte_order; + other._data_streamer = nullptr; } byte_order_changer& byte_order_changer::operator=(byte_order_changer&& other) { - if (&other != this) { - _data_streamer = other._data_streamer; - _saved_byte_order = other._saved_byte_order; - other._data_streamer = nullptr; - } - return *this; + if (&other != this) { + _data_streamer = other._data_streamer; + _saved_byte_order = other._saved_byte_order; + other._data_streamer = nullptr; + } + return *this; } // float_80 -------------------------------------------------------------------- diff --git a/libscio.hpp b/libscio.hpp index ff1abbb..634fb50 100644 --- a/libscio.hpp +++ b/libscio.hpp @@ -38,140 +38,140 @@ namespace sc { fdoutbuf _buf; }; - class fdinbuf : public std::streambuf { + class fdinbuf : public std::streambuf { - }; + }; - class fdistream : public std::istream { + class fdistream : public std::istream { - }; + }; - class fdstream : public fdostream, public fdistream { + class fdstream : public fdostream, public fdistream { - }; + }; - class socketstream : public fdstream { + class socketstream : public fdstream { - }; + }; - class meminbuf : public std::streambuf { + class meminbuf : public std::streambuf { - }; + }; - class memistream : public std::istream { + class memistream : public std::istream { - }; + }; - class memoutbuf : public std::streambuf { + class memoutbuf : public std::streambuf { - }; + }; - class memostream : public std::ostream { + class memostream : public std::ostream { - }; + }; - class memstream : public memostream, public memistream { + class memstream : public memostream, public memistream { - }; + }; - struct float_80 { - unsigned char _val[10]; // big endian + struct float_80 { + unsigned char _val[10]; // big endian - float_80(); - float_80(double val); - operator double() const; - }; + float_80(); + float_80(double val); + operator double() const; + }; - enum class byte_order { - undefined, - little_endian, - big_endian - }; + enum class byte_order { + undefined, + little_endian, + big_endian + }; - class data_streamer { - public: - static byte_order cur_byte_order(); - static inline void byte_swap(void* val, size_t n) { - char* p = reinterpret_cast(val); - for (size_t i = 0; i < n / 2; ++i) { - std::swap(p[i], p[n - 1 - i]); - } - } - template - inline T get(std::istream& file) const { - char buf[sizeof(T)]; - file.read(buf, sizeof(T)); - if (cur_byte_order() != _target_byte_order) { - byte_swap(buf, sizeof(T)); - } - return *reinterpret_cast(buf); - } - template - inline void put(T val, std::ostream& file) const { - if (cur_byte_order() != _target_byte_order) { - byte_swap(&val, sizeof(T)); - } - file.write(reinterpret_cast(&val), sizeof(T)); - } + class data_streamer { + public: + static byte_order cur_byte_order(); + static inline void byte_swap(void* val, size_t n) { + char* p = reinterpret_cast(val); + for (size_t i = 0; i < n / 2; ++i) { + std::swap(p[i], p[n - 1 - i]); + } + } + template + inline T get(std::istream& file) const { + char buf[sizeof(T)]; + file.read(buf, sizeof(T)); + if (cur_byte_order() != _target_byte_order) { + byte_swap(buf, sizeof(T)); + } + return *reinterpret_cast(buf); + } + template + inline void put(T val, std::ostream& file) const { + if (cur_byte_order() != _target_byte_order) { + byte_swap(&val, sizeof(T)); + } + file.write(reinterpret_cast(&val), sizeof(T)); + } - data_streamer() = default; + data_streamer() = default; - byte_order target_byte_order() const { return _target_byte_order; } - void target_byte_order(byte_order new_byte_order) { _target_byte_order = new_byte_order; } + byte_order target_byte_order() const { return _target_byte_order; } + void target_byte_order(byte_order new_byte_order) { _target_byte_order = new_byte_order; } - std::string get4chars(std::istream& file) const; + std::string get4chars(std::istream& file) const; - uint8_t getui8(std::istream& file) const { return static_cast(file.get()); } - int8_t getsi8(std::istream& file) const { return file.get(); } - uint16_t getui16(std::istream& file) const { return get(file); } - int16_t getsi16(std::istream& file) const { return get(file); } - uint32_t getui24(std::istream& file) const; - int32_t getsi24(std::istream& file) const; - uint32_t getui32(std::istream& file) const { return get(file); } - int32_t getsi32(std::istream& file) const { return get(file); } - uint64_t getui64(std::istream& file) const { return get(file); } - int64_t getsi64(std::istream& file) const { return get(file); } + uint8_t getui8(std::istream& file) const { return static_cast(file.get()); } + int8_t getsi8(std::istream& file) const { return file.get(); } + uint16_t getui16(std::istream& file) const { return get(file); } + int16_t getsi16(std::istream& file) const { return get(file); } + uint32_t getui24(std::istream& file) const; + int32_t getsi24(std::istream& file) const; + uint32_t getui32(std::istream& file) const { return get(file); } + int32_t getsi32(std::istream& file) const { return get(file); } + uint64_t getui64(std::istream& file) const { return get(file); } + int64_t getsi64(std::istream& file) const { return get(file); } - float getf32(std::istream& file) const { return get(file); } - double getf64(std::istream& file) const { return get(file); } - double getf80(std::istream& file) const; + float getf32(std::istream& file) const { return get(file); } + double getf64(std::istream& file) const { return get(file); } + double getf80(std::istream& file) const; - void put4chars(const std::string& s, std::ostream& file) const; + void put4chars(const std::string& s, std::ostream& file) const; - void putui8(uint8_t val, std::ostream& file) const { file.put(val); } - void putsi8(int8_t val, std::ostream& file) const { file.put(val); } - void putui16(uint16_t val, std::ostream& file) const { put(val, file); } - void putsi16(int16_t val, std::ostream& file) const { put(val, file); } - void putui24(uint32_t val, std::ostream& file) const; - void putsi24(int32_t val, std::ostream& file) const; - void putui32(uint32_t val, std::ostream& file) const { put(val, file); } - void putsi32(int32_t val, std::ostream& file) const { put(val, file); } - void putui64(uint64_t val, std::ostream& file) const { put(val, file); } - void putsi64(int64_t val, std::ostream& file) const { put(val, file); } + void putui8(uint8_t val, std::ostream& file) const { file.put(val); } + void putsi8(int8_t val, std::ostream& file) const { file.put(val); } + void putui16(uint16_t val, std::ostream& file) const { put(val, file); } + void putsi16(int16_t val, std::ostream& file) const { put(val, file); } + void putui24(uint32_t val, std::ostream& file) const; + void putsi24(int32_t val, std::ostream& file) const; + void putui32(uint32_t val, std::ostream& file) const { put(val, file); } + void putsi32(int32_t val, std::ostream& file) const { put(val, file); } + void putui64(uint64_t val, std::ostream& file) const { put(val, file); } + void putsi64(int64_t val, std::ostream& file) const { put(val, file); } - void putf32(float val, std::ostream& file) const { put(val, file); } - void putf64(double val, std::ostream& file) const { put(val, file); } - void putf80(double val, std::ostream& file) const; + void putf32(float val, std::ostream& file) const { put(val, file); } + void putf64(double val, std::ostream& file) const { put(val, file); } + void putf80(double val, std::ostream& file) const; - private: - byte_order _target_byte_order {cur_byte_order()}; - }; + private: + byte_order _target_byte_order {cur_byte_order()}; + }; - class byte_order_changer { - public: - byte_order_changer(data_streamer* ds, byte_order order); - ~byte_order_changer(); + class byte_order_changer { + public: + byte_order_changer(data_streamer* ds, byte_order order); + ~byte_order_changer(); - byte_order_changer(byte_order_changer&& other); - byte_order_changer& operator=(byte_order_changer&& other); + byte_order_changer(byte_order_changer&& other); + byte_order_changer& operator=(byte_order_changer&& other); - byte_order_changer(const byte_order_changer&) = delete; - byte_order_changer& operator=(const byte_order_changer&) = delete; + byte_order_changer(const byte_order_changer&) = delete; + byte_order_changer& operator=(const byte_order_changer&) = delete; - private: - data_streamer* _data_streamer {nullptr}; - byte_order _saved_byte_order {byte_order::undefined}; - }; + private: + data_streamer* _data_streamer {nullptr}; + byte_order _saved_byte_order {byte_order::undefined}; + }; }