Base: modernize C++: use default member init
This commit is contained in:
@@ -40,9 +40,7 @@
|
||||
|
||||
using namespace Base;
|
||||
|
||||
Stream::Stream() : _swap(false)
|
||||
{
|
||||
}
|
||||
Stream::Stream() = default;
|
||||
|
||||
Stream::~Stream() = default;
|
||||
|
||||
@@ -82,56 +80,56 @@ OutputStream& OutputStream::operator << (uint8_t uch)
|
||||
|
||||
OutputStream& OutputStream::operator << (int16_t s)
|
||||
{
|
||||
if (_swap) SwapEndian<int16_t>(s);
|
||||
if (isSwapped()) SwapEndian<int16_t>(s);
|
||||
_out.write((const char*)&s, sizeof(int16_t));
|
||||
return *this;
|
||||
}
|
||||
|
||||
OutputStream& OutputStream::operator << (uint16_t us)
|
||||
{
|
||||
if (_swap) SwapEndian<uint16_t>(us);
|
||||
if (isSwapped()) SwapEndian<uint16_t>(us);
|
||||
_out.write((const char*)&us, sizeof(uint16_t));
|
||||
return *this;
|
||||
}
|
||||
|
||||
OutputStream& OutputStream::operator << (int32_t i)
|
||||
{
|
||||
if (_swap) SwapEndian<int32_t>(i);
|
||||
if (isSwapped()) SwapEndian<int32_t>(i);
|
||||
_out.write((const char*)&i, sizeof(int32_t));
|
||||
return *this;
|
||||
}
|
||||
|
||||
OutputStream& OutputStream::operator << (uint32_t ui)
|
||||
{
|
||||
if (_swap) SwapEndian<uint32_t>(ui);
|
||||
if (isSwapped()) SwapEndian<uint32_t>(ui);
|
||||
_out.write((const char*)&ui, sizeof(uint32_t));
|
||||
return *this;
|
||||
}
|
||||
|
||||
OutputStream& OutputStream::operator << (int64_t l)
|
||||
{
|
||||
if (_swap) SwapEndian<int64_t>(l);
|
||||
if (isSwapped()) SwapEndian<int64_t>(l);
|
||||
_out.write((const char*)&l, sizeof(int64_t));
|
||||
return *this;
|
||||
}
|
||||
|
||||
OutputStream& OutputStream::operator << (uint64_t ul)
|
||||
{
|
||||
if (_swap) SwapEndian<uint64_t>(ul);
|
||||
if (isSwapped()) SwapEndian<uint64_t>(ul);
|
||||
_out.write((const char*)&ul, sizeof(uint64_t));
|
||||
return *this;
|
||||
}
|
||||
|
||||
OutputStream& OutputStream::operator << (float f)
|
||||
{
|
||||
if (_swap) SwapEndian<float>(f);
|
||||
if (isSwapped()) SwapEndian<float>(f);
|
||||
_out.write((const char*)&f, sizeof(float));
|
||||
return *this;
|
||||
}
|
||||
|
||||
OutputStream& OutputStream::operator << (double d)
|
||||
{
|
||||
if (_swap) SwapEndian<double>(d);
|
||||
if (isSwapped()) SwapEndian<double>(d);
|
||||
_out.write((const char*)&d, sizeof(double));
|
||||
return *this;
|
||||
}
|
||||
@@ -163,56 +161,56 @@ InputStream& InputStream::operator >> (uint8_t& uch)
|
||||
InputStream& InputStream::operator >> (int16_t& s)
|
||||
{
|
||||
_in.read((char*)&s, sizeof(int16_t));
|
||||
if (_swap) SwapEndian<int16_t>(s);
|
||||
if (isSwapped()) SwapEndian<int16_t>(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
InputStream& InputStream::operator >> (uint16_t& us)
|
||||
{
|
||||
_in.read((char*)&us, sizeof(uint16_t));
|
||||
if (_swap) SwapEndian<uint16_t>(us);
|
||||
if (isSwapped()) SwapEndian<uint16_t>(us);
|
||||
return *this;
|
||||
}
|
||||
|
||||
InputStream& InputStream::operator >> (int32_t& i)
|
||||
{
|
||||
_in.read((char*)&i, sizeof(int32_t));
|
||||
if (_swap) SwapEndian<int32_t>(i);
|
||||
if (isSwapped()) SwapEndian<int32_t>(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
InputStream& InputStream::operator >> (uint32_t& ui)
|
||||
{
|
||||
_in.read((char*)&ui, sizeof(uint32_t));
|
||||
if (_swap) SwapEndian<uint32_t>(ui);
|
||||
if (isSwapped()) SwapEndian<uint32_t>(ui);
|
||||
return *this;
|
||||
}
|
||||
|
||||
InputStream& InputStream::operator >> (int64_t& l)
|
||||
{
|
||||
_in.read((char*)&l, sizeof(int64_t));
|
||||
if (_swap) SwapEndian<int64_t>(l);
|
||||
if (isSwapped()) SwapEndian<int64_t>(l);
|
||||
return *this;
|
||||
}
|
||||
|
||||
InputStream& InputStream::operator >> (uint64_t& ul)
|
||||
{
|
||||
_in.read((char*)&ul, sizeof(uint64_t));
|
||||
if (_swap) SwapEndian<uint64_t>(ul);
|
||||
if (isSwapped()) SwapEndian<uint64_t>(ul);
|
||||
return *this;
|
||||
}
|
||||
|
||||
InputStream& InputStream::operator >> (float& f)
|
||||
{
|
||||
_in.read((char*)&f, sizeof(float));
|
||||
if (_swap) SwapEndian<float>(f);
|
||||
if (isSwapped()) SwapEndian<float>(f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
InputStream& InputStream::operator >> (double& d)
|
||||
{
|
||||
_in.read((char*)&d, sizeof(double));
|
||||
if (_swap) SwapEndian<double>(d);
|
||||
if (isSwapped()) SwapEndian<double>(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -284,11 +282,12 @@ ByteArrayOStreambuf::seekpos(std::streambuf::pos_type pos,
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
ByteArrayIStreambuf::ByteArrayIStreambuf(const QByteArray& data) : _buffer(data)
|
||||
ByteArrayIStreambuf::ByteArrayIStreambuf(const QByteArray& data)
|
||||
: _buffer(data)
|
||||
, _beg(0)
|
||||
, _end(data.size())
|
||||
, _cur(0)
|
||||
{
|
||||
_beg = 0;
|
||||
_end = data.size();
|
||||
_cur = 0;
|
||||
}
|
||||
|
||||
ByteArrayIStreambuf::~ByteArrayIStreambuf() = default;
|
||||
@@ -416,7 +415,7 @@ IODeviceOStreambuf::seekpos(std::streambuf::pos_type pos,
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
IODeviceIStreambuf::IODeviceIStreambuf(QIODevice* dev) : device(dev), buffer{}
|
||||
IODeviceIStreambuf::IODeviceIStreambuf(QIODevice* dev) : device(dev)
|
||||
{
|
||||
setg (buffer+pbSize, // beginning of putback area
|
||||
buffer+pbSize, // read position
|
||||
@@ -441,7 +440,7 @@ using std::memcpy;
|
||||
* - use number of characters read
|
||||
* - but at most size of putback area
|
||||
*/
|
||||
int numPutback;
|
||||
int numPutback{};
|
||||
numPutback = gptr() - eback();
|
||||
if (numPutback > pbSize) {
|
||||
numPutback = pbSize;
|
||||
@@ -454,7 +453,7 @@ using std::memcpy;
|
||||
numPutback);
|
||||
|
||||
// read at most bufSize new characters
|
||||
int num;
|
||||
int num{};
|
||||
num = device->read(buffer+pbSize, bufSize);
|
||||
if (num <= 0) {
|
||||
// ERROR or EOF
|
||||
@@ -488,7 +487,7 @@ IODeviceIStreambuf::seekoff(std::streambuf::off_type off,
|
||||
endpos = device->size();
|
||||
break;
|
||||
default:
|
||||
return pos_type(off_type(-1));
|
||||
return {off_type(-1)};
|
||||
}
|
||||
|
||||
if (endpos != curpos) {
|
||||
@@ -514,7 +513,6 @@ IODeviceIStreambuf::seekpos(std::streambuf::pos_type pos,
|
||||
// http://www.icce.rug.nl/documents/cplusplus/cplusplus24.html
|
||||
PyStreambuf::PyStreambuf(PyObject* o, std::size_t buf_size, std::size_t put_back)
|
||||
: inp(o)
|
||||
, type(Unknown)
|
||||
, put_back(std::max(put_back, std::size_t(1)))
|
||||
, buffer(std::max(buf_size, put_back) + put_back)
|
||||
{
|
||||
@@ -529,7 +527,7 @@ PyStreambuf::PyStreambuf(PyObject* o, std::size_t buf_size, std::size_t put_back
|
||||
|
||||
PyStreambuf::~PyStreambuf()
|
||||
{
|
||||
sync();
|
||||
PyStreambuf::sync();
|
||||
Py_DECREF(inp);
|
||||
}
|
||||
|
||||
@@ -547,7 +545,7 @@ PyStreambuf::int_type PyStreambuf::underflow()
|
||||
start += put_back;
|
||||
}
|
||||
|
||||
std::size_t n;
|
||||
std::size_t n{};
|
||||
Py::Tuple arg(1);
|
||||
long len = static_cast<long>(buffer.size() - (start - base));
|
||||
arg.setItem(0, Py::Long(len));
|
||||
@@ -731,7 +729,7 @@ Streambuf::Streambuf(const std::string& data)
|
||||
{
|
||||
_beg = data.begin();
|
||||
_end = data.end();
|
||||
_cur = _beg;
|
||||
_cur = _beg; //NOLINT
|
||||
}
|
||||
|
||||
Streambuf::~Streambuf() = default;
|
||||
|
||||
Reference in New Issue
Block a user