mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Add new virtual method QPDFObject::getStringValue
Avoid dynamic casting.
This commit is contained in:
parent
b0457b37e2
commit
6cbc55a5b5
@ -639,9 +639,8 @@ QPDFObjectHandle::getValueAsUInt(unsigned int& value)
|
||||
std::string
|
||||
QPDFObjectHandle::getRealValue()
|
||||
{
|
||||
auto real = asReal();
|
||||
if (real) {
|
||||
return real->getVal();
|
||||
if (isReal()) {
|
||||
return obj->getStringValue();
|
||||
} else {
|
||||
typeWarning("real", "returning 0.0");
|
||||
QTC::TC("qpdf", "QPDFObjectHandle real returning 0.0");
|
||||
@ -652,11 +651,10 @@ QPDFObjectHandle::getRealValue()
|
||||
bool
|
||||
QPDFObjectHandle::getValueAsReal(std::string& value)
|
||||
{
|
||||
auto real = asReal();
|
||||
if (real == nullptr) {
|
||||
if (!isReal()) {
|
||||
return false;
|
||||
}
|
||||
value = real->getVal();
|
||||
value = obj->getStringValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -665,9 +663,8 @@ QPDFObjectHandle::getValueAsReal(std::string& value)
|
||||
std::string
|
||||
QPDFObjectHandle::getName()
|
||||
{
|
||||
auto name = asName();
|
||||
if (name) {
|
||||
return name->getName();
|
||||
if (isName()) {
|
||||
return obj->getStringValue();
|
||||
} else {
|
||||
typeWarning("name", "returning dummy name");
|
||||
QTC::TC("qpdf", "QPDFObjectHandle name returning dummy name");
|
||||
@ -678,11 +675,10 @@ QPDFObjectHandle::getName()
|
||||
bool
|
||||
QPDFObjectHandle::getValueAsName(std::string& value)
|
||||
{
|
||||
auto name = asName();
|
||||
if (name == nullptr) {
|
||||
if (!isName()) {
|
||||
return false;
|
||||
}
|
||||
value = name->getName();
|
||||
value = obj->getStringValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -691,9 +687,8 @@ QPDFObjectHandle::getValueAsName(std::string& value)
|
||||
std::string
|
||||
QPDFObjectHandle::getStringValue()
|
||||
{
|
||||
auto str = asString();
|
||||
if (str) {
|
||||
return str->getVal();
|
||||
if (isString()) {
|
||||
return obj->getStringValue();
|
||||
} else {
|
||||
typeWarning("string", "returning empty string");
|
||||
QTC::TC("qpdf", "QPDFObjectHandle string returning empty string");
|
||||
@ -704,11 +699,10 @@ QPDFObjectHandle::getStringValue()
|
||||
bool
|
||||
QPDFObjectHandle::getValueAsString(std::string& value)
|
||||
{
|
||||
auto str = asString();
|
||||
if (str == nullptr) {
|
||||
if (!isString()) {
|
||||
return false;
|
||||
}
|
||||
value = str->getVal();
|
||||
value = obj->getStringValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -741,9 +735,8 @@ QPDFObjectHandle::getValueAsUTF8(std::string& value)
|
||||
std::string
|
||||
QPDFObjectHandle::getOperatorValue()
|
||||
{
|
||||
auto op = asOperator();
|
||||
if (op) {
|
||||
return op->getVal();
|
||||
if (isOperator()) {
|
||||
return obj->getStringValue();
|
||||
} else {
|
||||
typeWarning("operator", "returning fake value");
|
||||
QTC::TC("qpdf", "QPDFObjectHandle operator returning fake value");
|
||||
@ -754,20 +747,18 @@ QPDFObjectHandle::getOperatorValue()
|
||||
bool
|
||||
QPDFObjectHandle::getValueAsOperator(std::string& value)
|
||||
{
|
||||
auto op = asOperator();
|
||||
if (op == nullptr) {
|
||||
if (!isOperator()) {
|
||||
return false;
|
||||
}
|
||||
value = op->getVal();
|
||||
value = obj->getStringValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string
|
||||
QPDFObjectHandle::getInlineImageValue()
|
||||
{
|
||||
auto image = asInlineImage();
|
||||
if (image) {
|
||||
return image->getVal();
|
||||
if (isInlineImage()) {
|
||||
return obj->getStringValue();
|
||||
} else {
|
||||
typeWarning("inlineimage", "returning empty data");
|
||||
QTC::TC("qpdf", "QPDFObjectHandle inlineimage returning empty data");
|
||||
@ -778,11 +769,10 @@ QPDFObjectHandle::getInlineImageValue()
|
||||
bool
|
||||
QPDFObjectHandle::getValueAsInlineImage(std::string& value)
|
||||
{
|
||||
auto image = asInlineImage();
|
||||
if (image == nullptr) {
|
||||
if (!isInlineImage()) {
|
||||
return false;
|
||||
}
|
||||
value = image->getVal();
|
||||
value = obj->getStringValue();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,3 @@ QPDF_InlineImage::getJSON(int json_version)
|
||||
{
|
||||
return JSON::makeNull();
|
||||
}
|
||||
|
||||
std::string
|
||||
QPDF_InlineImage::getVal() const
|
||||
{
|
||||
return this->val;
|
||||
}
|
||||
|
@ -61,9 +61,3 @@ QPDF_Name::getJSON(int json_version)
|
||||
return JSON::makeString(this->name);
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
QPDF_Name::getName() const
|
||||
{
|
||||
return this->name;
|
||||
}
|
||||
|
@ -29,9 +29,3 @@ QPDF_Operator::getJSON(int json_version)
|
||||
{
|
||||
return JSON::makeNull();
|
||||
}
|
||||
|
||||
std::string
|
||||
QPDF_Operator::getVal() const
|
||||
{
|
||||
return this->val;
|
||||
}
|
||||
|
@ -61,9 +61,3 @@ QPDF_Real::getJSON(int json_version)
|
||||
}
|
||||
return JSON::makeNumber(result);
|
||||
}
|
||||
|
||||
std::string
|
||||
QPDF_Real::getVal()
|
||||
{
|
||||
return this->val;
|
||||
}
|
||||
|
@ -173,12 +173,6 @@ QPDF_String::unparse(bool force_binary)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string
|
||||
QPDF_String::getVal() const
|
||||
{
|
||||
return this->val;
|
||||
}
|
||||
|
||||
std::string
|
||||
QPDF_String::getUTF8Val() const
|
||||
{
|
||||
|
@ -38,7 +38,11 @@ class QPDFObject
|
||||
{
|
||||
return value->getJSON(json_version);
|
||||
}
|
||||
|
||||
std::string
|
||||
getStringValue() const
|
||||
{
|
||||
return value->getStringValue();
|
||||
}
|
||||
// Return a unique type code for the object
|
||||
qpdf_object_type_e
|
||||
getTypeCode() const
|
||||
|
@ -67,6 +67,11 @@ class QPDFValue
|
||||
disconnect()
|
||||
{
|
||||
}
|
||||
virtual std::string
|
||||
getStringValue() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
protected:
|
||||
QPDFValue() = default;
|
||||
|
@ -11,7 +11,11 @@ class QPDF_InlineImage: public QPDFValue
|
||||
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON(int json_version);
|
||||
std::string getVal() const;
|
||||
virtual std::string
|
||||
getStringValue() const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
private:
|
||||
QPDF_InlineImage(std::string const& val);
|
||||
|
@ -11,10 +11,14 @@ class QPDF_Name: public QPDFValue
|
||||
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON(int json_version);
|
||||
std::string getName() const;
|
||||
|
||||
// Put # into strings with characters unsuitable for name token
|
||||
static std::string normalizeName(std::string const& name);
|
||||
virtual std::string
|
||||
getStringValue() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
private:
|
||||
QPDF_Name(std::string const& name);
|
||||
|
@ -11,7 +11,11 @@ class QPDF_Operator: public QPDFValue
|
||||
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON(int json_version);
|
||||
std::string getVal() const;
|
||||
virtual std::string
|
||||
getStringValue() const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
private:
|
||||
QPDF_Operator(std::string const& val);
|
||||
|
@ -13,7 +13,11 @@ class QPDF_Real: public QPDFValue
|
||||
virtual std::shared_ptr<QPDFObject> copy(bool shallow = false);
|
||||
virtual std::string unparse();
|
||||
virtual JSON getJSON(int json_version);
|
||||
std::string getVal();
|
||||
virtual std::string
|
||||
getStringValue() const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
private:
|
||||
QPDF_Real(std::string const& val);
|
||||
|
@ -18,8 +18,12 @@ class QPDF_String: public QPDFValue
|
||||
virtual std::string unparse();
|
||||
std::string unparse(bool force_binary);
|
||||
virtual JSON getJSON(int json_version);
|
||||
std::string getVal() const;
|
||||
std::string getUTF8Val() const;
|
||||
virtual std::string
|
||||
getStringValue() const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
private:
|
||||
QPDF_String(std::string const& val);
|
||||
|
Loading…
Reference in New Issue
Block a user