mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 04:17:55 +01:00
Merge branch 'poco-1.10.0' into devel
This commit is contained in:
@@ -29,7 +29,7 @@ namespace Poco {
|
||||
|
||||
template <class T>
|
||||
class Buffer
|
||||
/// A buffer class that allocates a buffer of a given type and size
|
||||
/// A buffer class that allocates a buffer of a given type and size
|
||||
/// in the constructor and deallocates the buffer in the destructor.
|
||||
///
|
||||
/// This class is useful everywhere where a temporary buffer
|
||||
@@ -57,8 +57,8 @@ public:
|
||||
/// Creates the Buffer. Length argument specifies the length
|
||||
/// of the supplied memory pointed to by pMem in the number
|
||||
/// of elements of type T. Supplied pointer is considered
|
||||
/// blank and not owned by Buffer, so in this case Buffer
|
||||
/// only acts as a wrapper around externally supplied
|
||||
/// blank and not owned by Buffer, so in this case Buffer
|
||||
/// only acts as a wrapper around externally supplied
|
||||
/// (and lifetime-managed) memory.
|
||||
{
|
||||
}
|
||||
@@ -94,8 +94,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
Buffer(Buffer&& other) :
|
||||
/// Copy constructor.
|
||||
Buffer(Buffer&& other) noexcept:
|
||||
/// Move constructor.
|
||||
_capacity(other._capacity),
|
||||
_used(other._used),
|
||||
_ptr(other._ptr),
|
||||
@@ -119,21 +119,20 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
Buffer& operator = (Buffer&& other)
|
||||
/// Assignment operator.
|
||||
Buffer& operator = (Buffer&& other) noexcept
|
||||
/// Move assignment operator.
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
_capacity = other._capacity;
|
||||
_used = other._used;
|
||||
_ptr = other._ptr;
|
||||
_ownMem = other._ownMem;
|
||||
if (_ownMem) delete [] _ptr;
|
||||
|
||||
other._capacity = 0;
|
||||
other._used = 0;
|
||||
other._ownMem = false;
|
||||
other._ptr = nullptr;
|
||||
}
|
||||
_capacity = other._capacity;
|
||||
_used = other._used;
|
||||
_ptr = other._ptr;
|
||||
_ownMem = other._ownMem;
|
||||
|
||||
other._capacity = 0;
|
||||
other._used = 0;
|
||||
other._ownMem = false;
|
||||
other._ptr = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -143,15 +142,15 @@ public:
|
||||
{
|
||||
if (_ownMem) delete [] _ptr;
|
||||
}
|
||||
|
||||
|
||||
void resize(std::size_t newCapacity, bool preserveContent = true)
|
||||
/// Resizes the buffer capacity and size. If preserveContent is true,
|
||||
/// the content of the old buffer is copied over to the
|
||||
/// new buffer. The new capacity can be larger or smaller than
|
||||
/// the current one; if it is smaller, capacity will remain intact.
|
||||
/// Size will always be set to the new capacity.
|
||||
///
|
||||
/// Buffers only wrapping externally owned storage can not be
|
||||
///
|
||||
/// Buffers only wrapping externally owned storage can not be
|
||||
/// resized. If resize is attempted on those, IllegalAccessException
|
||||
/// is thrown.
|
||||
{
|
||||
@@ -168,19 +167,19 @@ public:
|
||||
_ptr = ptr;
|
||||
_capacity = newCapacity;
|
||||
}
|
||||
|
||||
|
||||
_used = newCapacity;
|
||||
}
|
||||
|
||||
|
||||
void setCapacity(std::size_t newCapacity, bool preserveContent = true)
|
||||
/// Sets the buffer capacity. If preserveContent is true,
|
||||
/// the content of the old buffer is copied over to the
|
||||
/// new buffer. The new capacity can be larger or smaller than
|
||||
/// the current one; size will be set to the new capacity only if
|
||||
/// the current one; size will be set to the new capacity only if
|
||||
/// new capacity is smaller than the current size, otherwise it will
|
||||
/// remain intact.
|
||||
///
|
||||
/// Buffers only wrapping externally owned storage can not be
|
||||
///
|
||||
/// Buffers only wrapping externally owned storage can not be
|
||||
/// resized. If resize is attempted on those, IllegalAccessException
|
||||
/// is thrown.
|
||||
{
|
||||
@@ -301,13 +300,13 @@ public:
|
||||
{
|
||||
return _used * sizeof(T);
|
||||
}
|
||||
|
||||
|
||||
T* begin()
|
||||
/// Returns a pointer to the beginning of the buffer.
|
||||
{
|
||||
return _ptr;
|
||||
}
|
||||
|
||||
|
||||
const T* begin() const
|
||||
/// Returns a pointer to the beginning of the buffer.
|
||||
{
|
||||
@@ -319,13 +318,13 @@ public:
|
||||
{
|
||||
return _ptr + _used;
|
||||
}
|
||||
|
||||
|
||||
const T* end() const
|
||||
/// Returns a pointer to the end of the buffer.
|
||||
{
|
||||
return _ptr + _used;
|
||||
}
|
||||
|
||||
|
||||
bool empty() const
|
||||
/// Return true if buffer is empty.
|
||||
{
|
||||
@@ -335,14 +334,14 @@ public:
|
||||
T& operator [] (std::size_t index)
|
||||
{
|
||||
poco_assert (index < _used);
|
||||
|
||||
|
||||
return _ptr[index];
|
||||
}
|
||||
|
||||
const T& operator [] (std::size_t index) const
|
||||
{
|
||||
poco_assert (index < _used);
|
||||
|
||||
|
||||
return _ptr[index];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user