author | llornkcor <llornkcor> | 2002-09-14 02:19:09 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-09-14 02:19:09 (UTC) |
commit | 2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975 (patch) (side-by-side diff) | |
tree | eeed16b5f80dd5883991a7a06133f5f7a6936256 /noncore/apps/opie-reader/CBuffer.cpp | |
parent | 5a95ed6a000a56849b8f093deea500214856c626 (diff) | |
download | opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.zip opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.gz opie-2d0c1ffcb39f9fac8193ed2e9e93794de0bd7975.tar.bz2 |
update by Tim
Diffstat (limited to 'noncore/apps/opie-reader/CBuffer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CBuffer.cpp | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/noncore/apps/opie-reader/CBuffer.cpp b/noncore/apps/opie-reader/CBuffer.cpp index db52476..526b25f 100644 --- a/noncore/apps/opie-reader/CBuffer.cpp +++ b/noncore/apps/opie-reader/CBuffer.cpp @@ -2,7 +2,10 @@ -CBuffer& CBuffer::operator=(const tchar*sztmp) +CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms) { - int i; - for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; - (*this)[i] = '\0'; + if (ms*membersize > len) + { + delete [] buffer; + buffer = new unsigned char[len = ms*membersize]; + } + memcpy(buffer, sztmp, ms*membersize); return *this; @@ -10,26 +13,34 @@ CBuffer& CBuffer::operator=(const tchar*sztmp) -tchar& CBuffer::operator[](int i) +CBufferBase::CBufferBase(size_t ms, size_t n = 16) : len(n), membersize(ms) +{ + buffer = new unsigned char[len*membersize]; + memset(buffer, 0, len*membersize); +} + +void* CBufferBase::operator[](int i) { - if (i >= len) + if ((i+1)*membersize > len) { - tchar *newbuff = new tchar[i+1]; - memcpy(newbuff,buffer,sizeof(tchar)*len); - delete [] buffer; - buffer = newbuff; - len = i+1; + unsigned char* oldbuffer = buffer; + buffer = new unsigned char[(i+1)*membersize]; + memcpy(buffer, oldbuffer, len); + memset(buffer+len, 0, (i+1)*membersize-len); + len = (i+1)*membersize; + delete [] oldbuffer; } - return buffer[i]; + return buffer+i*membersize; } -size_t& CSizeBuffer::operator[](int i) +size_t CBufferBase::bstrlen(unsigned char* _buffer = NULL) { - if (i >= len) + if (_buffer == NULL) _buffer = buffer; + unsigned char* zero = new unsigned char[membersize]; + memset(zero,0,membersize); + unsigned char* element = _buffer; + while (memcmp(element, zero, membersize) != 0) { - size_t *newbuff = new size_t[i+1]; - memcpy(newbuff,buffer,sizeof(size_t)*len); - delete [] buffer; - buffer = newbuff; - len = i+1; + element += membersize; } - return buffer[i]; + delete [] zero; + return (element - _buffer)/membersize; } |