2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Remove temporary OHArray::size, append and remove_last

Also, add const overload of QPDFObjectHandle::getObj
This commit is contained in:
m-holger 2023-03-25 16:37:47 +00:00
parent 8fdc3f0964
commit ad2875a4aa
4 changed files with 15 additions and 31 deletions

View File

@ -1578,6 +1578,11 @@ class QPDFObjectHandle
{
return obj;
}
std::shared_ptr<QPDFObject>
getObj() const
{
return obj;
}
QPDFObject*
getObjectPtr()
{

View File

@ -11,24 +11,6 @@ OHArray::OHArray()
{
}
size_t
OHArray::size() const
{
return elements.size();
}
void
OHArray::append(QPDFObjectHandle oh)
{
elements.push_back(oh.getObj());
}
void
OHArray::append(std::shared_ptr<QPDFObject>&& obj)
{
elements.push_back(std::move(obj));
}
QPDFObjectHandle
OHArray::at(size_t idx) const
{
@ -77,7 +59,7 @@ OHArray::insert(size_t idx, QPDFObjectHandle oh)
throw std::logic_error("bounds error inserting item to OHArray");
} else if (idx == elements.size()) {
// Allow inserting to the last position
append(oh.getObj());
elements.push_back(oh.getObj());
} else {
int n = int(idx);
elements.insert(elements.cbegin() + n, oh.getObj());

View File

@ -93,7 +93,7 @@ QPDF_Array::unparse()
return result;
} else {
std::string result = "[ ";
size_t size = elements.size();
size_t size = elements.elements.size();
for (size_t i = 0; i < size; ++i) {
result += elements.at(i).unparse();
result += " ";
@ -115,7 +115,7 @@ QPDF_Array::getJSON(int json_version)
return j;
} else {
JSON j = JSON::makeArray();
size_t size = elements.size();
size_t size = elements.elements.size();
for (size_t i = 0; i < size; ++i) {
j.addArrayElement(elements.at(i).getJSON(json_version));
}
@ -131,7 +131,7 @@ QPDF_Array::getNItems() const
// a lot of code.
return QIntC::to_int(sp_elements.size());
} else {
return QIntC::to_int(elements.size());
return QIntC::to_int(elements.elements.size());
}
}
@ -145,7 +145,7 @@ QPDF_Array::getItem(int n) const
}
return sp_elements.at(QIntC::to_size(n));
} else {
if ((n < 0) || (n >= QIntC::to_int(elements.size()))) {
if ((n < 0) || (n >= QIntC::to_int(elements.elements.size()))) {
throw std::logic_error(
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
}
@ -162,7 +162,7 @@ QPDF_Array::getAsVector(std::vector<QPDFObjectHandle>& v) const
v.push_back(sp_elements.at(i));
}
} else {
size_t size = elements.size();
size_t size = elements.elements.size();
for (size_t i = 0; i < size; ++i) {
v.push_back(elements.at(i));
}
@ -190,7 +190,7 @@ QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v)
} else {
elements = OHArray();
for (auto const& iter: v) {
elements.append(iter);
elements.elements.push_back(iter.getObj());
}
}
}
@ -211,7 +211,7 @@ QPDF_Array::setFromVector(std::vector<std::shared_ptr<QPDFObject>>&& v)
} else {
elements = OHArray();
for (auto&& item: v) {
elements.append(std::move(item));
elements.elements.push_back(std::move(item));
}
}
}
@ -228,7 +228,7 @@ QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
sp_elements.insert(QIntC::to_size(at), item);
} else {
// As special case, also allow insert beyond the end
if ((at < 0) || (at > QIntC::to_int(elements.size()))) {
if ((at < 0) || (at > QIntC::to_int(elements.elements.size()))) {
throw std::logic_error(
"INTERNAL ERROR: bounds error accessing QPDF_Array element");
}
@ -242,7 +242,7 @@ QPDF_Array::appendItem(QPDFObjectHandle const& item)
if (sparse) {
sp_elements.append(item);
} else {
elements.append(item);
elements.elements.push_back(item.getObj());
}
}

View File

@ -12,9 +12,6 @@ class OHArray
{
public:
OHArray();
size_t size() const;
void append(QPDFObjectHandle oh);
void append(std::shared_ptr<QPDFObject>&& obj);
QPDFObjectHandle at(size_t idx) const;
void setAt(size_t idx, QPDFObjectHandle oh);
void erase(size_t idx);