Commit 6cbc55a5b5ac4a1c44906ed9dd9ad5c50cd93ea1
Committed by
Jay Berkenbilt
1 parent
b0457b37
Add new virtual method QPDFObject::getStringValue
Avoid dynamic casting.
Showing
13 changed files
with
55 additions
and
66 deletions
libqpdf/QPDFObjectHandle.cc
| @@ -639,9 +639,8 @@ QPDFObjectHandle::getValueAsUInt(unsigned int& value) | @@ -639,9 +639,8 @@ QPDFObjectHandle::getValueAsUInt(unsigned int& value) | ||
| 639 | std::string | 639 | std::string |
| 640 | QPDFObjectHandle::getRealValue() | 640 | QPDFObjectHandle::getRealValue() |
| 641 | { | 641 | { |
| 642 | - auto real = asReal(); | ||
| 643 | - if (real) { | ||
| 644 | - return real->getVal(); | 642 | + if (isReal()) { |
| 643 | + return obj->getStringValue(); | ||
| 645 | } else { | 644 | } else { |
| 646 | typeWarning("real", "returning 0.0"); | 645 | typeWarning("real", "returning 0.0"); |
| 647 | QTC::TC("qpdf", "QPDFObjectHandle real returning 0.0"); | 646 | QTC::TC("qpdf", "QPDFObjectHandle real returning 0.0"); |
| @@ -652,11 +651,10 @@ QPDFObjectHandle::getRealValue() | @@ -652,11 +651,10 @@ QPDFObjectHandle::getRealValue() | ||
| 652 | bool | 651 | bool |
| 653 | QPDFObjectHandle::getValueAsReal(std::string& value) | 652 | QPDFObjectHandle::getValueAsReal(std::string& value) |
| 654 | { | 653 | { |
| 655 | - auto real = asReal(); | ||
| 656 | - if (real == nullptr) { | 654 | + if (!isReal()) { |
| 657 | return false; | 655 | return false; |
| 658 | } | 656 | } |
| 659 | - value = real->getVal(); | 657 | + value = obj->getStringValue(); |
| 660 | return true; | 658 | return true; |
| 661 | } | 659 | } |
| 662 | 660 | ||
| @@ -665,9 +663,8 @@ QPDFObjectHandle::getValueAsReal(std::string& value) | @@ -665,9 +663,8 @@ QPDFObjectHandle::getValueAsReal(std::string& value) | ||
| 665 | std::string | 663 | std::string |
| 666 | QPDFObjectHandle::getName() | 664 | QPDFObjectHandle::getName() |
| 667 | { | 665 | { |
| 668 | - auto name = asName(); | ||
| 669 | - if (name) { | ||
| 670 | - return name->getName(); | 666 | + if (isName()) { |
| 667 | + return obj->getStringValue(); | ||
| 671 | } else { | 668 | } else { |
| 672 | typeWarning("name", "returning dummy name"); | 669 | typeWarning("name", "returning dummy name"); |
| 673 | QTC::TC("qpdf", "QPDFObjectHandle name returning dummy name"); | 670 | QTC::TC("qpdf", "QPDFObjectHandle name returning dummy name"); |
| @@ -678,11 +675,10 @@ QPDFObjectHandle::getName() | @@ -678,11 +675,10 @@ QPDFObjectHandle::getName() | ||
| 678 | bool | 675 | bool |
| 679 | QPDFObjectHandle::getValueAsName(std::string& value) | 676 | QPDFObjectHandle::getValueAsName(std::string& value) |
| 680 | { | 677 | { |
| 681 | - auto name = asName(); | ||
| 682 | - if (name == nullptr) { | 678 | + if (!isName()) { |
| 683 | return false; | 679 | return false; |
| 684 | } | 680 | } |
| 685 | - value = name->getName(); | 681 | + value = obj->getStringValue(); |
| 686 | return true; | 682 | return true; |
| 687 | } | 683 | } |
| 688 | 684 | ||
| @@ -691,9 +687,8 @@ QPDFObjectHandle::getValueAsName(std::string& value) | @@ -691,9 +687,8 @@ QPDFObjectHandle::getValueAsName(std::string& value) | ||
| 691 | std::string | 687 | std::string |
| 692 | QPDFObjectHandle::getStringValue() | 688 | QPDFObjectHandle::getStringValue() |
| 693 | { | 689 | { |
| 694 | - auto str = asString(); | ||
| 695 | - if (str) { | ||
| 696 | - return str->getVal(); | 690 | + if (isString()) { |
| 691 | + return obj->getStringValue(); | ||
| 697 | } else { | 692 | } else { |
| 698 | typeWarning("string", "returning empty string"); | 693 | typeWarning("string", "returning empty string"); |
| 699 | QTC::TC("qpdf", "QPDFObjectHandle string returning empty string"); | 694 | QTC::TC("qpdf", "QPDFObjectHandle string returning empty string"); |
| @@ -704,11 +699,10 @@ QPDFObjectHandle::getStringValue() | @@ -704,11 +699,10 @@ QPDFObjectHandle::getStringValue() | ||
| 704 | bool | 699 | bool |
| 705 | QPDFObjectHandle::getValueAsString(std::string& value) | 700 | QPDFObjectHandle::getValueAsString(std::string& value) |
| 706 | { | 701 | { |
| 707 | - auto str = asString(); | ||
| 708 | - if (str == nullptr) { | 702 | + if (!isString()) { |
| 709 | return false; | 703 | return false; |
| 710 | } | 704 | } |
| 711 | - value = str->getVal(); | 705 | + value = obj->getStringValue(); |
| 712 | return true; | 706 | return true; |
| 713 | } | 707 | } |
| 714 | 708 | ||
| @@ -741,9 +735,8 @@ QPDFObjectHandle::getValueAsUTF8(std::string& value) | @@ -741,9 +735,8 @@ QPDFObjectHandle::getValueAsUTF8(std::string& value) | ||
| 741 | std::string | 735 | std::string |
| 742 | QPDFObjectHandle::getOperatorValue() | 736 | QPDFObjectHandle::getOperatorValue() |
| 743 | { | 737 | { |
| 744 | - auto op = asOperator(); | ||
| 745 | - if (op) { | ||
| 746 | - return op->getVal(); | 738 | + if (isOperator()) { |
| 739 | + return obj->getStringValue(); | ||
| 747 | } else { | 740 | } else { |
| 748 | typeWarning("operator", "returning fake value"); | 741 | typeWarning("operator", "returning fake value"); |
| 749 | QTC::TC("qpdf", "QPDFObjectHandle operator returning fake value"); | 742 | QTC::TC("qpdf", "QPDFObjectHandle operator returning fake value"); |
| @@ -754,20 +747,18 @@ QPDFObjectHandle::getOperatorValue() | @@ -754,20 +747,18 @@ QPDFObjectHandle::getOperatorValue() | ||
| 754 | bool | 747 | bool |
| 755 | QPDFObjectHandle::getValueAsOperator(std::string& value) | 748 | QPDFObjectHandle::getValueAsOperator(std::string& value) |
| 756 | { | 749 | { |
| 757 | - auto op = asOperator(); | ||
| 758 | - if (op == nullptr) { | 750 | + if (!isOperator()) { |
| 759 | return false; | 751 | return false; |
| 760 | } | 752 | } |
| 761 | - value = op->getVal(); | 753 | + value = obj->getStringValue(); |
| 762 | return true; | 754 | return true; |
| 763 | } | 755 | } |
| 764 | 756 | ||
| 765 | std::string | 757 | std::string |
| 766 | QPDFObjectHandle::getInlineImageValue() | 758 | QPDFObjectHandle::getInlineImageValue() |
| 767 | { | 759 | { |
| 768 | - auto image = asInlineImage(); | ||
| 769 | - if (image) { | ||
| 770 | - return image->getVal(); | 760 | + if (isInlineImage()) { |
| 761 | + return obj->getStringValue(); | ||
| 771 | } else { | 762 | } else { |
| 772 | typeWarning("inlineimage", "returning empty data"); | 763 | typeWarning("inlineimage", "returning empty data"); |
| 773 | QTC::TC("qpdf", "QPDFObjectHandle inlineimage returning empty data"); | 764 | QTC::TC("qpdf", "QPDFObjectHandle inlineimage returning empty data"); |
| @@ -778,11 +769,10 @@ QPDFObjectHandle::getInlineImageValue() | @@ -778,11 +769,10 @@ QPDFObjectHandle::getInlineImageValue() | ||
| 778 | bool | 769 | bool |
| 779 | QPDFObjectHandle::getValueAsInlineImage(std::string& value) | 770 | QPDFObjectHandle::getValueAsInlineImage(std::string& value) |
| 780 | { | 771 | { |
| 781 | - auto image = asInlineImage(); | ||
| 782 | - if (image == nullptr) { | 772 | + if (!isInlineImage()) { |
| 783 | return false; | 773 | return false; |
| 784 | } | 774 | } |
| 785 | - value = image->getVal(); | 775 | + value = obj->getStringValue(); |
| 786 | return true; | 776 | return true; |
| 787 | } | 777 | } |
| 788 | 778 |
libqpdf/QPDF_InlineImage.cc
libqpdf/QPDF_Name.cc
libqpdf/QPDF_Operator.cc
libqpdf/QPDF_Real.cc
libqpdf/QPDF_String.cc
| @@ -174,12 +174,6 @@ QPDF_String::unparse(bool force_binary) | @@ -174,12 +174,6 @@ QPDF_String::unparse(bool force_binary) | ||
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | std::string | 176 | std::string |
| 177 | -QPDF_String::getVal() const | ||
| 178 | -{ | ||
| 179 | - return this->val; | ||
| 180 | -} | ||
| 181 | - | ||
| 182 | -std::string | ||
| 183 | QPDF_String::getUTF8Val() const | 177 | QPDF_String::getUTF8Val() const |
| 184 | { | 178 | { |
| 185 | if (QUtil::is_utf16(this->val)) { | 179 | if (QUtil::is_utf16(this->val)) { |
libqpdf/qpdf/QPDFObject_private.hh
| @@ -38,7 +38,11 @@ class QPDFObject | @@ -38,7 +38,11 @@ class QPDFObject | ||
| 38 | { | 38 | { |
| 39 | return value->getJSON(json_version); | 39 | return value->getJSON(json_version); |
| 40 | } | 40 | } |
| 41 | - | 41 | + std::string |
| 42 | + getStringValue() const | ||
| 43 | + { | ||
| 44 | + return value->getStringValue(); | ||
| 45 | + } | ||
| 42 | // Return a unique type code for the object | 46 | // Return a unique type code for the object |
| 43 | qpdf_object_type_e | 47 | qpdf_object_type_e |
| 44 | getTypeCode() const | 48 | getTypeCode() const |
libqpdf/qpdf/QPDFValue.hh
libqpdf/qpdf/QPDF_InlineImage.hh
| @@ -11,7 +11,11 @@ class QPDF_InlineImage: public QPDFValue | @@ -11,7 +11,11 @@ class QPDF_InlineImage: public QPDFValue | ||
| 11 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 11 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 12 | virtual std::string unparse(); | 12 | virtual std::string unparse(); |
| 13 | virtual JSON getJSON(int json_version); | 13 | virtual JSON getJSON(int json_version); |
| 14 | - std::string getVal() const; | 14 | + virtual std::string |
| 15 | + getStringValue() const | ||
| 16 | + { | ||
| 17 | + return val; | ||
| 18 | + } | ||
| 15 | 19 | ||
| 16 | private: | 20 | private: |
| 17 | QPDF_InlineImage(std::string const& val); | 21 | QPDF_InlineImage(std::string const& val); |
libqpdf/qpdf/QPDF_Name.hh
| @@ -11,10 +11,14 @@ class QPDF_Name: public QPDFValue | @@ -11,10 +11,14 @@ class QPDF_Name: public QPDFValue | ||
| 11 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 11 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 12 | virtual std::string unparse(); | 12 | virtual std::string unparse(); |
| 13 | virtual JSON getJSON(int json_version); | 13 | virtual JSON getJSON(int json_version); |
| 14 | - std::string getName() const; | ||
| 15 | 14 | ||
| 16 | // Put # into strings with characters unsuitable for name token | 15 | // Put # into strings with characters unsuitable for name token |
| 17 | static std::string normalizeName(std::string const& name); | 16 | static std::string normalizeName(std::string const& name); |
| 17 | + virtual std::string | ||
| 18 | + getStringValue() const | ||
| 19 | + { | ||
| 20 | + return name; | ||
| 21 | + } | ||
| 18 | 22 | ||
| 19 | private: | 23 | private: |
| 20 | QPDF_Name(std::string const& name); | 24 | QPDF_Name(std::string const& name); |
libqpdf/qpdf/QPDF_Operator.hh
| @@ -11,7 +11,11 @@ class QPDF_Operator: public QPDFValue | @@ -11,7 +11,11 @@ class QPDF_Operator: public QPDFValue | ||
| 11 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 11 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 12 | virtual std::string unparse(); | 12 | virtual std::string unparse(); |
| 13 | virtual JSON getJSON(int json_version); | 13 | virtual JSON getJSON(int json_version); |
| 14 | - std::string getVal() const; | 14 | + virtual std::string |
| 15 | + getStringValue() const | ||
| 16 | + { | ||
| 17 | + return val; | ||
| 18 | + } | ||
| 15 | 19 | ||
| 16 | private: | 20 | private: |
| 17 | QPDF_Operator(std::string const& val); | 21 | QPDF_Operator(std::string const& val); |
libqpdf/qpdf/QPDF_Real.hh
| @@ -13,7 +13,11 @@ class QPDF_Real: public QPDFValue | @@ -13,7 +13,11 @@ class QPDF_Real: public QPDFValue | ||
| 13 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 13 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 14 | virtual std::string unparse(); | 14 | virtual std::string unparse(); |
| 15 | virtual JSON getJSON(int json_version); | 15 | virtual JSON getJSON(int json_version); |
| 16 | - std::string getVal(); | 16 | + virtual std::string |
| 17 | + getStringValue() const | ||
| 18 | + { | ||
| 19 | + return val; | ||
| 20 | + } | ||
| 17 | 21 | ||
| 18 | private: | 22 | private: |
| 19 | QPDF_Real(std::string const& val); | 23 | QPDF_Real(std::string const& val); |
libqpdf/qpdf/QPDF_String.hh
| @@ -18,8 +18,12 @@ class QPDF_String: public QPDFValue | @@ -18,8 +18,12 @@ class QPDF_String: public QPDFValue | ||
| 18 | virtual std::string unparse(); | 18 | virtual std::string unparse(); |
| 19 | std::string unparse(bool force_binary); | 19 | std::string unparse(bool force_binary); |
| 20 | virtual JSON getJSON(int json_version); | 20 | virtual JSON getJSON(int json_version); |
| 21 | - std::string getVal() const; | ||
| 22 | std::string getUTF8Val() const; | 21 | std::string getUTF8Val() const; |
| 22 | + virtual std::string | ||
| 23 | + getStringValue() const | ||
| 24 | + { | ||
| 25 | + return val; | ||
| 26 | + } | ||
| 23 | 27 | ||
| 24 | private: | 28 | private: |
| 25 | QPDF_String(std::string const& val); | 29 | QPDF_String(std::string const& val); |