Commit d6a447b654592cc1d1118a54bdedcc142ac8d434

Authored by m-holger
1 parent 69a5fb70

Remove ClosedFileInputSource::Members

include/qpdf/ClosedFileInputSource.hh
... ... @@ -73,23 +73,10 @@ class QPDF_DLL_CLASS ClosedFileInputSource: public InputSource
73 73 QPDF_DLL_PRIVATE
74 74 void after();
75 75  
76   - class QPDF_DLL_PRIVATE Members
77   - {
78   - friend class ClosedFileInputSource;
79   -
80   - public:
81   - QPDF_DLL
82   - ~Members() = default;
83   -
84   - private:
85   - Members(char const* filename);
86   -
87   - std::string filename;
88   - qpdf_offset_t offset;
89   - std::shared_ptr<FileInputSource> fis;
90   - bool stay_open;
91   - };
92   - std::shared_ptr<Members> m;
  76 + std::string filename;
  77 + qpdf_offset_t offset;
  78 + std::shared_ptr<FileInputSource> fis;
  79 + bool stay_open;
93 80 };
94 81  
95 82 #endif // QPDF_CLOSEDFILEINPUTSOURCE_HH
... ...
libqpdf/ClosedFileInputSource.cc
... ... @@ -2,18 +2,13 @@
2 2  
3 3 #include <qpdf/FileInputSource.hh>
4 4  
5   -ClosedFileInputSource::Members::Members(char const* filename) :
  5 +ClosedFileInputSource::ClosedFileInputSource(char const* filename) :
6 6 filename(filename),
7 7 offset(0),
8 8 stay_open(false)
9 9 {
10 10 }
11 11  
12   -ClosedFileInputSource::ClosedFileInputSource(char const* filename) :
13   - m(new Members(filename))
14   -{
15   -}
16   -
17 12 ClosedFileInputSource::~ClosedFileInputSource()
18 13 {
19 14 // Must be explicit and not inline -- see QPDF_DLL_CLASS in
... ... @@ -23,30 +18,29 @@ ClosedFileInputSource::~ClosedFileInputSource()
23 18 void
24 19 ClosedFileInputSource::before()
25 20 {
26   - if (nullptr == this->m->fis) {
27   - this->m->fis =
28   - std::make_shared<FileInputSource>(this->m->filename.c_str());
29   - this->m->fis->seek(this->m->offset, SEEK_SET);
30   - this->m->fis->setLastOffset(this->last_offset);
  21 + if (nullptr == this->fis) {
  22 + this->fis = std::make_shared<FileInputSource>(this->filename.c_str());
  23 + this->fis->seek(this->offset, SEEK_SET);
  24 + this->fis->setLastOffset(this->last_offset);
31 25 }
32 26 }
33 27  
34 28 void
35 29 ClosedFileInputSource::after()
36 30 {
37   - this->last_offset = this->m->fis->getLastOffset();
38   - this->m->offset = this->m->fis->tell();
39   - if (this->m->stay_open) {
  31 + this->last_offset = this->fis->getLastOffset();
  32 + this->offset = this->fis->tell();
  33 + if (this->stay_open) {
40 34 return;
41 35 }
42   - this->m->fis = nullptr;
  36 + this->fis = nullptr;
43 37 }
44 38  
45 39 qpdf_offset_t
46 40 ClosedFileInputSource::findAndSkipNextEOL()
47 41 {
48 42 before();
49   - qpdf_offset_t r = this->m->fis->findAndSkipNextEOL();
  43 + qpdf_offset_t r = this->fis->findAndSkipNextEOL();
50 44 after();
51 45 return r;
52 46 }
... ... @@ -54,14 +48,14 @@ ClosedFileInputSource::findAndSkipNextEOL()
54 48 std::string const&
55 49 ClosedFileInputSource::getName() const
56 50 {
57   - return this->m->filename;
  51 + return this->filename;
58 52 }
59 53  
60 54 qpdf_offset_t
61 55 ClosedFileInputSource::tell()
62 56 {
63 57 before();
64   - qpdf_offset_t r = this->m->fis->tell();
  58 + qpdf_offset_t r = this->fis->tell();
65 59 after();
66 60 return r;
67 61 }
... ... @@ -70,16 +64,16 @@ void
70 64 ClosedFileInputSource::seek(qpdf_offset_t offset, int whence)
71 65 {
72 66 before();
73   - this->m->fis->seek(offset, whence);
  67 + this->fis->seek(offset, whence);
74 68 after();
75 69 }
76 70  
77 71 void
78 72 ClosedFileInputSource::rewind()
79 73 {
80   - this->m->offset = 0;
81   - if (this->m->fis.get()) {
82   - this->m->fis->rewind();
  74 + this->offset = 0;
  75 + if (this->fis.get()) {
  76 + this->fis->rewind();
83 77 }
84 78 }
85 79  
... ... @@ -87,7 +81,7 @@ size_t
87 81 ClosedFileInputSource::read(char* buffer, size_t length)
88 82 {
89 83 before();
90   - size_t r = this->m->fis->read(buffer, length);
  84 + size_t r = this->fis->read(buffer, length);
91 85 after();
92 86 return r;
93 87 }
... ... @@ -96,7 +90,7 @@ void
96 90 ClosedFileInputSource::unreadCh(char ch)
97 91 {
98 92 before();
99   - this->m->fis->unreadCh(ch);
  93 + this->fis->unreadCh(ch);
100 94 // Don't call after -- the file has to stay open after this
101 95 // operation.
102 96 }
... ... @@ -104,8 +98,8 @@ ClosedFileInputSource::unreadCh(char ch)
104 98 void
105 99 ClosedFileInputSource::stayOpen(bool val)
106 100 {
107   - this->m->stay_open = val;
108   - if ((!val) && this->m->fis.get()) {
  101 + this->stay_open = val;
  102 + if ((!val) && this->fis.get()) {
109 103 after();
110 104 }
111 105 }
... ...