Commit fc4feb6f1abff887e22eaca05ae260e5eb7376c7

Authored by m-holger
1 parent d6a447b6

Remove BufferInputSource::Members

include/qpdf/BufferInputSource.hh
... ... @@ -54,26 +54,11 @@ class QPDF_DLL_CLASS BufferInputSource: public InputSource
54 54 virtual void unreadCh(char ch);
55 55  
56 56 private:
57   - class QPDF_DLL_PRIVATE Members
58   - {
59   - friend class BufferInputSource;
60   -
61   - public:
62   - QPDF_DLL
63   - ~Members() = default;
64   -
65   - private:
66   - Members(bool own_memory, std::string const& description, Buffer* buf);
67   - Members(Members const&) = delete;
68   -
69   - bool own_memory;
70   - std::string description;
71   - Buffer* buf;
72   - qpdf_offset_t cur_offset;
73   - qpdf_offset_t max_offset;
74   - };
75   -
76   - std::shared_ptr<Members> m;
  57 + bool own_memory;
  58 + std::string description;
  59 + Buffer* buf;
  60 + qpdf_offset_t cur_offset;
  61 + qpdf_offset_t max_offset;
77 62 };
78 63  
79 64 #endif // QPDF_BUFFERINPUTSOURCE_HH
... ...
libqpdf/BufferInputSource.cc
... ... @@ -7,8 +7,8 @@
7 7 #include <stdexcept>
8 8 #include <string.h>
9 9  
10   -BufferInputSource::Members::Members(
11   - bool own_memory, std::string const& description, Buffer* buf) :
  10 +BufferInputSource::BufferInputSource(
  11 + std::string const& description, Buffer* buf, bool own_memory) :
12 12 own_memory(own_memory),
13 13 description(description),
14 14 buf(buf),
... ... @@ -18,60 +18,54 @@ BufferInputSource::Members::Members(
18 18 }
19 19  
20 20 BufferInputSource::BufferInputSource(
21   - std::string const& description, Buffer* buf, bool own_memory) :
22   - m(new Members(own_memory, description, buf))
23   -{
24   -}
25   -
26   -BufferInputSource::BufferInputSource(
27 21 std::string const& description, std::string const& contents) :
28   - m(new Members(true, description, nullptr))
  22 + own_memory(true),
  23 + description(description),
  24 + buf(new Buffer(contents.length())),
  25 + cur_offset(0),
  26 + max_offset(QIntC::to_offset(buf->getSize()))
