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