aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/Pl_Buffer.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2008-04-29 14:55:25 +0200
committerJay Berkenbilt <ejb@ql.org>2008-04-29 14:55:25 +0200
commit9a0b88bf7777c153dc46ace22db74ef24d51583a (patch)
treef567ac1cf2bf5071a611eb49323a935b6ac938ff /libqpdf/Pl_Buffer.cc
downloadqpdf-9a0b88bf7777c153dc46ace22db74ef24d51583a.tar.zst
update release date to actual daterelease-qpdf-2.0
git-svn-id: svn+q:///qpdf/trunk@599 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'libqpdf/Pl_Buffer.cc')
-rw-r--r--libqpdf/Pl_Buffer.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc
new file mode 100644
index 00000000..185cf636
--- /dev/null
+++ b/libqpdf/Pl_Buffer.cc
@@ -0,0 +1,67 @@
+
+#include <qpdf/Pl_Buffer.hh>
+#include <qpdf/QEXC.hh>
+#include <assert.h>
+
+Pl_Buffer::Pl_Buffer(char const* identifier, Pipeline* next) :
+ Pipeline(identifier, next),
+ ready(false),
+ total_size(0)
+{
+}
+
+Pl_Buffer::~Pl_Buffer()
+{
+}
+
+void
+Pl_Buffer::write(unsigned char* buf, int len)
+{
+ Buffer* b = new Buffer(len);
+ memcpy(b->getBuffer(), buf, len);
+ this->data.push_back(b);
+ this->ready = false;
+ this->total_size += len;
+
+ if (getNext(true))
+ {
+ getNext()->write(buf, len);
+ }
+}
+
+void
+Pl_Buffer::finish()
+{
+ this->ready = true;
+ if (getNext(true))
+ {
+ getNext()->finish();
+ }
+}
+
+Buffer*
+Pl_Buffer::getBuffer()
+{
+ if (! this->ready)
+ {
+ throw QEXC::Internal("Pl_Buffer::getBuffer() called when not ready");
+ }
+
+ Buffer* b = new Buffer(this->total_size);
+ unsigned char* p = b->getBuffer();
+ while (! this->data.empty())
+ {
+ PointerHolder<Buffer> bph = this->data.front();
+ this->data.pop_front();
+ Buffer* bp = bph.getPointer();
+ size_t bytes = bp->getSize();
+ memcpy(p, bp->getBuffer(), bytes);
+ p += bytes;
+ this->total_size -= bytes;
+ }
+
+ assert(this->total_size == 0);
+ this->ready = false;
+
+ return b;
+}