Mercurial > vba-clojure
diff src/win32/7zip/7z/CPP/Common/DynamicBuffer.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/Common/DynamicBuffer.h Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,47 @@ 1.4 +// Common/DynamicBuffer.h 1.5 + 1.6 +#ifndef __COMMON_DYNAMICBUFFER_H 1.7 +#define __COMMON_DYNAMICBUFFER_H 1.8 + 1.9 +#include "Buffer.h" 1.10 + 1.11 +template <class T> class CDynamicBuffer: public CBuffer<T> 1.12 +{ 1.13 + void GrowLength(size_t size) 1.14 + { 1.15 + size_t delta; 1.16 + if (this->_capacity > 64) 1.17 + delta = this->_capacity / 4; 1.18 + else if (this->_capacity > 8) 1.19 + delta = 16; 1.20 + else 1.21 + delta = 4; 1.22 + delta = MyMax(delta, size); 1.23 + SetCapacity(this->_capacity + delta); 1.24 + } 1.25 +public: 1.26 + CDynamicBuffer(): CBuffer<T>() {}; 1.27 + CDynamicBuffer(const CDynamicBuffer &buffer): CBuffer<T>(buffer) {}; 1.28 + CDynamicBuffer(size_t size): CBuffer<T>(size) {}; 1.29 + CDynamicBuffer& operator=(const CDynamicBuffer &buffer) 1.30 + { 1.31 + this->Free(); 1.32 + if (buffer._capacity > 0) 1.33 + { 1.34 + SetCapacity(buffer._capacity); 1.35 + memmove(this->_items, buffer._items, buffer._capacity * sizeof(T)); 1.36 + } 1.37 + return *this; 1.38 + } 1.39 + void EnsureCapacity(size_t capacity) 1.40 + { 1.41 + if (this->_capacity < capacity) 1.42 + GrowLength(capacity - this->_capacity); 1.43 + } 1.44 +}; 1.45 + 1.46 +typedef CDynamicBuffer<char> CCharDynamicBuffer; 1.47 +typedef CDynamicBuffer<wchar_t> CWCharDynamicBuffer; 1.48 +typedef CDynamicBuffer<unsigned char> CByteDynamicBuffer; 1.49 + 1.50 +#endif