aboutsummaryrefslogtreecommitdiff
path: root/lout
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2014-03-01 21:26:25 +0100
committerSebastian Geerken <devnull@localhost>2014-03-01 21:26:25 +0100
commit975ba73389d2de0cd2bb50183bd988eab6ba0e06 (patch)
tree67947a7e22dd049685dc034223c212e2ae14c902 /lout
parent6369c18d186d52f0f3f5082ff6c9fdcf5c9285d1 (diff)
parent8818cda9ca4e4c19c4c5fcee68460d5ba0cd5ba2 (diff)
Merge with main repo.
Diffstat (limited to 'lout')
-rw-r--r--lout/container.cc10
-rw-r--r--lout/container.hh44
-rw-r--r--lout/debug.hh26
-rw-r--r--lout/misc.cc2
-rw-r--r--lout/misc.hh34
5 files changed, 64 insertions, 52 deletions
diff --git a/lout/container.cc b/lout/container.cc
index 602553d3..dcac4726 100644
--- a/lout/container.cc
+++ b/lout/container.cc
@@ -428,7 +428,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) {
@@ -462,7 +462,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) {
@@ -578,7 +578,7 @@ HashTable::~HashTable()
PRINTF ("- deleting value: %s\n", value->toString());
delete value;
}
- }
+ }
}
}
}
@@ -612,7 +612,7 @@ void HashTable::intoStringBuffer(misc::StringBuffer *sb)
node->object->intoStringBuffer(sb);
sb->append(" => ");
-
+
Object *value = ((KeyValuePair*)node)->value;
if (value)
value->intoStringBuffer(sb);
@@ -632,7 +632,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 9180b9e0..03800efd 100644
--- a/lout/container.hh
+++ b/lout/container.hh
@@ -114,7 +114,7 @@ private:
private:
Vector *vector;
int index;
-
+
public:
VectorIterator(Vector *vector) { this->vector = vector; index = -1; }
bool hasNext();
@@ -143,7 +143,7 @@ public:
{ insert (newElement, bsearch (newElement, false, comparator)); }
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();
@@ -203,10 +203,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; }
};
@@ -228,7 +228,7 @@ protected:
int tableSize;
bool ownerOfObjects;
- inline int calcHashValue(object::Object *object)
+ inline int calcHashValue(object::Object *object) const
{
return abs(object->hashValue()) % tableSize;
}
@@ -236,7 +236,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();
@@ -262,7 +262,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);
};
@@ -291,7 +291,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;
};
/**
@@ -335,9 +335,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
@@ -418,9 +418,9 @@ public:
&object::standardComparator)
{ ((untyped::Vector*)this->base)->insertSorted(newElement, comparator); }
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(object::Comparator *comparator =
&object::standardComparator)
@@ -457,12 +457,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(); }
};
@@ -480,7 +480,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); }
@@ -500,7 +500,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); }
};
@@ -517,10 +517,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/debug.hh b/lout/debug.hh
index 999a4a8b..a2393470 100644
--- a/lout/debug.hh
+++ b/lout/debug.hh
@@ -115,6 +115,13 @@
fflush (stdout); \
} D_STMT_END
+#define DBG_OBJ_DELETE() \
+ D_STMT_START { \
+ printf (RTFL_PREFIX_FMT "obj-delete:%p\n", \
+ RTFL_PREFIX_ARGS, this); \
+ fflush (stdout); \
+ } D_STMT_END
+
#define DBG_OBJ_BASECLASS(klass) \
D_STMT_START { \
printf (RTFL_PREFIX_FMT "obj-ident:%p:%p\n", \
@@ -124,9 +131,11 @@
#define DBG_OBJ_ASSOC(parent, child) \
D_STMT_START { \
- printf (RTFL_PREFIX_FMT "obj-assoc:%p:%p\n", \
- RTFL_PREFIX_ARGS, parent, child); \
- fflush (stdout); \
+ if (child) { \
+ printf (RTFL_PREFIX_FMT "obj-assoc:%p:%p\n", \
+ RTFL_PREFIX_ARGS, parent, child); \
+ fflush (stdout); \
+ } \
} D_STMT_END
#define DBG_OBJ_ASSOC_PARENT(parent) \
@@ -138,9 +147,11 @@
#define DBG_OBJ_ASSOC_CHILD(child) \
D_STMT_START { \
- printf (RTFL_PREFIX_FMT "obj-assoc:%p:%p\n", \
- RTFL_PREFIX_ARGS, this, child); \
- fflush (stdout); \
+ if (child) { \
+ printf (RTFL_PREFIX_FMT "obj-assoc:%p:%p\n", \
+ RTFL_PREFIX_ARGS, this, child); \
+ fflush (stdout); \
+ } \
} D_STMT_END
#define DBG_OBJ_SET_NUM(var, val) \
@@ -254,6 +265,7 @@
#define DBG_OBJ_MSG_END() D_STMT_NOP
#define DBG_OBJ_MSG_END_O(obj) D_STMT_NOP
#define DBG_OBJ_CREATE(klass) D_STMT_NOP
+#define DBG_OBJ_DELETE() D_STMT_NOP
#define DBG_OBJ_BASECLASS(klass) D_STMT_NOP
#define DBG_OBJ_ASSOC_PARENT(parent) D_STMT_NOP
#define DBG_OBJ_ASSOC_CHILD(child) D_STMT_NOP
@@ -271,7 +283,7 @@
#define DBG_OBJ_ARRATTRSET_SYM(var, ind, attr, val) D_STMT_NOP
#define DBG_OBJ_ARRATTRSET_STR(var, ind, attr, val) D_STMT_NOP
#define DBG_OBJ_ARRATTRSET_PTR(var, ind, attr, val) D_STMT_NOP
-#define DBG_OBJ_COLOR(klass, color)
+#define DBG_OBJ_COLOR(klass, color) D_STMT_NOP
#endif /* DBG_RTFL */
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 2ed5e1b0..2bb28b12 100644
--- a/lout/misc.hh
+++ b/lout/misc.hh
@@ -92,7 +92,7 @@ private:
}
public:
- inline SimpleVector (int initAlloc)
+ inline SimpleVector (int initAlloc = 1)
{
this->num = 0;
this->numAlloc = initAlloc;
@@ -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());
}
@@ -541,7 +541,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();
};