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