mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-13 15:42:21 +00:00
Remove ClosedFileInputSource::Members
This commit is contained in:
parent
69a5fb7047
commit
d6a447b654
|
@ -73,23 +73,10 @@ class QPDF_DLL_CLASS ClosedFileInputSource: public InputSource
|
||||||
QPDF_DLL_PRIVATE
|
QPDF_DLL_PRIVATE
|
||||||
void after();
|
void after();
|
||||||
|
|
||||||
class QPDF_DLL_PRIVATE Members
|
std::string filename;
|
||||||
{
|
qpdf_offset_t offset;
|
||||||
friend class ClosedFileInputSource;
|
std::shared_ptr<FileInputSource> fis;
|
||||||
|
bool stay_open;
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QPDF_CLOSEDFILEINPUTSOURCE_HH
|
#endif // QPDF_CLOSEDFILEINPUTSOURCE_HH
|
||||||
|
|
|
@ -2,18 +2,13 @@
|
||||||
|
|
||||||
#include <qpdf/FileInputSource.hh>
|
#include <qpdf/FileInputSource.hh>
|
||||||
|
|
||||||
ClosedFileInputSource::Members::Members(char const* filename) :
|
ClosedFileInputSource::ClosedFileInputSource(char const* filename) :
|
||||||
filename(filename),
|
filename(filename),
|
||||||
offset(0),
|
offset(0),
|
||||||
stay_open(false)
|
stay_open(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ClosedFileInputSource::ClosedFileInputSource(char const* filename) :
|
|
||||||
m(new Members(filename))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ClosedFileInputSource::~ClosedFileInputSource()
|
ClosedFileInputSource::~ClosedFileInputSource()
|
||||||
{
|
{
|
||||||
// Must be explicit and not inline -- see QPDF_DLL_CLASS in
|
// Must be explicit and not inline -- see QPDF_DLL_CLASS in
|
||||||
|
@ -23,30 +18,29 @@ ClosedFileInputSource::~ClosedFileInputSource()
|
||||||
void
|
void
|
||||||
ClosedFileInputSource::before()
|
ClosedFileInputSource::before()
|
||||||
{
|
{
|
||||||
if (nullptr == this->m->fis) {
|
if (nullptr == this->fis) {
|
||||||
this->m->fis =
|
this->fis = std::make_shared<FileInputSource>(this->filename.c_str());
|
||||||
std::make_shared<FileInputSource>(this->m->filename.c_str());
|
this->fis->seek(this->offset, SEEK_SET);
|
||||||
this->m->fis->seek(this->m->offset, SEEK_SET);
|
this->fis->setLastOffset(this->last_offset);
|
||||||
this->m->fis->setLastOffset(this->last_offset);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClosedFileInputSource::after()
|
ClosedFileInputSource::after()
|
||||||
{
|
{
|
||||||
this->last_offset = this->m->fis->getLastOffset();
|
this->last_offset = this->fis->getLastOffset();
|
||||||
this->m->offset = this->m->fis->tell();
|
this->offset = this->fis->tell();
|
||||||
if (this->m->stay_open) {
|
if (this->stay_open) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this->m->fis = nullptr;
|
this->fis = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
qpdf_offset_t
|
qpdf_offset_t
|
||||||
ClosedFileInputSource::findAndSkipNextEOL()
|
ClosedFileInputSource::findAndSkipNextEOL()
|
||||||
{
|
{
|
||||||
before();
|
before();
|
||||||
qpdf_offset_t r = this->m->fis->findAndSkipNextEOL();
|
qpdf_offset_t r = this->fis->findAndSkipNextEOL();
|
||||||
after();
|
after();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -54,14 +48,14 @@ ClosedFileInputSource::findAndSkipNextEOL()
|
||||||
std::string const&
|
std::string const&
|
||||||
ClosedFileInputSource::getName() const
|
ClosedFileInputSource::getName() const
|
||||||
{
|
{
|
||||||
return this->m->filename;
|
return this->filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
qpdf_offset_t
|
qpdf_offset_t
|
||||||
ClosedFileInputSource::tell()
|
ClosedFileInputSource::tell()
|
||||||
{
|
{
|
||||||
before();
|
before();
|
||||||
qpdf_offset_t r = this->m->fis->tell();
|
qpdf_offset_t r = this->fis->tell();
|
||||||
after();
|
after();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -70,16 +64,16 @@ void
|
||||||
ClosedFileInputSource::seek(qpdf_offset_t offset, int whence)
|
ClosedFileInputSource::seek(qpdf_offset_t offset, int whence)
|
||||||
{
|
{
|
||||||
before();
|
before();
|
||||||
this->m->fis->seek(offset, whence);
|
this->fis->seek(offset, whence);
|
||||||
after();
|
after();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ClosedFileInputSource::rewind()
|
ClosedFileInputSource::rewind()
|
||||||
{
|
{
|
||||||
this->m->offset = 0;
|
this->offset = 0;
|
||||||
if (this->m->fis.get()) {
|
if (this->fis.get()) {
|
||||||
this->m->fis->rewind();
|
this->fis->rewind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +81,7 @@ size_t
|
||||||
ClosedFileInputSource::read(char* buffer, size_t length)
|
ClosedFileInputSource::read(char* buffer, size_t length)
|
||||||
{
|
{
|
||||||
before();
|
before();
|
||||||
size_t r = this->m->fis->read(buffer, length);
|
size_t r = this->fis->read(buffer, length);
|
||||||
after();
|
after();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +90,7 @@ void
|
||||||
ClosedFileInputSource::unreadCh(char ch)
|
ClosedFileInputSource::unreadCh(char ch)
|
||||||
{
|
{
|
||||||
before();
|
before();
|
||||||
this->m->fis->unreadCh(ch);
|
this->fis->unreadCh(ch);
|
||||||
// Don't call after -- the file has to stay open after this
|
// Don't call after -- the file has to stay open after this
|
||||||
// operation.
|
// operation.
|
||||||
}
|
}
|
||||||
|
@ -104,8 +98,8 @@ ClosedFileInputSource::unreadCh(char ch)
|
||||||
void
|
void
|
||||||
ClosedFileInputSource::stayOpen(bool val)
|
ClosedFileInputSource::stayOpen(bool val)
|
||||||
{
|
{
|
||||||
this->m->stay_open = val;
|
this->stay_open = val;
|
||||||
if ((!val) && this->m->fis.get()) {
|
if ((!val) && this->fis.get()) {
|
||||||
after();
|
after();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user