Commit 1a33f60d authored by Albert Astals Cid's avatar Albert Astals Cid

Add some constness to the basic classes

parent 135843fa
......@@ -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];
......
......@@ -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);
......
......@@ -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()) {
......
......@@ -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
};
......
......@@ -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();
}
......@@ -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
......@@ -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;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment