mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-05 08:02:11 +00:00
Inline QPDF_Array::getNItems and rename to size
This commit is contained in:
parent
e6db8ddeba
commit
51d350c98c
@ -789,9 +789,8 @@ QPDFObjectHandle::aitems()
|
|||||||
int
|
int
|
||||||
QPDFObjectHandle::getArrayNItems()
|
QPDFObjectHandle::getArrayNItems()
|
||||||
{
|
{
|
||||||
auto array = asArray();
|
if (auto array = asArray()) {
|
||||||
if (array) {
|
return array->size();
|
||||||
return array->getNItems();
|
|
||||||
} else {
|
} else {
|
||||||
typeWarning("array", "treating as empty");
|
typeWarning("array", "treating as empty");
|
||||||
QTC::TC("qpdf", "QPDFObjectHandle array treating as empty");
|
QTC::TC("qpdf", "QPDFObjectHandle array treating as empty");
|
||||||
@ -803,7 +802,7 @@ QPDFObjectHandle
|
|||||||
QPDFObjectHandle::getArrayItem(int n)
|
QPDFObjectHandle::getArrayItem(int n)
|
||||||
{
|
{
|
||||||
auto array = asArray();
|
auto array = asArray();
|
||||||
if (array && (n < array->getNItems()) && (n >= 0)) {
|
if (array && n < array->size() && n >= 0) {
|
||||||
return array->getItem(n);
|
return array->getItem(n);
|
||||||
} else {
|
} else {
|
||||||
if (array) {
|
if (array) {
|
||||||
@ -823,7 +822,7 @@ bool
|
|||||||
QPDFObjectHandle::isRectangle()
|
QPDFObjectHandle::isRectangle()
|
||||||
{
|
{
|
||||||
auto array = asArray();
|
auto array = asArray();
|
||||||
if ((array == nullptr) || (array->getNItems() != 4)) {
|
if (array == nullptr || array->size() != 4) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
@ -838,7 +837,7 @@ bool
|
|||||||
QPDFObjectHandle::isMatrix()
|
QPDFObjectHandle::isMatrix()
|
||||||
{
|
{
|
||||||
auto array = asArray();
|
auto array = asArray();
|
||||||
if ((array == nullptr) || (array->getNItems() != 6)) {
|
if (array == nullptr || array->size() != 6) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 6; ++i) {
|
for (int i = 0; i < 6; ++i) {
|
||||||
@ -975,7 +974,7 @@ void
|
|||||||
QPDFObjectHandle::eraseItem(int at)
|
QPDFObjectHandle::eraseItem(int at)
|
||||||
{
|
{
|
||||||
auto array = asArray();
|
auto array = asArray();
|
||||||
if (array && (at < array->getNItems()) && (at >= 0)) {
|
if (array && at < array->size() && at >= 0) {
|
||||||
array->eraseItem(at);
|
array->eraseItem(at);
|
||||||
} else {
|
} else {
|
||||||
if (array) {
|
if (array) {
|
||||||
@ -991,11 +990,9 @@ QPDFObjectHandle::eraseItem(int at)
|
|||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
QPDFObjectHandle::eraseItemAndGetOld(int at)
|
QPDFObjectHandle::eraseItemAndGetOld(int at)
|
||||||
{
|
{
|
||||||
auto result = QPDFObjectHandle::newNull();
|
|
||||||
auto array = asArray();
|
auto array = asArray();
|
||||||
if (array && (at < array->getNItems()) && (at >= 0)) {
|
auto result = (array && at < array->size() && at >= 0) ? array->getItem(at)
|
||||||
result = array->getItem(at);
|
: newNull();
|
||||||
}
|
|
||||||
eraseItem(at);
|
eraseItem(at);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1515,9 +1512,8 @@ QPDFObjectHandle::arrayOrStreamToStreamArray(
|
|||||||
{
|
{
|
||||||
all_description = description;
|
all_description = description;
|
||||||
std::vector<QPDFObjectHandle> result;
|
std::vector<QPDFObjectHandle> result;
|
||||||
auto array = asArray();
|
if (auto array = asArray()) {
|
||||||
if (array) {
|
int n_items = array->size();
|
||||||
int n_items = array->getNItems();
|
|
||||||
for (int i = 0; i < n_items; ++i) {
|
for (int i = 0; i < n_items; ++i) {
|
||||||
QPDFObjectHandle item = array->getItem(i);
|
QPDFObjectHandle item = array->getItem(i);
|
||||||
if (item.isStream()) {
|
if (item.isStream()) {
|
||||||
@ -2217,7 +2213,7 @@ QPDFObjectHandle::makeDirect(
|
|||||||
} else if (isArray()) {
|
} else if (isArray()) {
|
||||||
std::vector<QPDFObjectHandle> items;
|
std::vector<QPDFObjectHandle> items;
|
||||||
auto array = asArray();
|
auto array = asArray();
|
||||||
int n = array->getNItems();
|
int n = array->size();
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
items.push_back(array->getItem(i));
|
items.push_back(array->getItem(i));
|
||||||
items.back().makeDirect(visited, stop_at_streams);
|
items.back().makeDirect(visited, stop_at_streams);
|
||||||
|
@ -142,18 +142,6 @@ QPDF_Array::getJSON(int json_version)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
QPDF_Array::getNItems() const
|
|
||||||
{
|
|
||||||
if (sparse) {
|
|
||||||
// This should really return a size_t, but changing it would break
|
|
||||||
// a lot of code.
|
|
||||||
return QIntC::to_int(sp_elements.size());
|
|
||||||
} else {
|
|
||||||
return QIntC::to_int(elements.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QPDFObjectHandle
|
QPDFObjectHandle
|
||||||
QPDF_Array::getItem(int n) const
|
QPDF_Array::getItem(int n) const
|
||||||
{
|
{
|
||||||
|
@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
int
|
|
||||||
SparseOHArray::size() const
|
|
||||||
{
|
|
||||||
return this->n_elements;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SparseOHArray::append(QPDFObjectHandle oh)
|
SparseOHArray::append(QPDFObjectHandle oh)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,11 @@ class QPDF_Array: public QPDFValue
|
|||||||
virtual JSON getJSON(int json_version);
|
virtual JSON getJSON(int json_version);
|
||||||
virtual void disconnect();
|
virtual void disconnect();
|
||||||
|
|
||||||
int getNItems() const;
|
int
|
||||||
|
size() const noexcept
|
||||||
|
{
|
||||||
|
return sparse ? sp_elements.size() : int(elements.size());
|
||||||
|
}
|
||||||
QPDFObjectHandle getItem(int n) const;
|
QPDFObjectHandle getItem(int n) const;
|
||||||
void getAsVector(std::vector<QPDFObjectHandle>&) const;
|
void getAsVector(std::vector<QPDFObjectHandle>&) const;
|
||||||
|
|
||||||
|
@ -11,7 +11,11 @@ class SparseOHArray
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SparseOHArray() = default;
|
SparseOHArray() = default;
|
||||||
int size() const;
|
int
|
||||||
|
size() const
|
||||||
|
{
|
||||||
|
return n_elements;
|
||||||
|
}
|
||||||
void append(QPDFObjectHandle oh);
|
void append(QPDFObjectHandle oh);
|
||||||
void append(std::shared_ptr<QPDFObject>&& obj);
|
void append(std::shared_ptr<QPDFObject>&& obj);
|
||||||
QPDFObjectHandle at(int idx) const;
|
QPDFObjectHandle at(int idx) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user