Commit 64f9b7b2425cc603549fcea8ce10b6261e169ffa
1 parent
0a6ab106
Refactor QPDFObjectHandle::getTypeName
Showing
17 changed files
with
42 additions
and
35 deletions
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -30,6 +30,7 @@ |
| 30 | 30 | #include <qpdf/QUtil.hh> |
| 31 | 31 | |
| 32 | 32 | #include <algorithm> |
| 33 | +#include <array> | |
| 33 | 34 | #include <cctype> |
| 34 | 35 | #include <climits> |
| 35 | 36 | #include <cstdlib> |
| ... | ... | @@ -263,7 +264,23 @@ char const* |
| 263 | 264 | QPDFObjectHandle::getTypeName() const |
| 264 | 265 | #endif |
| 265 | 266 | { |
| 266 | - return obj ? obj->getTypeName() : "uninitialized"; | |
| 267 | + static constexpr std::array<char const*, 15> tn{ | |
| 268 | + "uninitialized", | |
| 269 | + "reserved", | |
| 270 | + "null", | |
| 271 | + "boolean", | |
| 272 | + "integer", | |
| 273 | + "real", | |
| 274 | + "string", | |
| 275 | + "name", | |
| 276 | + "array", | |
| 277 | + "dictionary", | |
| 278 | + "stream", | |
| 279 | + "operator", | |
| 280 | + "inline-image", | |
| 281 | + "unresolved", | |
| 282 | + "destroyed"}; | |
| 283 | + return obj ? tn[getTypeCode()] : "uninitialized"; | |
| 267 | 284 | } |
| 268 | 285 | |
| 269 | 286 | QPDF_Array* |
| ... | ... | @@ -2528,7 +2545,7 @@ QPDFObjectHandle::typeWarning(char const* expected_type, std::string const& warn |
| 2528 | 2545 | description, |
| 2529 | 2546 | 0, |
| 2530 | 2547 | std::string("operation for ") + expected_type + " attempted on object of type " + |
| 2531 | - obj->getTypeName() + ": " + warning)); | |
| 2548 | + QPDFObjectHandle(*this).getTypeName() + ": " + warning)); | |
| 2532 | 2549 | } |
| 2533 | 2550 | |
| 2534 | 2551 | #ifndef QPDF_FUTURE |
| ... | ... | @@ -2565,7 +2582,7 @@ QPDFObjectHandle::assertType(char const* type_name, bool istype) const |
| 2565 | 2582 | if (!istype) { |
| 2566 | 2583 | throw std::runtime_error( |
| 2567 | 2584 | std::string("operation for ") + type_name + " attempted on object of type " + |
| 2568 | - (obj ? obj->getTypeName() : "uninitialized")); | |
| 2585 | + QPDFObjectHandle(*this).getTypeName()); | |
| 2569 | 2586 | } |
| 2570 | 2587 | } |
| 2571 | 2588 | ... | ... |
libqpdf/QPDF_Array.cc
| ... | ... | @@ -26,24 +26,24 @@ QPDF_Array::checkOwnership(QPDFObjectHandle const& item) const |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | QPDF_Array::QPDF_Array() : |
| 29 | - QPDFValue(::ot_array, "array") | |
| 29 | + QPDFValue(::ot_array) | |
| 30 | 30 | { |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | QPDF_Array::QPDF_Array(QPDF_Array const& other) : |
| 34 | - QPDFValue(::ot_array, "array"), | |
| 34 | + QPDFValue(::ot_array), | |
| 35 | 35 | sp(other.sp ? std::make_unique<Sparse>(*other.sp) : nullptr) |
| 36 | 36 | { |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | QPDF_Array::QPDF_Array(std::vector<QPDFObjectHandle> const& v) : |
| 40 | - QPDFValue(::ot_array, "array") | |
| 40 | + QPDFValue(::ot_array) | |
| 41 | 41 | { |
| 42 | 42 | setFromVector(v); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | QPDF_Array::QPDF_Array(std::vector<std::shared_ptr<QPDFObject>>&& v, bool sparse) : |
| 46 | - QPDFValue(::ot_array, "array") | |
| 46 | + QPDFValue(::ot_array) | |
| 47 | 47 | { |
| 48 | 48 | if (sparse) { |
| 49 | 49 | sp = std::make_unique<Sparse>(); | ... | ... |
libqpdf/QPDF_Bool.cc
libqpdf/QPDF_Destroyed.cc
libqpdf/QPDF_Dictionary.cc
| ... | ... | @@ -9,13 +9,13 @@ |
| 9 | 9 | using namespace std::literals; |
| 10 | 10 | |
| 11 | 11 | QPDF_Dictionary::QPDF_Dictionary(std::map<std::string, QPDFObjectHandle> const& items) : |
| 12 | - QPDFValue(::ot_dictionary, "dictionary"), | |
| 12 | + QPDFValue(::ot_dictionary), | |
| 13 | 13 | items(items) |
| 14 | 14 | { |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | QPDF_Dictionary::QPDF_Dictionary(std::map<std::string, QPDFObjectHandle>&& items) : |
| 18 | - QPDFValue(::ot_dictionary, "dictionary"), | |
| 18 | + QPDFValue(::ot_dictionary), | |
| 19 | 19 | items(items) |
| 20 | 20 | { |
| 21 | 21 | } | ... | ... |
libqpdf/QPDF_InlineImage.cc
libqpdf/QPDF_Integer.cc
libqpdf/QPDF_Name.cc
libqpdf/QPDF_Null.cc
libqpdf/QPDF_Operator.cc
libqpdf/QPDF_Real.cc
| ... | ... | @@ -4,13 +4,13 @@ |
| 4 | 4 | #include <qpdf/QUtil.hh> |
| 5 | 5 | |
| 6 | 6 | QPDF_Real::QPDF_Real(std::string const& val) : |
| 7 | - QPDFValue(::ot_real, "real"), | |
| 7 | + QPDFValue(::ot_real), | |
| 8 | 8 | val(val) |
| 9 | 9 | { |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | QPDF_Real::QPDF_Real(double value, int decimal_places, bool trim_trailing_zeroes) : |
| 13 | - QPDFValue(::ot_real, "real"), | |
| 13 | + QPDFValue(::ot_real), | |
| 14 | 14 | val(QUtil::double_to_string(value, decimal_places, trim_trailing_zeroes)) |
| 15 | 15 | { |
| 16 | 16 | } | ... | ... |
libqpdf/QPDF_Reserved.cc
libqpdf/QPDF_Stream.cc
| ... | ... | @@ -112,7 +112,7 @@ QPDF_Stream::QPDF_Stream( |
| 112 | 112 | QPDFObjectHandle stream_dict, |
| 113 | 113 | qpdf_offset_t offset, |
| 114 | 114 | size_t length) : |
| 115 | - QPDFValue(::ot_stream, "stream"), | |
| 115 | + QPDFValue(::ot_stream), | |
| 116 | 116 | filter_on_write(true), |
| 117 | 117 | stream_dict(stream_dict), |
| 118 | 118 | length(length) | ... | ... |
libqpdf/QPDF_String.cc
libqpdf/QPDF_Unresolved.cc
libqpdf/qpdf/QPDFObject_private.hh
| ... | ... | @@ -58,12 +58,6 @@ class QPDFObject |
| 58 | 58 | { |
| 59 | 59 | return value->type_code; |
| 60 | 60 | } |
| 61 | - // Return a string literal that describes the type, useful for debugging and testing | |
| 62 | - char const* | |
| 63 | - getTypeName() const | |
| 64 | - { | |
| 65 | - return resolved_object()->value->type_name; | |
| 66 | - } | |
| 67 | 61 | |
| 68 | 62 | QPDF* |
| 69 | 63 | getQPDF() const | ... | ... |
libqpdf/qpdf/QPDFValue.hh
| ... | ... | @@ -122,15 +122,12 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> |
| 122 | 122 | protected: |
| 123 | 123 | QPDFValue() = default; |
| 124 | 124 | |
| 125 | - QPDFValue(qpdf_object_type_e type_code, char const* type_name) : | |
| 126 | - type_code(type_code), | |
| 127 | - type_name(type_name) | |
| 125 | + QPDFValue(qpdf_object_type_e type_code) : | |
| 126 | + type_code(type_code) | |
| 128 | 127 | { |
| 129 | 128 | } |
| 130 | - QPDFValue( | |
| 131 | - qpdf_object_type_e type_code, char const* type_name, QPDF* qpdf, QPDFObjGen const& og) : | |
| 129 | + QPDFValue(qpdf_object_type_e type_code, QPDF* qpdf, QPDFObjGen og) : | |
| 132 | 130 | type_code(type_code), |
| 133 | - type_name(type_name), | |
| 134 | 131 | qpdf(qpdf), |
| 135 | 132 | og(og) |
| 136 | 133 | { |
| ... | ... | @@ -144,7 +141,6 @@ class QPDFValue: public std::enable_shared_from_this<QPDFValue> |
| 144 | 141 | std::shared_ptr<Description> object_description; |
| 145 | 142 | |
| 146 | 143 | const qpdf_object_type_e type_code{::ot_uninitialized}; |
| 147 | - char const* type_name{"uninitialized"}; | |
| 148 | 144 | |
| 149 | 145 | protected: |
| 150 | 146 | QPDF* qpdf{nullptr}; | ... | ... |