diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch) | |
tree | 2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /noatun-plugins/oblique/kbuffer.cpp | |
download | tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'noatun-plugins/oblique/kbuffer.cpp')
-rw-r--r-- | noatun-plugins/oblique/kbuffer.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/noatun-plugins/oblique/kbuffer.cpp b/noatun-plugins/oblique/kbuffer.cpp new file mode 100644 index 0000000..f54110e --- /dev/null +++ b/noatun-plugins/oblique/kbuffer.cpp @@ -0,0 +1,87 @@ +// Author: Eray Ozkural (exa) <erayo@cs.bilkent.edu.tr>, (c) 2002 +// +// Copyright: GNU LGPL: http://www.gnu.org/licenses/lgpl.html + +#include "kbuffer.h" +#include <algorithm> +#include <iostream> +#include <iomanip> + +KBuffer::KBuffer() +{ + bufPos = buf.end(); // will become 0 in the beginning +} + +KBuffer::~KBuffer(){ +} + +/** open a memory buffer */ +bool KBuffer::open(int ) { + // ignore mode + buf.erase(buf.begin(), buf.end()); // erase buffer + buf.reserve(8); // prevent iterators from ever being 0 and start with a reasonable mem + bufPos = buf.end(); // reset position + return true; +} + +/** Close buffer */ +void KBuffer::close(){ +} + +/** No descriptions */ +void KBuffer::flush(){ +} + +/** query buffer size */ +Q_ULONG KBuffer::size() const { + return buf.size(); +} + +/** read a block of memory from buffer, advances read/write position */ +Q_LONG KBuffer::readBlock(char* data, long unsigned int maxLen) { + int len; + if ((long unsigned)(buf.end()-bufPos) > maxLen) + len = maxLen; + else + len = buf.end()-bufPos; + std::vector<char>::iterator bufPosNew = bufPos + len; + for (std::vector<char>::iterator it=bufPos; it < bufPosNew; it++, data++) + *data = *it; + bufPos = bufPosNew; + return len; +} + +/** write a block of memory into buffer */ +Q_LONG KBuffer::writeBlock(const char *data, long unsigned int len){ + int pos = bufPos-buf.begin(); + copy(data, data+len, inserter(buf,bufPos)); + bufPos = buf.begin() + pos + len; + return len; +} + +/** read a byte */ +int KBuffer::getch() { + if (bufPos!=buf.end()) + return *(bufPos++); + else + return -1; +} + +/** write a byte */ +int KBuffer::putch(int c) { + int pos = bufPos-buf.begin(); + buf.insert(bufPos, c); + bufPos = buf.begin() + pos + 1; + return c; +} + +/** undo last getch() + */ +int KBuffer::ungetch(int c) { + if (bufPos!=buf.begin()) { + bufPos--; + return c; + } + else + return -1; +} |