2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-29 00:10:54 +00:00

Add getBufferSharedPointer() to Pl_Buffer and QPDFWriter

This commit is contained in:
Jay Berkenbilt 2022-02-06 12:30:18 -05:00
parent 3e98fe46a2
commit cfaae47dc6
6 changed files with 32 additions and 5 deletions

View File

@ -1,5 +1,9 @@
2022-02-06 Jay Berkenbilt <ejb@ql.org> 2022-02-06 Jay Berkenbilt <ejb@ql.org>
* Pl_Buffer and QPDFWriter: add getBufferSharedPointer(), which
turns a PointerHolder<Buffer> but will return a
std::shared_ptr<Buffer> in qpdf 11.
* From m-holger: add getKeyIfDict(), which calls getKey for * From m-holger: add getKeyIfDict(), which calls getKey for
dictionaries and returns null if called on null. This is for dictionaries and returns null if called on null. This is for
easier access to optional, lower-level dictionaries. easier access to optional, lower-level dictionaries.

2
TODO
View File

@ -420,6 +420,8 @@ auto x = std::make_unique<T[]>(5)
PointerHolder in public API: PointerHolder in public API:
PointerHolder<Buffer> Pl_Buffer::getBufferSharedPointer();
PointerHolder<Buffer> QPDFWriter::getBufferSharedPointer();
QUtil::read_file_into_memory( QUtil::read_file_into_memory(
char const*, PointerHolder<char>&, unsigned long&) char const*, PointerHolder<char>&, unsigned long&)
QPDFObjectHandle::addContentTokenFilter( QPDFObjectHandle::addContentTokenFilter(

View File

@ -51,10 +51,14 @@ class Pl_Buffer: public Pipeline
// Each call to getBuffer() resets this object -- see notes above. // Each call to getBuffer() resets this object -- see notes above.
// The caller is responsible for deleting the returned Buffer // The caller is responsible for deleting the returned Buffer
// object. // object. See also getBufferSharedPointer() and getMallocBuffer().
QPDF_DLL QPDF_DLL
Buffer* getBuffer(); Buffer* getBuffer();
// Same as getBuffer but wraps the result in a shared pointer.
QPDF_DLL
PointerHolder<Buffer> getBufferSharedPointer();
// getMallocBuffer behaves in the same was as getBuffer except the // getMallocBuffer behaves in the same was as getBuffer except the
// buffer is allocated with malloc(), making it suitable for use // buffer is allocated with malloc(), making it suitable for use
// when calling from other languages. If there is no data, *buf is // when calling from other languages. If there is no data, *buf is

View File

@ -118,13 +118,18 @@ class QPDFWriter
QPDF_DLL QPDF_DLL
void setOutputMemory(); void setOutputMemory();
// Return the buffer object containing the PDF file. If // Return the buffer object containing the PDF file. If
// setOutputMemory() has been called, this method may be called // setOutputMemory() has been called, this method may be called
// exactly one time after write() has returned. The caller is // exactly one time after write() has returned. The caller is
// responsible for deleting the buffer when done. // responsible for deleting the buffer when done. See also
// getBufferSharedPointer().
QPDF_DLL QPDF_DLL
Buffer* getBuffer(); Buffer* getBuffer();
// Return getBuffer() in a shared pointer.
QPDF_DLL
PointerHolder<Buffer> getBufferSharedPointer();
// Supply your own pipeline object. Output will be written to // Supply your own pipeline object. Output will be written to
// this pipeline, and QPDFWriter will call finish() on the // this pipeline, and QPDFWriter will call finish() on the
// pipeline. It is the caller's responsibility to manage the // pipeline. It is the caller's responsibility to manage the

View File

@ -79,10 +79,16 @@ Pl_Buffer::getBuffer()
unsigned char* p = b->getBuffer(); unsigned char* p = b->getBuffer();
memcpy(p, this->m->data->getBuffer(), this->m->total_size); memcpy(p, this->m->data->getBuffer(), this->m->total_size);
} }
this->m = new Members(); this->m = PointerHolder<Members>(new Members());
return b; return b;
} }
PointerHolder<Buffer>
Pl_Buffer::getBufferSharedPointer()
{
return PointerHolder<Buffer>(getBuffer());
}
void void
Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len) Pl_Buffer::getMallocBuffer(unsigned char **buf, size_t* len)
{ {

View File

@ -157,6 +157,12 @@ QPDFWriter::getBuffer()
return result; return result;
} }
PointerHolder<Buffer>
QPDFWriter::getBufferSharedPointer()
{
return PointerHolder<Buffer>(getBuffer());
}
void void
QPDFWriter::setOutputPipeline(Pipeline* p) QPDFWriter::setOutputPipeline(Pipeline* p)
{ {