|
|
|
@ -7,16 +7,16 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
|
|
KBuffer::KBuffer()
|
|
|
|
|
TDEBuffer::TDEBuffer()
|
|
|
|
|
{
|
|
|
|
|
bufPos = buf.end(); // will become 0 in the beginning
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KBuffer::~KBuffer(){
|
|
|
|
|
TDEBuffer::~TDEBuffer(){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** open a memory buffer */
|
|
|
|
|
bool KBuffer::open(int ) {
|
|
|
|
|
bool TDEBuffer::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
|
|
|
|
@ -25,24 +25,24 @@ bool KBuffer::open(int ) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Close buffer */
|
|
|
|
|
void KBuffer::close(){
|
|
|
|
|
void TDEBuffer::close(){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** No descriptions */
|
|
|
|
|
void KBuffer::flush(){
|
|
|
|
|
void TDEBuffer::flush(){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** query buffer size */
|
|
|
|
|
#ifdef USE_QT4
|
|
|
|
|
qint64 KBuffer::size() const {
|
|
|
|
|
qint64 TDEBuffer::size() const {
|
|
|
|
|
#else // USE_QT4
|
|
|
|
|
TQ_ULONG KBuffer::size() const {
|
|
|
|
|
TQ_ULONG TDEBuffer::size() const {
|
|
|
|
|
#endif // USE_QT4
|
|
|
|
|
return buf.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** read a block of memory from buffer, advances read/write position */
|
|
|
|
|
TQ_LONG KBuffer::readBlock(char* data, long unsigned int maxLen) {
|
|
|
|
|
TQ_LONG TDEBuffer::readBlock(char* data, long unsigned int maxLen) {
|
|
|
|
|
int len;
|
|
|
|
|
if ((long unsigned)(buf.end()-bufPos) > maxLen)
|
|
|
|
|
len = maxLen;
|
|
|
|
@ -56,7 +56,7 @@ TQ_LONG KBuffer::readBlock(char* data, long unsigned int maxLen) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** write a block of memory into buffer */
|
|
|
|
|
TQ_LONG KBuffer::writeBlock(const char *data, long unsigned int len){
|
|
|
|
|
TQ_LONG TDEBuffer::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;
|
|
|
|
@ -64,7 +64,7 @@ TQ_LONG KBuffer::writeBlock(const char *data, long unsigned int len){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** read a byte */
|
|
|
|
|
int KBuffer::getch() {
|
|
|
|
|
int TDEBuffer::getch() {
|
|
|
|
|
if (bufPos!=buf.end())
|
|
|
|
|
return *(bufPos++);
|
|
|
|
|
else
|
|
|
|
@ -72,7 +72,7 @@ int KBuffer::getch() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** write a byte */
|
|
|
|
|
int KBuffer::putch(int c) {
|
|
|
|
|
int TDEBuffer::putch(int c) {
|
|
|
|
|
int pos = bufPos-buf.begin();
|
|
|
|
|
buf.insert(bufPos, c);
|
|
|
|
|
bufPos = buf.begin() + pos + 1;
|
|
|
|
@ -81,7 +81,7 @@ int KBuffer::putch(int c) {
|
|
|
|
|
|
|
|
|
|
/** undo last getch()
|
|
|
|
|
*/
|
|
|
|
|
int KBuffer::ungetch(int c) {
|
|
|
|
|
int TDEBuffer::ungetch(int c) {
|
|
|
|
|
if (bufPos!=buf.begin()) {
|
|
|
|
|
bufPos--;
|
|
|
|
|
return c;
|
|
|
|
|