2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Remove temporary OHArray

This commit is contained in:
m-holger 2023-03-25 18:23:39 +00:00
parent 9e30de8032
commit ea5164938e
5 changed files with 29 additions and 62 deletions

View File

@ -116,7 +116,6 @@ set(libqpdf_SOURCES
SecureRandomDataProvider.cc SecureRandomDataProvider.cc
SF_FlateLzwDecode.cc SF_FlateLzwDecode.cc
SparseOHArray.cc SparseOHArray.cc
OHArray.cc
qpdf-c.cc qpdf-c.cc
qpdfjob-c.cc qpdfjob-c.cc
qpdflogger-c.cc) qpdflogger-c.cc)

View File

@ -1,5 +0,0 @@
#include <qpdf/OHArray.hh>
OHArray::OHArray()
{
}

View File

@ -29,7 +29,7 @@ QPDF_Array::QPDF_Array(SparseOHArray const& items) :
{ {
} }
QPDF_Array::QPDF_Array(OHArray const& items) : QPDF_Array::QPDF_Array(std::vector<std::shared_ptr<QPDFObject>> const& items) :
QPDFValue(::ot_array, "array"), QPDFValue(::ot_array, "array"),
sparse(false), sparse(false),
elements(items) elements(items)
@ -56,7 +56,7 @@ QPDF_Array::create(SparseOHArray const& items)
} }
std::shared_ptr<QPDFObject> std::shared_ptr<QPDFObject>
QPDF_Array::create(OHArray const& items) QPDF_Array::create(std::vector<std::shared_ptr<QPDFObject>> const& items)
{ {
return do_create(new QPDF_Array(items)); return do_create(new QPDF_Array(items));
} }
@ -70,10 +70,10 @@ QPDF_Array::copy(bool shallow)
if (shallow) { if (shallow) {
return create(elements); return create(elements);
} else { } else {
OHArray result; std::vector<std::shared_ptr<QPDFObject>> result;
result.elements.reserve(elements.elements.size()); result.reserve(elements.size());
for (auto const& element: elements.elements) { for (auto const& element: elements) {
result.elements.push_back( result.push_back(
element element
? (element->getObjGen().isIndirect() ? element ? (element->getObjGen().isIndirect() ? element
: element->copy()) : element->copy())
@ -90,7 +90,7 @@ QPDF_Array::disconnect()
if (sparse) { if (sparse) {
sp_elements.disconnect(); sp_elements.disconnect();
} else { } else {
for (auto const& iter: elements.elements) { for (auto const& iter: elements) {
if (iter) { if (iter) {
QPDFObjectHandle::DisconnectAccess::disconnect(iter); QPDFObjectHandle::DisconnectAccess::disconnect(iter);
} }
@ -112,7 +112,7 @@ QPDF_Array::unparse()
return result; return result;
} else { } else {
std::string result = "[ "; std::string result = "[ ";
auto size = elements.elements.size(); auto size = elements.size();
for (int i = 0; i < int(size); ++i) { for (int i = 0; i < int(size); ++i) {
result += getItem(i).unparse(); result += getItem(i).unparse();
result += " "; result += " ";
@ -134,7 +134,7 @@ QPDF_Array::getJSON(int json_version)
return j; return j;
} else { } else {
JSON j = JSON::makeArray(); JSON j = JSON::makeArray();
size_t size = elements.elements.size(); size_t size = elements.size();
for (int i = 0; i < int(size); ++i) { for (int i = 0; i < int(size); ++i) {
j.addArrayElement(getItem(i).getJSON(json_version)); j.addArrayElement(getItem(i).getJSON(json_version));
} }
@ -150,7 +150,7 @@ QPDF_Array::getNItems() const
// a lot of code. // a lot of code.
return QIntC::to_int(sp_elements.size()); return QIntC::to_int(sp_elements.size());
} else { } else {
return QIntC::to_int(elements.elements.size()); return QIntC::to_int(elements.size());
} }
} }
@ -164,11 +164,11 @@ QPDF_Array::getItem(int n) const
} }
return sp_elements.at(QIntC::to_size(n)); return sp_elements.at(QIntC::to_size(n));
} else { } else {
if ((n < 0) || (n >= QIntC::to_int(elements.elements.size()))) { if ((n < 0) || (n >= QIntC::to_int(elements.size()))) {
throw std::logic_error( throw std::logic_error(
"INTERNAL ERROR: bounds error accessing QPDF_Array element"); "INTERNAL ERROR: bounds error accessing QPDF_Array element");
} }
auto const& obj = elements.elements.at(size_t(n)); auto const& obj = elements.at(size_t(n));
return obj ? obj : null_oh; return obj ? obj : null_oh;
} }
} }
@ -182,8 +182,7 @@ QPDF_Array::getAsVector(std::vector<QPDFObjectHandle>& v) const
v.push_back(sp_elements.at(i)); v.push_back(sp_elements.at(i));
} }
} else { } else {
v = std::vector<QPDFObjectHandle>( v = std::vector<QPDFObjectHandle>(elements.cbegin(), elements.cend());
elements.elements.cbegin(), elements.elements.cend());
} }
} }
@ -194,10 +193,10 @@ QPDF_Array::setItem(int n, QPDFObjectHandle const& oh)
sp_elements.setAt(QIntC::to_size(n), oh); sp_elements.setAt(QIntC::to_size(n), oh);
} else { } else {
size_t idx = size_t(n); size_t idx = size_t(n);
if (n < 0 || idx >= elements.elements.size()) { if (n < 0 || idx >= elements.size()) {
throw std::logic_error("bounds error setting item in QPDF_Array"); throw std::logic_error("bounds error setting item in QPDF_Array");
} }
elements.elements[idx] = oh.getObj(); elements[idx] = oh.getObj();
} }
} }
@ -210,9 +209,9 @@ QPDF_Array::setFromVector(std::vector<QPDFObjectHandle> const& v)
sp_elements.append(iter); sp_elements.append(iter);
} }
} else { } else {
elements = OHArray(); elements.resize(0);
for (auto const& iter: v) { for (auto const& iter: v) {
elements.elements.push_back(iter.getObj()); elements.push_back(iter.getObj());
} }
} }
} }
@ -231,10 +230,7 @@ QPDF_Array::setFromVector(std::vector<std::shared_ptr<QPDFObject>>&& v)
} }
} }
} else { } else {
elements = OHArray(); elements = std::move(v);
for (auto&& item: v) {
elements.elements.push_back(std::move(item));
}
} }
} }
@ -251,17 +247,16 @@ QPDF_Array::insertItem(int at, QPDFObjectHandle const& item)
} else { } else {
// As special case, also allow insert beyond the end // As special case, also allow insert beyond the end
size_t idx = QIntC::to_size(at); size_t idx = QIntC::to_size(at);
if ((at < 0) || (at > QIntC::to_int(elements.elements.size()))) { if ((at < 0) || (at > QIntC::to_int(elements.size()))) {
throw std::logic_error( throw std::logic_error(
"INTERNAL ERROR: bounds error accessing QPDF_Array element"); "INTERNAL ERROR: bounds error accessing QPDF_Array element");
} }
if (idx == elements.elements.size()) { if (idx == elements.size()) {
// Allow inserting to the last position // Allow inserting to the last position
elements.elements.push_back(item.getObj()); elements.push_back(item.getObj());
} else { } else {
int n = int(idx); int n = int(idx);
elements.elements.insert( elements.insert(elements.cbegin() + n, item.getObj());
elements.elements.cbegin() + n, item.getObj());
} }
} }
} }
@ -272,7 +267,7 @@ QPDF_Array::appendItem(QPDFObjectHandle const& item)
if (sparse) { if (sparse) {
sp_elements.append(item); sp_elements.append(item);
} else { } else {
elements.elements.push_back(item.getObj()); elements.push_back(item.getObj());
} }
} }
@ -283,10 +278,10 @@ QPDF_Array::eraseItem(int at)
sp_elements.erase(QIntC::to_size(at)); sp_elements.erase(QIntC::to_size(at));
} else { } else {
size_t idx = QIntC::to_size(at); size_t idx = QIntC::to_size(at);
if (idx >= elements.elements.size()) { if (idx >= elements.size()) {
throw std::logic_error("bounds error erasing item from OHArray"); throw std::logic_error("bounds error erasing item from OHArray");
} }
int n = int(idx); int n = int(idx);
elements.elements.erase(elements.elements.cbegin() + n); elements.erase(elements.cbegin() + n);
} }
} }

