2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-03 07:12:28 +00:00

Remove temporary OHArray::at

This commit is contained in:
m-holger 2023-03-25 16:59:49 +00:00
parent ad2875a4aa
commit 1367226002
3 changed files with 11 additions and 22 deletions

View File

@ -11,17 +11,6 @@ OHArray::OHArray()
{ {
} }
QPDFObjectHandle
OHArray::at(size_t idx) const
{
if (idx >= elements.size()) {
throw std::logic_error(
"INTERNAL ERROR: bounds error accessing OHArray element");
}
auto const& obj = elements.at(idx);
return obj ? obj : null_oh;
}
void void
OHArray::disconnect() OHArray::disconnect()
{ {

View File

@ -5,6 +5,8 @@
#include <qpdf/QUtil.hh> #include <qpdf/QUtil.hh>
#include <stdexcept> #include <stdexcept>
static const QPDFObjectHandle null_oh = QPDFObjectHandle::newNull();
QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v) : QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v) :
QPDFValue(::ot_array, "array") QPDFValue(::ot_array, "array")
{ {
@ -93,9 +95,9 @@ QPDF_Array::unparse()
return result; return result;
} else { } else {
std::string result = "[ "; std::string result = "[ ";
size_t size = elements.elements.size(); auto size = elements.elements.size();
for (size_t i = 0; i < size; ++i) { for (int i = 0; i < int(size); ++i) {
result += elements.at(i).unparse(); result += getItem(i).unparse();
result += " "; result += " ";
} }
result += "]"; result += "]";
@ -116,8 +118,8 @@ QPDF_Array::getJSON(int json_version)
} else { } else {
JSON j = JSON::makeArray(); JSON j = JSON::makeArray();
size_t size = elements.elements.size(); size_t size = elements.elements.size();
for (size_t i = 0; i < size; ++i) { for (int i = 0; i < int(size); ++i) {
j.addArrayElement(elements.at(i).getJSON(json_version)); j.addArrayElement(getItem(i).getJSON(json_version));
} }
return j; return j;
} }
@ -149,7 +151,8 @@ QPDF_Array::getItem(int n) const
throw std::logic_error( throw std::logic_error(
"INTERNAL ERROR: bounds error accessing QPDF_Array element"); "INTERNAL ERROR: bounds error accessing QPDF_Array element");
} }
return elements.at(QIntC::to_size(n)); auto const& obj = elements.elements.at(size_t(n));
return obj ? obj : null_oh;
} }
} }
@ -162,10 +165,8 @@ QPDF_Array::getAsVector(std::vector<QPDFObjectHandle>& v) const
v.push_back(sp_elements.at(i)); v.push_back(sp_elements.at(i));
} }
} else { } else {
size_t size = elements.elements.size(); v = std::vector<QPDFObjectHandle>(
for (size_t i = 0; i < size; ++i) { elements.elements.cbegin(), elements.elements.cend());
v.push_back(elements.at(i));
}
} }
} }

View File

@ -12,7 +12,6 @@ class OHArray
{ {
public: public:
OHArray(); OHArray();
QPDFObjectHandle at(size_t idx) const;
void setAt(size_t idx, QPDFObjectHandle oh); void setAt(size_t idx, QPDFObjectHandle oh);
void erase(size_t idx); void erase(size_t idx);
void insert(size_t idx, QPDFObjectHandle oh); void insert(size_t idx, QPDFObjectHandle oh);