29 27 {
30   - this->m->buf = new Buffer(contents.length());
31   - this->m->max_offset = QIntC::to_offset(this->m->buf->getSize());
32   - unsigned char* bp = this->m->buf->getBuffer();
33   - memcpy(bp, contents.c_str(), contents.length());
  28 + memcpy(buf->getBuffer(), contents.c_str(), contents.length());
34 29 }
35 30  
36 31 BufferInputSource::~BufferInputSource()
37 32 {
38   - if (this->m->own_memory) {
39   - delete this->m->buf;
  33 + if (this->own_memory) {
  34 + delete this->buf;
40 35 }
41 36 }
42 37  
43 38 qpdf_offset_t
44 39 BufferInputSource::findAndSkipNextEOL()
45 40 {
46   - if (this->m->cur_offset < 0) {
  41 + if (this->cur_offset < 0) {
47 42 throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0");
48 43 }
49   - qpdf_offset_t end_pos = this->m->max_offset;
50   - if (this->m->cur_offset >= end_pos) {
  44 + qpdf_offset_t end_pos = this->max_offset;
  45 + if (this->cur_offset >= end_pos) {
51 46 this->last_offset = end_pos;
52   - this->m->cur_offset = end_pos;
  47 + this->cur_offset = end_pos;
53 48 return end_pos;
54 49 }
55 50  
56 51 qpdf_offset_t result = 0;
57   - unsigned char const* buffer = this->m->buf->getBuffer();
  52 + unsigned char const* buffer = this->buf->getBuffer();
58 53 unsigned char const* end = buffer + end_pos;
59   - unsigned char const* p = buffer + this->m->cur_offset;
  54 + unsigned char const* p = buffer + this->cur_offset;
60 55  
61 56 while ((p < end) && !((*p == '\r') || (*p == '\n'))) {
62 57 ++p;
63 58 }
64 59 if (p < end) {
65 60 result = p - buffer;
66   - this->m->cur_offset = result + 1;
  61 + this->cur_offset = result + 1;
67 62 ++p;
68   - while ((this->m->cur_offset < end_pos) &&
69   - ((*p == '\r') || (*p == '\n'))) {
  63 + while ((this->cur_offset < end_pos) && ((*p == '\r') || (*p == '\n'))) {
70 64 ++p;
71   - ++this->m->cur_offset;
  65 + ++this->cur_offset;
72 66 }
73 67 } else {
74   - this->m->cur_offset = end_pos;
  68 + this->cur_offset = end_pos;
75 69 result = end_pos;
76 70 }
77 71 return result;
... ... @@ -80,13 +74,13 @@ BufferInputSource::findAndSkipNextEOL()
80 74 std::string const&
81 75 BufferInputSource::getName() const
82 76 {
83   - return this->m->description;
  77 + return this->description;
84 78 }
85 79  
86 80 qpdf_offset_t
87 81 BufferInputSource::tell()
88 82 {
89   - return this->m->cur_offset;
  83 + return this->cur_offset;
90 84 }
91 85  
92 86 void
... ... @@ -94,17 +88,17 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence)
94 88 {
95 89 switch (whence) {
96 90 case SEEK_SET:
97   - this->m->cur_offset = offset;
  91 + this->cur_offset = offset;
98 92 break;
99 93  
100 94 case SEEK_END:
101   - QIntC::range_check(this->m->max_offset, offset);
102   - this->m->cur_offset = this->m->max_offset + offset;
  95 + QIntC::range_check(this->max_offset, offset);
  96 + this->cur_offset = this->max_offset + offset;
103 97 break;
104 98  
105 99 case SEEK_CUR:
106   - QIntC::range_check(this->m->cur_offset, offset);
107   - this->m->cur_offset += offset;
  100 + QIntC::range_check(this->cur_offset, offset);
  101 + this->cur_offset += offset;
108 102 break;
109 103  
110 104 default:
... ... @@ -113,42 +107,41 @@ BufferInputSource::seek(qpdf_offset_t offset, int whence)
113 107 break;
114 108 }
115 109  
116   - if (this->m->cur_offset < 0) {
  110 + if (this->cur_offset < 0) {
117 111 throw std::runtime_error(
118   - this->m->description + ": seek before beginning of buffer");
  112 + this->description + ": seek before beginning of buffer");
119 113 }
120 114 }
121 115  
122 116 void
123 117 BufferInputSource::rewind()
124 118 {
125   - this->m->cur_offset = 0;
  119 + this->cur_offset = 0;
126 120 }
127 121  
128 122 size_t
129 123 BufferInputSource::read(char* buffer, size_t length)
130 124 {
131   - if (this->m->cur_offset < 0) {
  125 + if (this->cur_offset < 0) {
132 126 throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0");
133 127 }
134   - qpdf_offset_t end_pos = this->m->max_offset;
135   - if (this->m->cur_offset >= end_pos) {
  128 + qpdf_offset_t end_pos = this->max_offset;
  129 + if (this->cur_offset >= end_pos) {
136 130 this->last_offset = end_pos;
137 131 return 0;
138 132 }
139 133  
140   - this->last_offset = this->m->cur_offset;
141   - size_t len =
142   - std::min(QIntC::to_size(end_pos - this->m->cur_offset), length);
143   - memcpy(buffer, this->m->buf->getBuffer() + this->m->cur_offset, len);
144   - this->m->cur_offset += QIntC::to_offset(len);
  134 + this->last_offset = this->cur_offset;
  135 + size_t len = std::min(QIntC::to_size(end_pos - this->cur_offset), length);
  136 + memcpy(buffer, this->buf->getBuffer() + this->cur_offset, len);
  137 + this->cur_offset += QIntC::to_offset(len);
145 138 return len;
146 139 }
147 140  
148 141 void
149 142 BufferInputSource::unreadCh(char ch)
150 143 {
151   - if (this->m->cur_offset > 0) {
152   - --this->m->cur_offset;
  144 + if (this->cur_offset > 0) {
  145 + --this->cur_offset;
153 146 }
154 147 }
... ...