32 #ifndef _QORE_TRANSFORMINPUTSTREAM_H 33 #define _QORE_TRANSFORMINPUTSTREAM_H 36 #include "qore/InputStream.h" 37 #include "qore/Transform.h" 44 inBufSize(t->inputBufferSize()),
45 outBufSize(t->outputBufferSize()),
46 buf(new char[inBufSize]),
47 outBuf(new char[outBufSize]) {
50 DLLLOCAL ~TransformInputStream() {
55 DLLLOCAL
const char *
getName()
override {
56 return "TransformInputStream";
60 if (outBufCount > 0) {
61 return readFromBuffer(ptr, limit);
64 if (!eof && inBufSize - bufCount > 0) {
65 int64 r = is->read(buf + bufCount, inBufSize - bufCount, xsink);
76 assert(eof || bufCount > 0);
79 std::pair<int64, int64> r = t->apply(bufCount ? buf :
nullptr, bufCount, outBuf, outBufSize, xsink);
86 memmove(buf, buf + r.first, bufCount);
89 outBufCount = r.second;
90 return readFromBuffer(ptr, limit);
103 return outBuf[outBufOffset];
104 int64 rc =
read(outBuf, outBufSize, xsink);
120 size_t outBufOffset = 0;
124 size_t outBufCount = 0;
127 DLLLOCAL
int64 readFromBuffer(
void *ptr,
int64 limit) {
129 int64 toCopy =
QORE_MIN(static_cast<int64>(outBufCount), limit);
130 memcpy(ptr, outBuf + outBufOffset, toCopy);
132 outBufCount -= toCopy;
136 outBufOffset += toCopy;
142 #endif // _QORE_TRANSFORMINPUTSTREAM_H
virtual DLLLOCAL const char * getName()=0
Returns the name of the class.
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
#define QORE_MIN(a, b)
macro to return the minimum of 2 numbers
Definition: QoreLib.h:535