[poppler] goo/GooString.cc goo/GooString.h poppler/Array.cc poppler/Array.h poppler/Dict.cc poppler/Dict.h poppler/Object.cc poppler/Object.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Thu Sep 21 18:32:47 UTC 2017
goo/GooString.cc | 2
goo/GooString.h | 2
poppler/Array.cc | 8 +-
poppler/Array.h | 12 ++--
poppler/Dict.cc | 18 +++---
poppler/Dict.h | 26 ++++-----
poppler/Object.cc | 4 -
poppler/Object.h | 152 +++++++++++++++++++++++++++---------------------------
8 files changed, 112 insertions(+), 112 deletions(-)
New commits:
commit 1a33f60da2996ea64c1b903580885697940cf046
Author: Albert Astals Cid <aacid at kde.org>
Date: Thu Sep 21 20:32:25 2017 +0200
Add some constness to the basic classes
diff --git a/goo/GooString.cc b/goo/GooString.cc
index f76e7d14..10976e87 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -923,7 +923,7 @@ void GooString::prependUnicodeMarker()
insert(0, (char)0xfe);
}
-GooString *GooString::sanitizedName(GBool psmode)
+GooString *GooString::sanitizedName(GBool psmode) const
{
GooString *name;
char buf[8];
diff --git a/goo/GooString.h b/goo/GooString.h
index 5d17ec80..a5418c3d 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -168,7 +168,7 @@ public:
// not contain any ( ) < > [ ] { } / %
// The postscript mode also has some more strict checks
// The caller owns the return value
- GooString *sanitizedName(GBool psmode);
+ GooString *sanitizedName(GBool psmode) const;
private:
GooString(const GooString &other);
diff --git a/poppler/Array.cc b/poppler/Array.cc
index c2c4040d..94b8d66a 100644
--- a/poppler/Array.cc
+++ b/poppler/Array.cc
@@ -65,7 +65,7 @@ Array::~Array() {
#endif
}
-Object Array::copy(XRef *xrefA) {
+Object Array::copy(XRef *xrefA) const {
arrayLocker();
Array *a = new Array(xrefA);
for (int i = 0; i < length; ++i) {
@@ -114,7 +114,7 @@ void Array::remove(int i) {
memmove( elems + i, elems + i + 1, sizeof(elems[0]) * (length - i) );
}
-Object Array::get(int i, int recursion) {
+Object Array::get(int i, int recursion) const {
if (i < 0 || i >= length) {
#ifdef DEBUG_MEM
abort();
@@ -125,7 +125,7 @@ Object Array::get(int i, int recursion) {
return elems[i].fetch(xref, recursion);
}
-Object Array::getNF(int i) {
+Object Array::getNF(int i) const {
if (i < 0 || i >= length) {
#ifdef DEBUG_MEM
abort();
@@ -136,7 +136,7 @@ Object Array::getNF(int i) {
return elems[i].copy();
}
-GBool Array::getString(int i, GooString *string)
+GBool Array::getString(int i, GooString *string) const
{
Object obj = getNF(i);
if (obj.isString()) {
diff --git a/poppler/Array.h b/poppler/Array.h
index 8043c830..d2cdf65f 100644
--- a/poppler/Array.h
+++ b/poppler/Array.h
@@ -50,10 +50,10 @@ public:
~Array();
// Get number of elements.
- int getLength() { return length; }
+ int getLength() const { return length; }
// Copy array with new xref
- Object copy(XRef *xrefA);
+ Object copy(XRef *xrefA) const;
// Add an element
// elem becomes a dead object after this call
@@ -63,9 +63,9 @@ public:
void remove(int i);
// Accessors.
- Object get(int i, int resursion = 0);
- Object getNF(int i);
- GBool getString(int i, GooString *string);
+ Object get(int i, int resursion = 0) const;
+ Object getNF(int i) const;
+ GBool getString(int i, GooString *string) const;
private:
friend class Object; // for incRef/decRef
@@ -80,7 +80,7 @@ private:
int length; // number of elements in array
int ref; // reference count
#if MULTITHREADED
- GooMutex mutex;
+ mutable GooMutex mutex;
#endif
};
diff --git a/poppler/Dict.cc b/poppler/Dict.cc
index 5c231d14..2bd86abf 100644
--- a/poppler/Dict.cc
+++ b/poppler/Dict.cc
@@ -163,7 +163,7 @@ void Dict::add(char *key, Object &&val) {
++length;
}
-inline DictEntry *Dict::find(const char *key) {
+inline DictEntry *Dict::find(const char *key) const {
if (!sorted && length >= SORT_LENGTH_LOWER_LIMIT)
{
dictLocker();
@@ -187,7 +187,7 @@ inline DictEntry *Dict::find(const char *key) {
return NULL;
}
-GBool Dict::hasKey(const char *key) {
+GBool Dict::hasKey(const char *key) const {
return find(key) != NULL;
}
@@ -247,25 +247,25 @@ void Dict::set(const char *key, Object &&val) {
}
-GBool Dict::is(const char *type) {
+GBool Dict::is(const char *type) const {
DictEntry *e;
return (e = find("Type")) && e->val.isName(type);
}
-Object Dict::lookup(const char *key, int recursion) {
+Object Dict::lookup(const char *key, int recursion) const {
DictEntry *e;
return (e = find(key)) ? e->val.fetch(xref, recursion) : Object(objNull);
}
-Object Dict::lookupNF(const char *key) {
+Object Dict::lookupNF(const char *key) const {
DictEntry *e;
return (e = find(key)) ? e->val.copy() : Object(objNull);
}
-GBool Dict::lookupInt(const char *key, const char *alt_key, int *value)
+GBool Dict::lookupInt(const char *key, const char *alt_key, int *value) const
{
GBool success = gFalse;
Object obj1 = lookup ((char *) key);
@@ -283,14 +283,14 @@ GBool Dict::lookupInt(const char *key, const char *alt_key, int *value)
return success;
}
-char *Dict::getKey(int i) {
+char *Dict::getKey(int i) const {
return entries[i].key;
}
-Object Dict::getVal(int i) {
+Object Dict::getVal(int i) const {
return entries[i].val.fetch(xref);
}
-Object Dict::getValNF(int i) {
+Object Dict::getValNF(int i) const {
return entries[i].val.copy();
}
diff --git a/poppler/Dict.h b/poppler/Dict.h
index b775a574..1b922b0e 100644
--- a/poppler/Dict.h
+++ b/poppler/Dict.h
@@ -57,7 +57,7 @@ public:
~Dict();
// Get number of entries.
- int getLength() { return length; }
+ int getLength() const { return length; }
// Add an entry. NB: does not copy key.
// val becomes a dead object after the call
@@ -70,27 +70,27 @@ public:
void remove(const char *key);
// Check if dictionary is of specified type.
- GBool is(const char *type);
+ GBool is(const char *type) const;
// Look up an entry and return the value. Returns a null object
// if <key> is not in the dictionary.
- Object lookup(const char *key, int recursion = 0);
- Object lookupNF(const char *key);
- GBool lookupInt(const char *key, const char *alt_key, int *value);
+ Object lookup(const char *key, int recursion = 0) const;
+ Object lookupNF(const char *key) const;
+ GBool lookupInt(const char *key, const char *alt_key, int *value) const;
// Iterative accessors.
- char *getKey(int i);
- Object getVal(int i);
- Object getValNF(int i);
+ char *getKey(int i) const;
+ Object getVal(int i) const;
+ Object getValNF(int i) const;
// Set the xref pointer. This is only used in one special case: the
// trailer dictionary, which is read before the xref table is
// parsed.
void setXRef(XRef *xrefA) { xref = xrefA; }
- XRef *getXRef() { return xref; }
+ XRef *getXRef() const { return xref; }
- GBool hasKey(const char *key);
+ GBool hasKey(const char *key) const;
private:
friend class Object; // for incRef/decRef
@@ -99,17 +99,17 @@ private:
int incRef();
int decRef();
- GBool sorted;
+ mutable GBool sorted;
XRef *xref; // the xref table for this PDF file
DictEntry *entries; // array of entries
int size; // size of <entries> array
int length; // number of entries in dictionary
int ref; // reference count
#if MULTITHREADED
- GooMutex mutex;
+ mutable GooMutex mutex;
#endif
- DictEntry *find(const char *key);
+ DictEntry *find(const char *key) const;
};
#endif
diff --git a/poppler/Object.cc b/poppler/Object.cc
index 4fce012d..d3adc447 100644
--- a/poppler/Object.cc
+++ b/poppler/Object.cc
@@ -160,11 +160,11 @@ void Object::free() {
type = objNone;
}
-const char *Object::getTypeName() {
+const char *Object::getTypeName() const {
return objTypeNames[type];
}
-void Object::print(FILE *f) {
+void Object::print(FILE *f) const {
Object obj;
int i;
diff --git a/poppler/Object.h b/poppler/Object.h
index 23c98a9e..8b18af68 100644
--- a/poppler/Object.h
+++ b/poppler/Object.h
@@ -184,100 +184,100 @@ public:
Object fetch(XRef *xref, int recursion = 0) const;
// Type checking.
- ObjType getType() { CHECK_NOT_DEAD; return type; }
- GBool isBool() { CHECK_NOT_DEAD; return type == objBool; }
- GBool isInt() { CHECK_NOT_DEAD; return type == objInt; }
- GBool isReal() { CHECK_NOT_DEAD; return type == objReal; }
- GBool isNum() { CHECK_NOT_DEAD; return type == objInt || type == objReal || type == objInt64; }
- GBool isString() { CHECK_NOT_DEAD; return type == objString; }
- GBool isName() { CHECK_NOT_DEAD; return type == objName; }
- GBool isNull() { CHECK_NOT_DEAD; return type == objNull; }
- GBool isArray() { CHECK_NOT_DEAD; return type == objArray; }
- GBool isDict() { CHECK_NOT_DEAD; return type == objDict; }
- GBool isStream() { CHECK_NOT_DEAD; return type == objStream; }
- GBool isRef() { CHECK_NOT_DEAD; return type == objRef; }
- GBool isCmd() { CHECK_NOT_DEAD; return type == objCmd; }
- GBool isError() { CHECK_NOT_DEAD; return type == objError; }
- GBool isEOF() { CHECK_NOT_DEAD; return type == objEOF; }
- GBool isNone() { CHECK_NOT_DEAD; return type == objNone; }
- GBool isInt64() { CHECK_NOT_DEAD; return type == objInt64; }
- GBool isIntOrInt64() { CHECK_NOT_DEAD; return type == objInt || type == objInt64; }
+ ObjType getType() const { CHECK_NOT_DEAD; return type; }
+ GBool isBool() const { CHECK_NOT_DEAD; return type == objBool; }
+ GBool isInt() const { CHECK_NOT_DEAD; return type == objInt; }
+ GBool isReal() const { CHECK_NOT_DEAD; return type == objReal; }
+ GBool isNum() const { CHECK_NOT_DEAD; return type == objInt || type == objReal || type == objInt64; }
+ GBool isString() const { CHECK_NOT_DEAD; return type == objString; }
+ GBool isName() const { CHECK_NOT_DEAD; return type == objName; }
+ GBool isNull() const { CHECK_NOT_DEAD; return type == objNull; }
+ GBool isArray() const { CHECK_NOT_DEAD; return type == objArray; }
+ GBool isDict() const { CHECK_NOT_DEAD; return type == objDict; }
+ GBool isStream() const { CHECK_NOT_DEAD; return type == objStream; }
+ GBool isRef() const { CHECK_NOT_DEAD; return type == objRef; }
+ GBool isCmd() const { CHECK_NOT_DEAD; return type == objCmd; }
+ GBool isError() const { CHECK_NOT_DEAD; return type == objError; }
+ GBool isEOF() const { CHECK_NOT_DEAD; return type == objEOF; }
+ GBool isNone() const { CHECK_NOT_DEAD; return type == objNone; }
+ GBool isInt64() const { CHECK_NOT_DEAD; return type == objInt64; }
+ GBool isIntOrInt64() const { CHECK_NOT_DEAD; return type == objInt || type == objInt64; }
// Special type checking.
- GBool isName(const char *nameA)
+ GBool isName(const char *nameA) const
{ return type == objName && !strcmp(cString, nameA); }
- GBool isDict(const char *dictType);
- GBool isStream(char *dictType);
- GBool isCmd(const char *cmdA)
+ GBool isDict(const char *dictType) const;
+ GBool isStream(char *dictType) const;
+ GBool isCmd(const char *cmdA) const
{ return type == objCmd && !strcmp(cString, cmdA); }
// Accessors.
- GBool getBool() { OBJECT_TYPE_CHECK(objBool); return booln; }
- int getInt() { OBJECT_TYPE_CHECK(objInt); return intg; }
- double getReal() { OBJECT_TYPE_CHECK(objReal); return real; }
+ GBool getBool() const { OBJECT_TYPE_CHECK(objBool); return booln; }
+ int getInt() const { OBJECT_TYPE_CHECK(objInt); return intg; }
+ double getReal() const { OBJECT_TYPE_CHECK(objReal); return real; }
// Note: integers larger than 2^53 can not be exactly represented by a double.
// Where the exact value of integers up to 2^63 is required, use isInt64()/getInt64().
- double getNum() { OBJECT_3TYPES_CHECK(objInt, objInt64, objReal);
+ double getNum() const { OBJECT_3TYPES_CHECK(objInt, objInt64, objReal);
return type == objInt ? (double)intg : type == objInt64 ? (double)int64g : real; }
- double getNum(bool *ok) {
+ double getNum(bool *ok) const {
if (unlikely(type != objInt && type != objInt64 && type != objReal)) {
*ok = false;
return 0.;
}
return type == objInt ? (double)intg : type == objInt64 ? (double)int64g : real;
}
- GooString *getString() { OBJECT_TYPE_CHECK(objString); return string; }
+ GooString *getString() const { OBJECT_TYPE_CHECK(objString); return string; }
// After takeString() the only method that should be called for the object is free()
// because the object it's not expected to have a NULL string.
GooString *takeString() {
OBJECT_TYPE_CHECK(objString); GooString *s = string; string = NULL; return s; }
- char *getName() { OBJECT_TYPE_CHECK(objName); return cString; }
- Array *getArray() { OBJECT_TYPE_CHECK(objArray); return array; }
- Dict *getDict() { OBJECT_TYPE_CHECK(objDict); return dict; }
- Stream *getStream() { OBJECT_TYPE_CHECK(objStream); return stream; }
- Ref getRef() { OBJECT_TYPE_CHECK(objRef); return ref; }
- int getRefNum() { OBJECT_TYPE_CHECK(objRef); return ref.num; }
- int getRefGen() { OBJECT_TYPE_CHECK(objRef); return ref.gen; }
- char *getCmd() { OBJECT_TYPE_CHECK(objCmd); return cString; }
- long long getInt64() { OBJECT_TYPE_CHECK(objInt64); return int64g; }
- long long getIntOrInt64() { OBJECT_2TYPES_CHECK(objInt, objInt64);
+ char *getName() const { OBJECT_TYPE_CHECK(objName); return cString; }
+ Array *getArray() const { OBJECT_TYPE_CHECK(objArray); return array; }
+ Dict *getDict() const { OBJECT_TYPE_CHECK(objDict); return dict; }
+ Stream *getStream() const { OBJECT_TYPE_CHECK(objStream); return stream; }
+ Ref getRef() const { OBJECT_TYPE_CHECK(objRef); return ref; }
+ int getRefNum() const { OBJECT_TYPE_CHECK(objRef); return ref.num; }
+ int getRefGen() const { OBJECT_TYPE_CHECK(objRef); return ref.gen; }
+ char *getCmd() const { OBJECT_TYPE_CHECK(objCmd); return cString; }
+ long long getInt64() const { OBJECT_TYPE_CHECK(objInt64); return int64g; }
+ long long getIntOrInt64() const { OBJECT_2TYPES_CHECK(objInt, objInt64);
return type == objInt ? intg : int64g; }
// Array accessors.
- int arrayGetLength();
+ int arrayGetLength() const;
void arrayAdd(Object &&elem);
void arrayRemove(int i);
- Object arrayGet(int i, int recursion);
- Object arrayGetNF(int i);
+ Object arrayGet(int i, int recursion) const;
+ Object arrayGetNF(int i) const;
// Dict accessors.
- int dictGetLength();
+ int dictGetLength() const;
void dictAdd(char *key, Object &&val);
void dictSet(const char *key, Object &&val);
void dictRemove(const char *key);
- GBool dictIs(const char *dictType);
- Object dictLookup(const char *key, int recursion = 0);
- Object dictLookupNF(const char *key);
- char *dictGetKey(int i);
- Object dictGetVal(int i);
- Object dictGetValNF(int i);
+ GBool dictIs(const char *dictType) const;
+ Object dictLookup(const char *key, int recursion = 0) const;
+ Object dictLookupNF(const char *key) const;
+ char *dictGetKey(int i) const;
+ Object dictGetVal(int i) const;
+ Object dictGetValNF(int i) const;
// Stream accessors.
- GBool streamIs(char *dictType);
+ GBool streamIs(char *dictType) const;
void streamReset();
void streamClose();
- int streamGetChar();
- int streamGetChars(int nChars, Guchar *buffer);
- int streamLookChar();
- char *streamGetLine(char *buf, int size);
- Goffset streamGetPos();
+ int streamGetChar() const;
+ int streamGetChars(int nChars, Guchar *buffer) const;
+ int streamLookChar() const;
+ char *streamGetLine(char *buf, int size) const;
+ Goffset streamGetPos() const;
void streamSetPos(Goffset pos, int dir = 0);
- Dict *streamGetDict();
+ Dict *streamGetDict() const;
// Output.
- const char *getTypeName();
- void print(FILE *f = stdout);
+ const char *getTypeName() const;
+ void print(FILE *f = stdout) const;
// Memory testing.
static void memCheck(FILE *f);
@@ -319,7 +319,7 @@ private:
#include "Array.h"
-inline int Object::arrayGetLength()
+inline int Object::arrayGetLength() const
{ OBJECT_TYPE_CHECK(objArray); return array->getLength(); }
inline void Object::arrayAdd(Object &&elem)
@@ -328,10 +328,10 @@ inline void Object::arrayAdd(Object &&elem)
inline void Object::arrayRemove(int i)
{ OBJECT_TYPE_CHECK(objArray); array->remove(i); }
-inline Object Object::arrayGet(int i, int recursion = 0)
+inline Object Object::arrayGet(int i, int recursion = 0) const
{ OBJECT_TYPE_CHECK(objArray); return array->get(i, recursion); }
-inline Object Object::arrayGetNF(int i)
+inline Object Object::arrayGetNF(int i) const
{ OBJECT_TYPE_CHECK(objArray); return array->getNF(i); }
//------------------------------------------------------------------------
@@ -340,7 +340,7 @@ inline Object Object::arrayGetNF(int i)
#include "Dict.h"
-inline int Object::dictGetLength()
+inline int Object::dictGetLength() const
{ OBJECT_TYPE_CHECK(objDict); return dict->getLength(); }
inline void Object::dictAdd(char *key, Object &&val)
@@ -352,25 +352,25 @@ inline void Object::dictSet(const char *key, Object &&val)
inline void Object::dictRemove(const char *key)
{ OBJECT_TYPE_CHECK(objDict); dict->remove(key); }
-inline GBool Object::dictIs(const char *dictType)
+inline GBool Object::dictIs(const char *dictType) const
{ OBJECT_TYPE_CHECK(objDict); return dict->is(dictType); }
-inline GBool Object::isDict(const char *dictType)
+inline GBool Object::isDict(const char *dictType) const
{ return type == objDict && dictIs(dictType); }
-inline Object Object::dictLookup(const char *key, int recursion)
+inline Object Object::dictLookup(const char *key, int recursion) const
{ OBJECT_TYPE_CHECK(objDict); return dict->lookup(key, recursion); }
-inline Object Object::dictLookupNF(const char *key)
+inline Object Object::dictLookupNF(const char *key) const
{ OBJECT_TYPE_CHECK(objDict); return dict->lookupNF(key); }
-inline char *Object::dictGetKey(int i)
+inline char *Object::dictGetKey(int i) const
{ OBJECT_TYPE_CHECK(objDict); return dict->getKey(i); }
-inline Object Object::dictGetVal(int i)
+inline Object Object::dictGetVal(int i) const
{ OBJECT_TYPE_CHECK(objDict); return dict->getVal(i); }
-inline Object Object::dictGetValNF(int i)
+inline Object Object::dictGetValNF(int i) const
{ OBJECT_TYPE_CHECK(objDict); return dict->getValNF(i); }
//------------------------------------------------------------------------
@@ -379,10 +379,10 @@ inline Object Object::dictGetValNF(int i)
#include "Stream.h"
-inline GBool Object::streamIs(char *dictType)
+inline GBool Object::streamIs(char *dictType) const
{ OBJECT_TYPE_CHECK(objStream); return stream->getDict()->is(dictType); }
-inline GBool Object::isStream(char *dictType)
+inline GBool Object::isStream(char *dictType) const
{ return type == objStream && streamIs(dictType); }
inline void Object::streamReset()
@@ -391,25 +391,25 @@ inline void Object::streamReset()
inline void Object::streamClose()
{ OBJECT_TYPE_CHECK(objStream); stream->close(); }
-inline int Object::streamGetChar()
+inline int Object::streamGetChar() const
{ OBJECT_TYPE_CHECK(objStream); return stream->getChar(); }
-inline int Object::streamGetChars(int nChars, Guchar *buffer)
+inline int Object::streamGetChars(int nChars, Guchar *buffer) const
{ OBJECT_TYPE_CHECK(objStream); return stream->doGetChars(nChars, buffer); }
-inline int Object::streamLookChar()
+inline int Object::streamLookChar() const
{ OBJECT_TYPE_CHECK(objStream); return stream->lookChar(); }
-inline char *Object::streamGetLine(char *buf, int size)
+inline char *Object::streamGetLine(char *buf, int size) const
{ OBJECT_TYPE_CHECK(objStream); return stream->getLine(buf, size); }
-inline Goffset Object::streamGetPos()
+inline Goffset Object::streamGetPos() const
{ OBJECT_TYPE_CHECK(objStream); return stream->getPos(); }
inline void Object::streamSetPos(Goffset pos, int dir)
{ OBJECT_TYPE_CHECK(objStream); stream->setPos(pos, dir); }
-inline Dict *Object::streamGetDict()
+inline Dict *Object::streamGetDict() const
{ OBJECT_TYPE_CHECK(objStream); return stream->getDict(); }
#endif
More information about the poppler
mailing list