mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-11 00:07:09 -06:00
3.13
This commit is contained in:
49
Common/DynamicBuffer.h
Executable file
49
Common/DynamicBuffer.h
Executable file
@@ -0,0 +1,49 @@
|
||||
// Common/DynamicBuffer.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __COMMON_DYNAMICBUFFER_H
|
||||
#define __COMMON_DYNAMICBUFFER_H
|
||||
|
||||
#include "Buffer.h"
|
||||
|
||||
template <class T> class CDynamicBuffer: public CBuffer<T>
|
||||
{
|
||||
void GrowLength(size_t size)
|
||||
{
|
||||
size_t delta;
|
||||
if (_capacity > 64)
|
||||
delta = _capacity / 4;
|
||||
else if (_capacity > 8)
|
||||
delta = 16;
|
||||
else
|
||||
delta = 4;
|
||||
delta = MyMax(delta, size);
|
||||
SetCapacity(_capacity + delta);
|
||||
}
|
||||
public:
|
||||
CDynamicBuffer(): CBuffer<T>() {};
|
||||
CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {};
|
||||
CDynamicBuffer(size_t size): CBuffer<T>(size) {};
|
||||
CDynamicBuffer& operator=(const CDynamicBuffer &buffer)
|
||||
{
|
||||
Free();
|
||||
if(buffer._capacity > 0)
|
||||
{
|
||||
SetCapacity(buffer._capacity);
|
||||
memmove(_items, buffer._items, buffer._capacity * sizeof(T));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
void EnsureCapacity(size_t capacity)
|
||||
{
|
||||
if (_capacity < capacity)
|
||||
GrowLength(capacity - _capacity);
|
||||
}
|
||||
};
|
||||
|
||||
typedef CDynamicBuffer<char> CCharDynamicBuffer;
|
||||
typedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer;
|
||||
typedef CDynamicBuffer<unsigned char> CByteDynamicBuffer;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user