summaryrefslogtreecommitdiff
path: root/poppler/Object.h
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2019-10-27 17:37:58 +0100
committerAlbert Astals Cid <tsdgeos@yahoo.es>2019-10-30 21:34:31 +0000
commit647274f118222cce978b3a79a50ad222d003d133 (patch)
treeaf961d7ffee69b74b0bd8dba7564d073c6ac2e33 /poppler/Object.h
parentaa7827ab29377ef00c2dfbb16082617690375513 (diff)
Introduce Object::getNumWithDefaultValue
Is like getNum but instead of asserting if Object is not a num it returns the given default value I find it much easier to read rect->x1 = obj1.arrayGet(0).getNumWithDefaultValue(0); than (obj2 = obj1.arrayGet(0), obj2.isNum() ? rect->x1 = obj2.getNum() : rect->x1 = 0); On top of it has the benefit of being slightly faster
Diffstat (limited to 'poppler/Object.h')
-rw-r--r--poppler/Object.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/poppler/Object.h b/poppler/Object.h
index 77ae34bf..c01a191f 100644
--- a/poppler/Object.h
+++ b/poppler/Object.h
@@ -307,6 +307,13 @@ public:
const char *getTypeName() const;
void print(FILE *f = stdout) const;
+ double getNumWithDefaultValue(double defaultValue) const {
+ if (unlikely(type != objInt && type != objInt64 && type != objReal)) {
+ return defaultValue;
+ }
+ return type == objInt ? (double)intg : type == objInt64 ? (double)int64g : real;
+ }
+
private:
// Free object contents.
void free();