View File

@ -1,21 +0,0 @@
#ifndef QPDF_OHARRAY_HH
#define QPDF_OHARRAY_HH
#include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/QPDFObject_private.hh>
#include <vector>
class QPDF_Array;
class OHArray
{
public:
OHArray();
private:
friend class QPDF_Array;
std::vector<std::shared_ptr<QPDFObject>> elements;
};
#endif // QPDF_OHARRAY_HH

View File

@ -3,9 +3,7 @@
#include <qpdf/QPDFValue.hh> #include <qpdf/QPDFValue.hh>
#include <qpdf/OHArray.hh>
#include <qpdf/SparseOHArray.hh> #include <qpdf/SparseOHArray.hh>
#include <list>
#include <vector> #include <vector>
class QPDF_Array: public QPDFValue class QPDF_Array: public QPDFValue
@ -17,7 +15,8 @@ class QPDF_Array: public QPDFValue
static std::shared_ptr<QPDFObject> static std::shared_ptr<QPDFObject>
create(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse); create(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse);
static std::shared_ptr<QPDFObject> create(SparseOHArray const& items); static std::shared_ptr<QPDFObject> create(SparseOHArray const& items);
static std::shared_ptr<QPDFObject> create(OHArray const& items); static std::shared_ptr<QPDFObject>
create(std::vector<std::shared_ptr<QPDFObject>> const& items);
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
virtual std::string unparse(); virtual std::string unparse();
virtual JSON getJSON(int json_version); virtual JSON getJSON(int json_version);
@ -38,10 +37,10 @@ class QPDF_Array: public QPDFValue
QPDF_Array(std::vector<QPDFObjectHandle> const& items); QPDF_Array(std::vector<QPDFObjectHandle> const& items);
QPDF_Array(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse); QPDF_Array(std::vector<std::shared_ptr<QPDFObject>>&& items, bool sparse);
QPDF_Array(SparseOHArray const& items); QPDF_Array(SparseOHArray const& items);
QPDF_Array(OHArray const& items); QPDF_Array(std::vector<std::shared_ptr<QPDFObject>> const& items);
bool sparse{false}; bool sparse{false};
SparseOHArray sp_elements; SparseOHArray sp_elements;
OHArray elements; std::vector<std::shared_ptr<QPDFObject>> elements;
}; };
#endif // QPDF_ARRAY_HH #endif // QPDF_ARRAY_HH