Remove ClosedFileInputSource::Members

This commit is contained in:
m-holger 2022-08-25 14:23:53 +01:00
parent 69a5fb7047
commit d6a447b654
2 changed files with 24 additions and 43 deletions

View File

@ -73,23 +73,10 @@ class QPDF_DLL_CLASS ClosedFileInputSource: public InputSource
QPDF_DLL_PRIVATE
void after();
class QPDF_DLL_PRIVATE Members
{
friend class ClosedFileInputSource;
public:
QPDF_DLL
~Members() = default;
private:
Members(char const* filename);
std::string filename;
qpdf_offset_t offset;
std::shared_ptr<FileInputSource> fis;
bool stay_open;
};
std::shared_ptr<Members> m;
std::string filename;
qpdf_offset_t offset;
std::shared_ptr<FileInputSource> fis;
bool stay_open;
};
#endif // QPDF_CLOSEDFILEINPUTSOURCE_HH

View File

@ -2,18 +2,13 @@
#include <qpdf/FileInputSource.hh>
ClosedFileInputSource::Members::Members(char const* filename) :
ClosedFileInputSource::ClosedFileInputSource(char const* filename) :
filename(filename),
offset(0),
stay_open(false)
{
}
ClosedFileInputSource::ClosedFileInputSource(char const* filename) :
m(new Members(filename))
{
}
ClosedFileInputSource::~ClosedFileInputSource()
{
// Must be explicit and not inline -- see QPDF_DLL_CLASS in
@ -23,30 +18,29 @@ ClosedFileInputSource::~ClosedFileInputSource()
void
ClosedFileInputSource::before()
{
if (nullptr == this->m->fis) {
this->m->fis =
std::make_shared<FileInputSource>(this->m->filename.c_str());
this->m->fis->seek(this->m->offset, SEEK_SET);
this->m->fis->setLastOffset(this->last_offset);
if (nullptr == this->fis) {
this->fis = std::make_shared<FileInputSource>(this->filename.c_str());
this->fis->seek(this->offset, SEEK_SET);
this->fis->setLastOffset(this->last_offset);
}
}
void
ClosedFileInputSource::after()
{
this->last_offset = this->m->fis->getLastOffset();
this->m->offset = this->m->fis->tell();
if (this->m->stay_open) {
this->last_offset = this->fis->getLastOffset();
this->offset = this->fis->tell();
if (this->stay_open) {
return;
}
this->m->fis = nullptr;
this->fis = nullptr;
}
qpdf_offset_t
ClosedFileInputSource::findAndSkipNextEOL()
{
before();
qpdf_offset_t r = this->m->fis->findAndSkipNextEOL();
qpdf_offset_t r = this->fis->findAndSkipNextEOL();
after();
return r;
}
@ -54,14 +48,14 @@ ClosedFileInputSource::findAndSkipNextEOL()
std::string const&
ClosedFileInputSource::getName() const
{
return this->m->filename;
return this->filename;
}
qpdf_offset_t
ClosedFileInputSource::tell()
{
before();
qpdf_offset_t r = this->m->fis->tell();
qpdf_offset_t r = this->fis->tell();
after();
return r;
}
@ -70,16 +64,16 @@ void
ClosedFileInputSource::seek(qpdf_offset_t offset, int whence)
{
before();
this->m->fis->seek(offset, whence);
this->fis->seek(offset, whence);
after();
}
void
ClosedFileInputSource::rewind()
{
this->m->offset = 0;
if (this->m->fis.get()) {
this->m->fis->rewind();
this->offset = 0;
if (this->fis.get()) {
this->fis->rewind();
}
}
@ -87,7 +81,7 @@ size_t
ClosedFileInputSource::read(char* buffer, size_t length)
{
before();
size_t r = this->m->fis->read(buffer, length);
size_t r = this->fis->read(buffer, length);
after();
return r;
}
@ -96,7 +90,7 @@ void
ClosedFileInputSource::unreadCh(char ch)
{
before();
this->m->fis->unreadCh(ch);
this->fis->unreadCh(ch);
// Don't call after -- the file has to stay open after this
// operation.
}
@ -104,8 +98,8 @@ ClosedFileInputSource::unreadCh(char ch)
void
ClosedFileInputSource::stayOpen(bool val)
{
this->m->stay_open = val;
if ((!val) && this->m->fis.get()) {
this->stay_open = val;
if ((!val) && this->fis.get()) {
after();
}
}