You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by th...@apache.org on 2021/04/03 04:29:21 UTC
[avro] branch master updated: Legacy C++ code modernized (#1170)
This is an automated email from the ASF dual-hosted git repository.
thiru pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new c4168a0 Legacy C++ code modernized (#1170)
c4168a0 is described below
commit c4168a0c0eccca5f117e2cc98e283fa73fe4ea91
Author: Thiruvalluvan M G <th...@apache.org>
AuthorDate: Sat Apr 3 09:59:11 2021 +0530
Legacy C++ code modernized (#1170)
---
lang/c++/api/buffer/Buffer.hh | 7 ++--
lang/c++/api/buffer/BufferPrint.hh | 2 +-
lang/c++/api/buffer/BufferReader.hh | 28 ++++++++--------
lang/c++/api/buffer/BufferStream.hh | 4 +--
lang/c++/api/buffer/BufferStreambuf.hh | 30 +++++++++--------
lang/c++/api/buffer/detail/BufferDetail.hh | 38 +++++++++-------------
lang/c++/api/buffer/detail/BufferDetail.hh.rej | 12 -------
lang/c++/api/buffer/detail/BufferDetailIterator.hh | 4 +--
8 files changed, 54 insertions(+), 71 deletions(-)
diff --git a/lang/c++/api/buffer/Buffer.hh b/lang/c++/api/buffer/Buffer.hh
index 48e6bdb..bc3baf1 100644
--- a/lang/c++/api/buffer/Buffer.hh
+++ b/lang/c++/api/buffer/Buffer.hh
@@ -22,6 +22,7 @@
#ifndef _WIN32
#include <sys/uio.h>
#endif
+#include <utility>
#include <vector>
#include "../Config.hh"
@@ -92,7 +93,7 @@ public:
*
**/
- OutputBuffer(size_type reserveSize = 0) : pimpl_(new detail::BufferImpl) {
+ explicit OutputBuffer(size_type reserveSize = 0) : pimpl_(new detail::BufferImpl) {
if (reserveSize) {
reserve(reserveSize);
}
@@ -291,7 +292,7 @@ private:
friend class InputBuffer;
friend class BufferReader;
- explicit OutputBuffer(const detail::BufferImpl::SharedPtr &pimpl) : pimpl_(pimpl) {}
+ explicit OutputBuffer(detail::BufferImpl::SharedPtr pimpl) : pimpl_(std::move(pimpl)) {}
detail::BufferImpl::SharedPtr pimpl_; ///< Must never be null.
};
@@ -343,7 +344,7 @@ public:
*
* Implicit conversion is allowed.
**/
-
+ // NOLINTNEXTLINE(google-explicit-constructor)
InputBuffer(const OutputBuffer &src) : pimpl_(new detail::BufferImpl(*src.pimpl_)) {}
/**
diff --git a/lang/c++/api/buffer/BufferPrint.hh b/lang/c++/api/buffer/BufferPrint.hh
index 3262ec9..c8eb15b 100644
--- a/lang/c++/api/buffer/BufferPrint.hh
+++ b/lang/c++/api/buffer/BufferPrint.hh
@@ -20,7 +20,7 @@
#define avro_BufferPrint_hh__
#include "BufferReader.hh"
-#include <ctype.h>
+#include <cctype>
#include <iomanip>
#include <iostream>
diff --git a/lang/c++/api/buffer/BufferReader.hh b/lang/c++/api/buffer/BufferReader.hh
index c3acc26..7f49518 100644
--- a/lang/c++/api/buffer/BufferReader.hh
+++ b/lang/c++/api/buffer/BufferReader.hh
@@ -51,9 +51,9 @@ private:
return iter_->dataSize() - chunkPos_;
}
- void incrementChunk(size_type howmuch) {
- bytesRemaining_ -= howmuch;
- chunkPos_ += howmuch;
+ void incrementChunk(size_type howMuch) {
+ bytesRemaining_ -= howMuch;
+ chunkPos_ += howMuch;
if (chunkPos_ == iter_->dataSize()) {
chunkPos_ = 0;
++iter_;
@@ -71,17 +71,17 @@ private:
}
public:
- BufferReader(const InputBuffer &buf) : bufferImpl_(buf.pimpl_),
- iter_(bufferImpl_->beginRead()),
- bytes_(bufferImpl_->size()),
- bytesRemaining_(bytes_),
- chunkPos_(0) {}
-
- BufferReader(const OutputBuffer &buf) : bufferImpl_(buf.pimpl_),
- iter_(bufferImpl_->beginRead()),
- bytes_(bufferImpl_->size()),
- bytesRemaining_(bytes_),
- chunkPos_(0) {}
+ explicit BufferReader(const InputBuffer &buf) : bufferImpl_(buf.pimpl_),
+ iter_(bufferImpl_->beginRead()),
+ bytes_(bufferImpl_->size()),
+ bytesRemaining_(bytes_),
+ chunkPos_(0) {}
+
+ explicit BufferReader(const OutputBuffer &buf) : bufferImpl_(buf.pimpl_),
+ iter_(bufferImpl_->beginRead()),
+ bytes_(bufferImpl_->size()),
+ bytesRemaining_(bytes_),
+ chunkPos_(0) {}
/**
* How many bytes are still not read from this buffer.
diff --git a/lang/c++/api/buffer/BufferStream.hh b/lang/c++/api/buffer/BufferStream.hh
index 341822d..a8510ad 100644
--- a/lang/c++/api/buffer/BufferStream.hh
+++ b/lang/c++/api/buffer/BufferStream.hh
@@ -42,8 +42,8 @@ public:
ostream() : std::ostream(&obuf_) {}
/// Output to a specific buffer.
- ostream(OutputBuffer &buf) : std::ostream(&obuf_),
- obuf_(buf) {}
+ explicit ostream(OutputBuffer &buf) : std::ostream(&obuf_),
+ obuf_(buf) {}
/// Return the output buffer created by the write operations to this ostream.
const OutputBuffer &getBuffer() const {
diff --git a/lang/c++/api/buffer/BufferStreambuf.hh b/lang/c++/api/buffer/BufferStreambuf.hh
index 476262e..2b7aea4 100644
--- a/lang/c++/api/buffer/BufferStreambuf.hh
+++ b/lang/c++/api/buffer/BufferStreambuf.hh
@@ -19,6 +19,8 @@
#ifndef avro_BufferStreambuf_hh__
#define avro_BufferStreambuf_hh__
+#include <utility>
+
#include "Buffer.hh"
/** \file BufferStreambuf.hh
@@ -57,13 +59,13 @@ public:
protected:
/// Write a single character to the stream.
- virtual int_type overflow(int_type c) {
+ int_type overflow(int_type c) override {
buffer_.writeTo(static_cast<OutputBuffer::data_type>(c));
return c;
}
/// Write a block of characters to the stream.
- virtual std::streamsize xsputn(const char_type *s, std::streamsize n) {
+ std::streamsize xsputn(const char_type *s, std::streamsize n) override {
return buffer_.writeTo(s, static_cast<size_t>(n));
}
@@ -88,10 +90,10 @@ class AVRO_DECL istreambuf : public std::streambuf {
public:
/// Default constructor requires an InputBuffer to read from.
- explicit istreambuf(const InputBuffer &buffer) : std::streambuf(),
- buffer_(buffer),
- basePos_(0),
- iter_(buffer_.begin()) {
+ explicit istreambuf(InputBuffer buffer) : std::streambuf(),
+ buffer_(std::move(buffer)),
+ basePos_(0),
+ iter_(buffer_.begin()) {
setBuffer();
}
@@ -110,7 +112,7 @@ public:
protected:
/// The current chunk of data is exhausted, read the next chunk.
- virtual int_type underflow() {
+ int_type underflow() override {
if (iter_ != buffer_.end()) {
basePos_ += (egptr() - eback());
++iter_;
@@ -120,7 +122,7 @@ protected:
/// Get a block of data from the stream. Overrides default behavior
/// to ignore eof characters that may reside in the stream.
- virtual std::streamsize xsgetn(char_type *c, std::streamsize len) {
+ std::streamsize xsgetn(char_type *c, std::streamsize len) override {
std::streamsize bytesCopied = 0;
while (bytesCopied < len) {
@@ -128,7 +130,7 @@ protected:
size_t inBuffer = egptr() - gptr();
if (inBuffer) {
- size_t remaining = static_cast<size_t>(len - bytesCopied);
+ auto remaining = static_cast<size_t>(len - bytesCopied);
size_t toCopy = std::min(inBuffer, remaining);
memcpy(c, gptr(), toCopy);
c += toCopy;
@@ -148,7 +150,7 @@ protected:
}
/// Special seek override to navigate InputBuffer chunks.
- virtual pos_type seekoff(off_type off, std::ios::seekdir dir, std::ios_base::openmode) {
+ pos_type seekoff(off_type off, std::ios::seekdir dir, std::ios_base::openmode) override {
off_type curpos = basePos_ + (gptr() - eback());
off_type newpos = off;
@@ -168,7 +170,7 @@ protected:
// if the position is after our current buffer make
// sure it's not past the end of the buffer
if ((newpos > endpos) && (newpos > static_cast<off_type>(buffer_.size()))) {
- return pos_type(-1);
+ return {-1};
}
// if the new position is before our current iterator
// reset the iterator to the beginning
@@ -191,13 +193,13 @@ protected:
}
/// Calls seekoff for implemention.
- virtual pos_type seekpos(pos_type pos, std::ios_base::openmode) {
+ pos_type seekpos(pos_type pos, std::ios_base::openmode) override {
return istreambuf::seekoff(pos, std::ios::beg, std::ios_base::openmode(0));
}
/// Shows the number of bytes buffered in the current chunk, or next chunk if
/// current is exhausted.
- virtual std::streamsize showmanyc() {
+ std::streamsize showmanyc() override {
// this function only gets called when the current buffer has been
// completely read, verify this is the case, and if so, underflow to
@@ -221,7 +223,7 @@ private:
setg(loc, loc, loc + iter_->size());
ret = std::char_traits<char>::to_int_type(*gptr());
} else {
- setg(0, 0, 0);
+ setg(nullptr, nullptr, nullptr);
}
return ret;
}
diff --git a/lang/c++/api/buffer/detail/BufferDetail.hh b/lang/c++/api/buffer/detail/BufferDetail.hh
index 22cca95..b487cdb 100644
--- a/lang/c++/api/buffer/detail/BufferDetail.hh
+++ b/lang/c++/api/buffer/detail/BufferDetail.hh
@@ -24,6 +24,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/static_assert.hpp>
#include <boost/utility.hpp>
+#include <utility>
#ifdef HAVE_BOOST_ASIO
#include <boost/asio/buffer.hpp>
#endif
@@ -61,7 +62,7 @@ typedef boost::function<void(void)> free_func;
**/
class CallOnDestroy {
public:
- CallOnDestroy(const free_func &func) : func_(func) {}
+ explicit CallOnDestroy(free_func func) : func_(std::move(func)) {}
~CallOnDestroy() {
if (func_) {
func_();
@@ -92,13 +93,11 @@ private:
class Chunk {
public:
- typedef boost::shared_ptr<Chunk> SharedPtr;
-
/// Default constructor, allocates a new underlying block for this chunk.
- Chunk(size_type size) : underlyingBlock_(new data_type[size]),
- readPos_(underlyingBlock_.get()),
- writePos_(readPos_),
- endPos_(readPos_ + size) {}
+ explicit Chunk(size_type size) : underlyingBlock_(new data_type[size]),
+ readPos_(underlyingBlock_.get()),
+ writePos_(readPos_),
+ endPos_(readPos_ + size) {}
/// Foreign buffer constructor, uses the supplied data for this chunk, and
/// only for reading.
@@ -283,9 +282,9 @@ public:
size_(0) {}
/// Copy constructor, gets a copy of all the chunks with data.
- explicit BufferImpl(const BufferImpl &src) : readChunks_(src.readChunks_),
- freeSpace_(0),
- size_(src.size_) {}
+ BufferImpl(const BufferImpl &src) : readChunks_(src.readChunks_),
+ freeSpace_(0),
+ size_(src.size_) {}
/// Amount of data held in this buffer.
size_type size() const {
@@ -343,7 +342,7 @@ public:
/// An uninstantiable function, this is if boost::is_fundamental check fails,
/// and will compile-time assert.
template<typename T>
- void writeTo(T val, const std::false_type &) {
+ void writeTo(T /*val*/, const std::false_type &) {
BOOST_STATIC_ASSERT(sizeof(T) == 0);
}
@@ -453,10 +452,10 @@ public:
/// Copy data to a different buffer by copying the chunks. It's
/// a bit like extract, but without modifying the source buffer.
- void copyData(BufferImpl &dest,
- ChunkList::const_iterator iter,
- size_type offset,
- size_type bytes) const {
+ static void copyData(BufferImpl &dest,
+ ChunkList::const_iterator iter,
+ size_type offset,
+ size_type bytes) {
// now we are positioned to start the copying, copy as many
// chunks as we need, the first chunk may have a non-zero offset
// if the data to copy is not at the start of the chunk
@@ -499,16 +498,9 @@ public:
readChunks_.push_back(Chunk(data, size, func));
size_ += size;
}
+ BufferImpl &operator=(const BufferImpl &src) = delete;
private:
- /// Assignment not allowed
- BufferImpl &operator=(const BufferImpl &src);
- /* {
- readChunks_.assign(src.readChunks_.begin(), src.readChunks_.end());
- size_ = src.size();
- return *this;
- } */
-
ChunkList readChunks_; ///< chunks of this buffer containing data
ChunkList writeChunks_; ///< chunks of this buffer containing free space
diff --git a/lang/c++/api/buffer/detail/BufferDetail.hh.rej b/lang/c++/api/buffer/detail/BufferDetail.hh.rej
deleted file mode 100644
index 5f2fa85..0000000
--- a/lang/c++/api/buffer/detail/BufferDetail.hh.rej
+++ /dev/null
@@ -1,12 +0,0 @@
-******************301, 306 * ***
-
- /// Copy constructor, gets a copy of all the chunks with data.
- explicit BufferImpl(const BufferImpl &src) : readChunks_(src.readChunks_),
-freeSpace_(0),
-size_(src.size_)-- - 301, 307 ----
-
- /// Copy constructor, gets a copy of all the chunks with data.
- explicit BufferImpl(const BufferImpl &src) : +boost::noncopyable(),
- readChunks_(src.readChunks_),
- freeSpace_(0),
- size_(src.size_)
diff --git a/lang/c++/api/buffer/detail/BufferDetailIterator.hh b/lang/c++/api/buffer/detail/BufferDetailIterator.hh
index 2fc2794..44e35dd 100644
--- a/lang/c++/api/buffer/detail/BufferDetailIterator.hh
+++ b/lang/c++/api/buffer/detail/BufferDetailIterator.hh
@@ -45,7 +45,7 @@ struct InputIteratorHelper {
InputIteratorHelper() : iter_() {}
/// Construct a helper with an iterator.
- InputIteratorHelper(const BufferImpl::ChunkList::const_iterator &iter) : iter_(iter) {}
+ explicit InputIteratorHelper(const BufferImpl::ChunkList::const_iterator &iter) : iter_(iter) {}
/// The location of valid data in this chunk.
const data_type *data() const {
@@ -83,7 +83,7 @@ struct OutputIteratorHelper {
OutputIteratorHelper() : iter_() {}
/// Construct a helper with an iterator.
- OutputIteratorHelper(const BufferImpl::ChunkList::const_iterator &iter) : iter_(iter) {}
+ explicit OutputIteratorHelper(const BufferImpl::ChunkList::const_iterator &iter) : iter_(iter) {}
/// The location of the first writable byte in this chunk.
data_type *data() const {