aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2014-02-16 00:27:28 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2014-02-16 00:27:28 +0100
commit950e73503f41ab65396271d02e0331b85f302b29 (patch)
tree26f60a1ae95dbfd45cd7e6425220446774b82a42
parent7167b40921d0e0b47fa9ebdf9b5abe9db8752f59 (diff)
lout: mark getters as const
-rw-r--r--lout/container.cc6
-rw-r--r--lout/container.hh42
-rw-r--r--lout/misc.cc2
-rw-r--r--lout/misc.hh32
4 files changed, 41 insertions, 41 deletions
diff --git a/lout/container.cc b/lout/container.cc
index de7b93e2..d3385137 100644
--- a/lout/container.cc
+++ b/lout/container.cc
@@ -412,7 +412,7 @@ void HashSet::clearNode(HashSet::Node *node)
}
}
-HashSet::Node *HashSet::findNode(Object *object)
+HashSet::Node *HashSet::findNode(Object *object) const
{
int h = calcHashValue(object);
for (Node *node = table[h]; node; node = node->next) {
@@ -446,7 +446,7 @@ void HashSet::put(Object *object)
insertNode (object);
}
-bool HashSet::contains(Object *object)
+bool HashSet::contains(Object *object) const
{
int h = calcHashValue(object);
for (Node *n = table[h]; n; n = n->next) {
@@ -616,7 +616,7 @@ void HashTable::put(Object *key, Object *value)
node->value = value;
}
-Object *HashTable::get(Object *key)
+Object *HashTable::get(Object *key) const
{
Node *node = findNode(key);
if (node)
diff --git a/lout/container.hh b/lout/container.hh
index 09c8ffc0..14803140 100644
--- a/lout/container.hh
+++ b/lout/container.hh
@@ -141,7 +141,7 @@ public:
{ insert (newElement, bsearch (newElement, false)); }
void remove(int pos);
- inline object::Object *get(int pos)
+ inline object::Object *get(int pos) const
{ return (pos >= 0 && pos < numElements) ? array[pos] : NULL; }
inline int size() { return numElements; }
void clear();
@@ -196,10 +196,10 @@ public:
{ return remove0(element, true, false); }
inline bool detachRef(object::Object *element)
{ return remove0(element, false, true); }
- inline int size() { return numElements; }
- inline bool isEmpty() { return numElements == 0; }
- inline object::Object *getFirst() { return first->object; }
- inline object::Object *getLast() { return last->object; }
+ inline int size() const { return numElements; }
+ inline bool isEmpty() const { return numElements == 0; }
+ inline object::Object *getFirst() const { return first->object; }
+ inline object::Object *getLast() const { return last->object; }
};
@@ -221,7 +221,7 @@ protected:
int tableSize;
bool ownerOfObjects;
- inline int calcHashValue(object::Object *object)
+ inline int calcHashValue(object::Object *object) const
{
return abs(object->hashValue()) % tableSize;
}
@@ -229,7 +229,7 @@ protected:
virtual Node *createNode();
virtual void clearNode(Node *node);
- Node *findNode(object::Object *object);
+ Node *findNode(object::Object *object) const;
Node *insertNode(object::Object *object);
AbstractIterator* createIterator();
@@ -255,7 +255,7 @@ public:
~HashSet();
void put (object::Object *object);
- bool contains (object::Object *key);
+ bool contains (object::Object *key) const;
bool remove (object::Object *key);
//Object *getReference (object::Object *object);
};
@@ -284,7 +284,7 @@ public:
void intoStringBuffer(misc::StringBuffer *sb);
void put (object::Object *key, object::Object *value);
- object::Object *get (object::Object *key);
+ object::Object *get (object::Object *key) const;
};
/**
@@ -328,9 +328,9 @@ public:
void push (object::Object *object);
void pushUnder (object::Object *object);
- inline object::Object *getTop () { return top ? top->object : NULL; }
+ inline object::Object *getTop () const { return top ? top->object : NULL; }
void pop ();
- inline int size() { return numElements; }
+ inline int size() const { return numElements; }
};
} // namespace untyped
@@ -409,9 +409,9 @@ public:
inline void insertSorted(T *newElement)
{ ((untyped::Vector*)this->base)->insertSorted(newElement); }
inline void remove(int pos) { ((untyped::Vector*)this->base)->remove(pos); }
- inline T *get(int pos)
+ inline T *get(int pos) const
{ return (T*)((untyped::Vector*)this->base)->get(pos); }
- inline int size() { return ((untyped::Vector*)this->base)->size(); }
+ inline int size() const { return ((untyped::Vector*)this->base)->size(); }
inline void clear() { ((untyped::Vector*)this->base)->clear(); }
inline void sort() { ((untyped::Vector*)this->base)->sort(); }
inline int bsearch(T *key, bool mustExist)
@@ -438,12 +438,12 @@ public:
inline bool detachRef(T *element) {
return ((untyped::List*)this->base)->detachRef(element); }
- inline int size() { return ((untyped::List*)this->base)->size(); }
- inline bool isEmpty()
+ inline int size() const { return ((untyped::List*)this->base)->size(); }
+ inline bool isEmpty() const
{ return ((untyped::List*)this->base)->isEmpty(); }
- inline T *getFirst()
+ inline T *getFirst() const
{ return (T*)((untyped::List*)this->base)->getFirst(); }
- inline T *getLast()
+ inline T *getLast() const
{ return (T*)((untyped::List*)this->base)->getLast(); }
};
@@ -461,7 +461,7 @@ public:
inline void put(T *object)
{ return ((untyped::HashSet*)this->base)->put(object); }
- inline bool contains(T *object)
+ inline bool contains(T *object) const
{ return ((untyped::HashSet*)this->base)->contains(object); }
inline bool remove(T *object)
{ return ((untyped::HashSet*)this->base)->remove(object); }
@@ -481,7 +481,7 @@ public:
inline void put(K *key, V *value)
{ return ((untyped::HashTable*)this->base)->put(key, value); }
- inline V *get(K *key)
+ inline V *get(K *key) const
{ return (V*)((untyped::HashTable*)this->base)->get(key); }
};
@@ -498,10 +498,10 @@ public:
((untyped::Stack*)this->base)->push (object); }
inline void pushUnder (T *object)
{ ((untyped::Stack*)this->base)->pushUnder (object); }
- inline T *getTop ()
+ inline T *getTop () const
{ return (T*)((untyped::Stack*)this->base)->getTop (); }
inline void pop () { ((untyped::Stack*)this->base)->pop (); }
- inline int size() { return ((untyped::Stack*)this->base)->size(); }
+ inline int size() const { return ((untyped::Stack*)this->base)->size(); }
};
} // namespace untyped
diff --git a/lout/misc.cc b/lout/misc.cc
index d4db609e..8d630efc 100644
--- a/lout/misc.cc
+++ b/lout/misc.cc
@@ -151,7 +151,7 @@ void BitSet::intoStringBuffer(misc::StringBuffer *sb)
sb->append("]");
}
-bool BitSet::get(int i)
+bool BitSet::get(int i) const
{
if (8 * i >= numBytes)
return false;
diff --git a/lout/misc.hh b/lout/misc.hh
index cff8e05b..0fcb914a 100644
--- a/lout/misc.hh
+++ b/lout/misc.hh
@@ -116,9 +116,9 @@ public:
/**
* \brief Return the number of elements put into this vector.
*/
- inline int size() { return this->num; }
+ inline int size() const { return this->num; }
- inline T* getArray() { return array; }
+ inline T* getArray() const { return array; }
inline T* detachArray() {
T* arr = array;
@@ -163,7 +163,7 @@ public:
*
* \sa misc::SimpleVector::get
*/
- inline T* getRef (int i) {
+ inline T* getRef (int i) const {
assert (i >= 0 && this->num - i > 0);
return array + i;
}
@@ -174,7 +174,7 @@ public:
* The element is copied, so for complex elements, you should rather used
* misc::SimpleVector::getRef.
*/
- inline T get (int i) {
+ inline T get (int i) const {
assert (i >= 0 && this->num - i > 0);
return this->array[i];
}
@@ -182,7 +182,7 @@ public:
/**
* \brief Return the reference of the first element (convenience method).
*/
- inline T* getFirstRef () {
+ inline T* getFirstRef () const {
assert (this->num > 0);
return this->array;
}
@@ -190,7 +190,7 @@ public:
/**
* \brief Return the first element, explicitly.
*/
- inline T getFirst () {
+ inline T getFirst () const {
assert (this->num > 0);
return this->array[0];
}
@@ -198,7 +198,7 @@ public:
/**
* \brief Return the reference of the last element (convenience method).
*/
- inline T* getLastRef () {
+ inline T* getLastRef () const {
assert (this->num > 0);
return this->array + this->num - 1;
}
@@ -206,7 +206,7 @@ public:
/**
* \brief Return the last element, explicitly.
*/
- inline T getLast () {
+ inline T getLast () const {
assert (this->num > 0);
return this->array[this->num - 1];
}
@@ -352,7 +352,7 @@ public:
free (this->arrayExtra2);
}
- inline int size() { return this->numMain + this->numExtra; }
+ inline int size() const { return this->numMain + this->numExtra; }
inline void increase() { setSize(size() + 1); }
@@ -419,7 +419,7 @@ public:
*
* \sa misc::SimpleVector::get
*/
- inline T* getRef (int i)
+ inline T* getRef (int i) const
{
if (this->startExtra == -1)
return this->arrayMain + i;
@@ -439,7 +439,7 @@ public:
* The element is copied, so for complex elements, you should rather used
* misc::SimpleVector::getRef.
*/
- inline T get (int i)
+ inline T get (int i) const
{
return *(this->getRef(i));
}
@@ -447,7 +447,7 @@ public:
/**
* \brief Return the reference of the first element (convenience method).
*/
- inline T* getFirstRef () {
+ inline T* getFirstRef () const {
assert (size () > 0);
return this->getRef(0);
}
@@ -455,14 +455,14 @@ public:
/**
* \brief Return the first element, explicitly.
*/
- inline T getFirst () {
+ inline T getFirst () const {
return *(this->getFirstRef());
}
/**
* \brief Return the reference of the last element (convenience method).
*/
- inline T* getLastRef () {
+ inline T* getLastRef () const {
assert (size () > 0);
return this->getRef(size () - 1);
}
@@ -470,7 +470,7 @@ public:
/**
* \brief Return the last element, explicitly.
*/
- inline T getLast () {
+ inline T getLast () const {
return *(this->getLastRef());
}
@@ -536,7 +536,7 @@ public:
BitSet(int initBits);
~BitSet();
void intoStringBuffer(misc::StringBuffer *sb);
- bool get(int i);
+ bool get(int i) const;
void set(int i, bool val);
void clear();
};