libscio/src/byte_order_changer.cpp

38 lines
1013 B
C++
Raw Normal View History

#include <cmath>
#include <cstring>
#include <stdexcept>
#include "byte_order_changer.hpp"
#include "data_streamer.hpp"
using namespace sc::io;
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);
}
byte_order_changer::~byte_order_changer() {
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;
}
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;
}