aboutsummaryrefslogtreecommitdiff
path: root/lout
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2010-08-20 23:24:19 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2010-08-20 23:24:19 +0200
commitf5c598b518d1f906148534d015f50075d3e8242d (patch)
tree21dd70add5b366c3dd80641b77f6b18e0baa009e /lout
parente98d02a01ffeb18ede86af025e51ae1ec011c75a (diff)
parent5f0fc0e48b8cbee7e1795935da0abff6627fd498 (diff)
merge
Diffstat (limited to 'lout')
-rw-r--r--lout/Makefile.am3
-rw-r--r--lout/container.cc117
-rw-r--r--lout/container.hh18
-rw-r--r--lout/identity.cc3
-rw-r--r--lout/identity.hh6
-rw-r--r--lout/misc.cc60
-rw-r--r--lout/misc.hh55
-rw-r--r--lout/msg.h39
-rw-r--r--lout/object.cc35
-rw-r--r--lout/object.hh6
-rw-r--r--lout/signal.cc11
-rw-r--r--lout/signal.hh8
12 files changed, 186 insertions, 175 deletions
diff --git a/lout/Makefile.am b/lout/Makefile.am
index 18e00cf2..5a246708 100644
--- a/lout/Makefile.am
+++ b/lout/Makefile.am
@@ -11,4 +11,5 @@ liblout_a_SOURCES = \
object.cc \
object.hh \
signal.cc \
- signal.hh
+ signal.hh \
+ msg.h
diff --git a/lout/container.cc b/lout/container.cc
index 0b00c195..0a3d6acd 100644
--- a/lout/container.cc
+++ b/lout/container.cc
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -43,41 +42,41 @@ Iterator::Iterator()
Iterator::Iterator(const Iterator &it2)
{
impl = it2.impl;
- if(impl)
+ if (impl)
impl->ref();
}
Iterator::Iterator(Iterator &it2)
{
impl = it2.impl;
- if(impl)
+ if (impl)
impl->ref();
}
Iterator &Iterator::operator=(const Iterator &it2)
{
- if(impl)
+ if (impl)
impl->unref();
impl = it2.impl;
- if(impl)
+ if (impl)
impl->ref();
return *this;
}
Iterator &Iterator::operator=(Iterator &it2)
{
- if(impl)
+ if (impl)
impl->unref();
impl = it2.impl;
- if(impl)
+ if (impl)
impl->ref();
return *this;
}
Iterator::~Iterator()
{
- if(impl)
- impl->unref();
+ if (impl)
+ impl->unref();
}
// ----------------
@@ -88,8 +87,8 @@ void Collection::intoStringBuffer(misc::StringBuffer *sb)
{
sb->append("{ ");
bool first = true;
- for(Iterator it = iterator(); it.hasNext(); ) {
- if(!first)
+ for (Iterator it = iterator(); it.hasNext(); ) {
+ if (!first)
sb->append(", ");
it.getNext()->intoStringBuffer(sb);
first = false;
@@ -117,27 +116,27 @@ Vector::~Vector()
void Vector::put(Object *newElement, int newPos)
{
- if(newPos == -1)
+ if (newPos == -1)
newPos = numElements;
// Old entry is overwritten.
- if(newPos < numElements) {
- if(ownerOfObjects && array[newPos])
+ if (newPos < numElements) {
+ if (ownerOfObjects && array[newPos])
delete array[newPos];
}
// Allocated memory has to be increased.
- if(newPos >= numAlloc) {
+ if (newPos >= numAlloc) {
while (newPos >= numAlloc)
numAlloc *= 2;
array = (Object**)realloc(array, numAlloc * sizeof(Object*));
}
// Insert NULL's into possible gap before new position.
- for(int i = numElements; i < newPos; i++)
+ for (int i = numElements; i < newPos; i++)
array[i] = NULL;
- if(newPos >= numElements)
+ if (newPos >= numElements)
numElements = newPos + 1;
array[newPos] = newElement;
@@ -146,8 +145,8 @@ void Vector::put(Object *newElement, int newPos)
void Vector::clear()
{
if (ownerOfObjects) {
- for(int i = 0; i < numElements; i++)
- if(array[i])
+ for (int i = 0; i < numElements; i++)
+ if (array[i])
delete array[i];
}
@@ -156,18 +155,18 @@ void Vector::clear()
void Vector::insert(Object *newElement, int pos)
{
- if(pos >= numElements)
+ if (pos >= numElements)
put(newElement, pos);
else {
numElements++;
// Allocated memory has to be increased.
- if(numElements >= numAlloc) {
+ if (numElements >= numAlloc) {
numAlloc *= 2;
array = (Object**)realloc(array, numAlloc * sizeof(Object*));
}
- for(int i = numElements - 1; i > pos; i--)
+ for (int i = numElements - 1; i > pos; i--)
array[i] = array[i - 1];
array[pos] = newElement;
@@ -176,10 +175,10 @@ void Vector::insert(Object *newElement, int pos)
void Vector::remove(int pos)
{
- if(ownerOfObjects && array[pos])
+ if (ownerOfObjects && array[pos])
delete array[pos];
- for(int i = pos + 1; i < numElements; i++)
+ for (int i = pos + 1; i < numElements; i++)
array[i - 1] = array[i];
numElements--;
@@ -220,8 +219,8 @@ List::~List()
void List::clear()
{
- while(first) {
- if(ownerOfObjects && first->object)
+ while (first) {
+ if (ownerOfObjects && first->object)
delete first->object;
Node *next = first->next;
delete first;
@@ -238,10 +237,10 @@ void List::append(Object *element)
newLast->next = NULL;
newLast->object = element;
- if(last) {
+ if (last) {
last->next = newLast;
last = newLast;
- } else
+ } else
first = last = newLast;
numElements++;
@@ -252,21 +251,21 @@ bool List::remove0(Object *element, bool compare, bool doNotDeleteAtAll)
{
Node *beforeCur, *cur;
- for(beforeCur = NULL, cur = first; cur; beforeCur = cur, cur = cur->next) {
+ for (beforeCur = NULL, cur = first; cur; beforeCur = cur, cur = cur->next) {
if (compare ?
(cur->object && element->equals(cur->object)) :
element == cur->object) {
- if(beforeCur) {
+ if (beforeCur) {
beforeCur->next = cur->next;
- if(cur->next == NULL)
+ if (cur->next == NULL)
last = beforeCur;
} else {
first = cur->next;
- if(first == NULL)
+ if (first == NULL)
last = NULL;
}
- if(ownerOfObjects && cur->object && !doNotDeleteAtAll)
+ if (ownerOfObjects && cur->object && !doNotDeleteAtAll)
delete cur->object;
delete cur;
@@ -282,7 +281,7 @@ Object *List::ListIterator::getNext()
{
Object *object;
- if(current) {
+ if (current) {
object = current->object;
current = current->next;
} else
@@ -313,20 +312,20 @@ HashTable::HashTable(bool ownerOfKeys, bool ownerOfValues, int tableSize)
this->tableSize = tableSize;
table = new Node*[tableSize];
- for(int i = 0; i < tableSize; i++)
+ for (int i = 0; i < tableSize; i++)
table[i] = NULL;
}
HashTable::~HashTable()
{
- for(int i = 0; i < tableSize; i++) {
+ for (int i = 0; i < tableSize; i++) {
Node *n1 = table[i];
- while(n1) {
+ while (n1) {
Node *n2 = n1->next;
- if(ownerOfValues && n1->value)
+ if (ownerOfValues && n1->value)
delete n1->value;
- if(ownerOfKeys)
+ if (ownerOfKeys)
delete n1->key;
delete n1;
@@ -342,9 +341,9 @@ void HashTable::intoStringBuffer(misc::StringBuffer *sb)
sb->append("{ ");
bool first = true;
- for(int i = 0; i < tableSize; i++) {
- for(Node *node = table[i]; node; node = node->next) {
- if(!first)
+ for (int i = 0; i < tableSize; i++) {
+ for (Node *node = table[i]; node; node = node->next) {
+ if (!first)
sb->append(", ");
node->key->intoStringBuffer(sb);
sb->append(" => ");
@@ -369,7 +368,7 @@ void HashTable::put(Object *key, Object *value)
bool HashTable::contains(Object *key)
{
int h = calcHashValue(key);
- for(Node *n = table[h]; n; n = n->next) {
+ for (Node *n = table[h]; n; n = n->next) {
if (key->equals(n->key))
return true;
}
@@ -380,7 +379,7 @@ bool HashTable::contains(Object *key)
Object *HashTable::get(Object *key)
{
int h = calcHashValue(key);
- for(Node *n = table[h]; n; n = n->next) {
+ for (Node *n = table[h]; n; n = n->next) {
if (key->equals(n->key))
return n->value;
}
@@ -393,16 +392,16 @@ bool HashTable::remove(Object *key)
int h = calcHashValue(key);
Node *last, *cur;
- for(last = NULL, cur = table[h]; cur; last = cur, cur = cur->next) {
+ for (last = NULL, cur = table[h]; cur; last = cur, cur = cur->next) {
if (key->equals(cur->key)) {
- if(last)
+ if (last)
last->next = cur->next;
else
table[h] = cur->next;
- if(ownerOfValues && cur->value)
+ if (ownerOfValues && cur->value)
delete cur->value;
- if(ownerOfKeys)
+ if (ownerOfKeys)
delete cur->key;
delete cur;
@@ -416,7 +415,7 @@ bool HashTable::remove(Object *key)
Object *HashTable::getKey (Object *key)
{
int h = calcHashValue(key);
- for(Node *n = table[h]; n; n = n->next) {
+ for (Node *n = table[h]; n; n = n->next) {
if (key->equals(n->key))
return n->key;
}
@@ -434,11 +433,11 @@ HashTable::HashTableIterator::HashTableIterator(HashTable *table)
void HashTable::HashTableIterator::gotoNext()
{
- if(node)
+ if (node)
node = node->next;
- while(node == NULL) {
- if(pos >= table->tableSize - 1)
+ while (node == NULL) {
+ if (pos >= table->tableSize - 1)
return;
pos++;
node = table->table[pos];
@@ -449,7 +448,7 @@ void HashTable::HashTableIterator::gotoNext()
Object *HashTable::HashTableIterator::getNext()
{
Object *result;
- if(node)
+ if (node)
result = node->key;
else
result = NULL;
@@ -492,7 +491,7 @@ void Stack::push (object::Object *object)
newTop->prev = top;
top = newTop;
- if(bottom == NULL)
+ if (bottom == NULL)
bottom = top;
numElements++;
@@ -503,11 +502,11 @@ void Stack::pushUnder (object::Object *object)
Node *newBottom = new Node ();
newBottom->object = object;
newBottom->prev = NULL;
- if(bottom != NULL)
+ if (bottom != NULL)
bottom->prev = newBottom;
bottom = newBottom;
- if(top == NULL)
+ if (top == NULL)
top = bottom;
numElements++;
@@ -522,7 +521,7 @@ void Stack::pop ()
delete top;
top = newTop;
- if(top == NULL)
+ if (top == NULL)
bottom = NULL;
numElements--;
@@ -532,7 +531,7 @@ Object *Stack::StackIterator::getNext()
{
Object *object;
- if(current) {
+ if (current) {
object = current->object;
current = current->prev;
} else
diff --git a/lout/container.hh b/lout/container.hh
index 26803e23..68a15da4 100644
--- a/lout/container.hh
+++ b/lout/container.hh
@@ -8,7 +8,7 @@
* members are instances of object::Object.
*
* A common problem in languanges without garbage collection is, where the
- * children belong to, and so, who is responsible to delete them (instanciation
+ * children belong to, and so, who is responsible to delete them (instantiation
* is always done by the caller). This information is here told to the
* collections, each container has a constructor with the parameter
* "ownerOfObjects" (HashTable has two such parameters, for keys and values).
@@ -20,7 +20,7 @@ namespace lout {
namespace container {
/**
- * \brief The container classes defined here contain instances of
+ * \brief The container classes defined here contain instances of
* object::Object.
*
* Different sub-classes may be mixed, and you have to care about casting,
@@ -44,13 +44,13 @@ protected:
{
private:
int refcount;
-
+
public:
AbstractIterator() { refcount = 1; }
-
+
void ref () { refcount++; }
void unref () { refcount--; if (refcount == 0) delete this; }
-
+
virtual bool hasNext () = 0;
virtual Object *getNext () = 0;
};
@@ -60,7 +60,7 @@ protected:
};
/**
- * \brief This is a small wrapper for AbstractIterator, which may be used
+ * \brief This is a small wrapper for AbstractIterator, which may be used
* directly, not as a pointer, to makes memory management simpler.
*/
class Iterator
@@ -70,7 +70,7 @@ class Iterator
private:
Collection0::AbstractIterator *impl;
- // Should not instanciated directly.
+ // Should not instantiated directly.
inline Iterator(Collection0::AbstractIterator *impl) { this->impl = impl; }
public:
@@ -271,7 +271,7 @@ protected:
public:
Stack (bool ownerOfObjects);
~Stack();
-
+
void push (object::Object *object);
void pushUnder (object::Object *object);
inline object::Object *getTop () { return top ? top->object : NULL; }
@@ -421,7 +421,7 @@ public:
inline Stack (bool ownerOfObjects)
{ this->base = new untyped::Stack (ownerOfObjects); }
~Stack() { delete this->base; }
-
+
inline void push (T *object) {
((untyped::Stack*)this->base)->push (object); }
inline void pushUnder (T *object)
diff --git a/lout/identity.cc b/lout/identity.cc
index 8a5d68fd..ebe95ef0 100644
--- a/lout/identity.cc
+++ b/lout/identity.cc
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "identity.hh"
diff --git a/lout/identity.hh b/lout/identity.hh
index 7dcdbac4..6102933d 100644
--- a/lout/identity.hh
+++ b/lout/identity.hh
@@ -53,7 +53,7 @@ namespace identity {
* </ul>
*
* After this, <i>class</i>::CLASS_ID refers to a number, which denotes the
- * class. (If this is still -1, since the class has not yet been instanciated,
+ * class. (If this is still -1, since the class has not yet been instantiated,
* any test will fail, which is correct.)
*
* <h3>Notes on implementation</h3>
@@ -131,11 +131,11 @@ public:
* identity::IdentifiableObject::instanceOf are done.
*/
int getClassId () { return classId; }
-
+
/**
* \brief Return the name, under which the class of this object was
* registered.
- */
+ */
const char *getClassName() { return classesById->get(classId)->className; }
bool instanceOf (int otherClassId);
diff --git a/lout/misc.cc b/lout/misc.cc
index 2008737b..78f758fd 100644
--- a/lout/misc.cc
+++ b/lout/misc.cc
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -38,29 +37,6 @@ void init (int argc, char *argv[])
prgName = strdup (argv[0]);
}
-void chop (char *s)
-{
- char *p = s + strlen (s) - 1;
- while (*p == '\n') {
- *p = 0;
- p--;
- }
-}
-
-char *strip (char *s)
-{
- while (isspace (*s))
- s++;
-
- char *p = s + strlen (s) - 1;
- while (isspace (*p)) {
- *p = 0;
- p--;
- }
-
- return s;
-}
-
// ----------------
// Comparable
// ----------------
@@ -77,11 +53,11 @@ int Comparable::compareFun(const void *p1, const void *p2)
{
Comparable **c1 = (Comparable**)p1;
Comparable **c2 = (Comparable**)p2;
- if(c1 && c2)
+ if (c1 && c2)
return ((*c1)->compareTo(*c2));
- else if(c1)
+ else if (c1)
return 1;
- else if(c2)
+ else if (c2)
return -1;
else
return 0;
@@ -104,7 +80,7 @@ StringBuffer::StringBuffer()
StringBuffer::~StringBuffer()
{
clear ();
- if(str)
+ if (str)
delete[] str;
}
@@ -121,7 +97,7 @@ void StringBuffer::appendNoCopy(char *str)
node->data = str;
node->next = NULL;
- if(firstNode == NULL) {
+ if (firstNode == NULL) {
firstNode = node;
lastNode = node;
} else {
@@ -141,20 +117,20 @@ void StringBuffer::appendNoCopy(char *str)
*/
const char *StringBuffer::getChars()
{
- if(strValid)
+ if (strValid)
return str;
- if(str)
+ if (str)
delete[] str;
str = new char[numChars + 1];
char *p = str;
- for(Node *node = firstNode; node; node = node->next) {
+ for (Node *node = firstNode; node; node = node->next) {
int l = strlen(node->data);
memcpy(p, node->data, l * sizeof(char));
p += l;
}
-
+
*p = 0;
strValid = true;
return str;
@@ -166,7 +142,7 @@ const char *StringBuffer::getChars()
void StringBuffer::clear ()
{
Node *node, *nextNode;
- for(node = firstNode; node; node = nextNode) {
+ for (node = firstNode; node; node = nextNode) {
nextNode = node->next;
delete node->data;
delete node;
@@ -183,7 +159,7 @@ void StringBuffer::clear ()
BitSet::BitSet(int initBits)
{
- numBytes = bytesForBits(initBits);
+ numBytes = bytesForBits(initBits);
bits = (unsigned char*)malloc(numBytes * sizeof(unsigned char));
clear();
}
@@ -196,14 +172,14 @@ BitSet::~BitSet()
void BitSet::intoStringBuffer(misc::StringBuffer *sb)
{
sb->append("[");
- for(int i = 0; i < numBytes; i++)
+ for (int i = 0; i < numBytes; i++)
sb->append(get(i) ? "1" : "0");
sb->append("]");
}
bool BitSet::get(int i)
{
- if(8 * i >= numBytes)
+ if (8 * i >= numBytes)
return false;
else
return bits[i / 8] & (1 << (i % 8));
@@ -211,17 +187,17 @@ bool BitSet::get(int i)
void BitSet::set(int i, bool val)
{
- if(8 * i >= numBytes) {
+ if (8 * i >= numBytes) {
int newNumBytes = numBytes;
- while(8 * i >= newNumBytes)
+ while (8 * i >= newNumBytes)
newNumBytes *= 2;
bits =
(unsigned char*)realloc(bits, newNumBytes * sizeof(unsigned char));
memset(bits + numBytes, 0, newNumBytes - numBytes);
numBytes = newNumBytes;
}
-
- if(val)
+
+ if (val)
bits[i / 8] |= (1 << (i % 8));
else
bits[i / 8] &= ~(1 << (i % 8));
diff --git a/lout/misc.hh b/lout/misc.hh
index f9184bf3..393bac0c 100644
--- a/lout/misc.hh
+++ b/lout/misc.hh
@@ -31,9 +31,6 @@ template <class T> inline T max (T a, T b, T c)
extern const char *prgName;
void init (int argc, char *argv[]);
-void chop (char *s);
-char *strip (char *s);
-
inline void assertNotReached ()
{
@@ -51,7 +48,7 @@ class Comparable
{
public:
virtual ~Comparable();
-
+
/**
* \brief Compare two objects c1 and c2.
*
@@ -77,19 +74,12 @@ public:
template <class T> class SimpleVector
{
private:
- enum {
- /**
- * \brief Edit this for debugging. Should be optimized by the compiler.
- */
- BOUND_CHECKING = 1
- };
-
T *array;
int num, numAlloc;
inline void resize ()
{
- /* This algorithm was tunned for memory&speed with this huge page:
+ /* This algorithm was tuned for memory&speed with this huge page:
* http://downloads.mysql.com/docs/refman-6.0-en.html.tar.gz
*/
if (array == NULL) {
@@ -112,6 +102,14 @@ public:
this->array = NULL;
}
+ inline SimpleVector (const SimpleVector &o) {
+ this->array = NULL;
+ this->num = o.num;
+ this->numAlloc = o.numAlloc;
+ resize ();
+ memcpy (this->array, o.array, sizeof (T) * num);
+ }
+
inline ~SimpleVector ()
{
if (this->array)
@@ -130,19 +128,23 @@ public:
*
* May be necessary before calling misc::SimpleVector::set.
*/
- inline void increase() { this->num++; this->resize (); }
+ inline void increase() { setSize(this->num + 1); }
/**
- * \brief Set the size explicitely.
+ * \brief Set the size explicitly.
*
- * May be necessary before called before misc::SimpleVector::set.
+ * May be necessary before calling misc::SimpleVector::set.
*/
- inline void setSize(int newSize) { this->num = newSize; this->resize (); }
+ inline void setSize(int newSize) {
+ assert (newSize >= 0);
+ this->num = newSize;
+ this->resize ();
+ }
/**
- * \brief Set the size explicitely and initialize new values.
+ * \brief Set the size explicitly and initialize new values.
*
- * May be necessary before called before misc::SimpleVector::set.
+ * May be necessary before calling misc::SimpleVector::set.
*/
inline void setSize (int newSize, T t) {
int oldSize = this->num;
@@ -157,20 +159,18 @@ public:
* \sa misc::SimpleVector::get
*/
inline T* getRef (int i) {
- if (BOUND_CHECKING)
- assert (i >= 0 && i < this->num);
+ assert (i >= 0 && this->num - i > 0);
return array + i;
}
/**
- * \brief Return the one element, explicitety.
+ * \brief Return the one element, explicitly.
*
* The element is copied, so for complex elements, you should rather used
* misc::SimpleVector::getRef.
*/
inline T get (int i) {
- if (BOUND_CHECKING)
- assert (i >= 0 && i < this->num);
+ assert (i >= 0 && this->num - i > 0);
return this->array[i];
}
@@ -183,8 +183,7 @@ public:
* be necessary before.
*/
inline void set (int i, T t) {
- if (BOUND_CHECKING)
- assert (i >= 0 && i < this->num);
+ assert (i >= 0 && this->num - i > 0);
this->array[i] = t;
}
};
@@ -232,9 +231,9 @@ class BitSet
private:
unsigned char *bits;
int numBytes;
-
+
inline int bytesForBits(int bits) { return bits == 0 ? 1 : (bits + 7) / 8; }
-
+
public:
BitSet(int initBits);
~BitSet();
@@ -255,7 +254,7 @@ private:
size_t poolSize, poolLimit, freeIdx;
SimpleVector <char*> *pools;
SimpleVector <char*> *bulk;
-
+
public:
ZoneAllocator (size_t poolSize) {
this->poolSize = poolSize;
diff --git a/lout/msg.h b/lout/msg.h
new file mode 100644
index 00000000..4993c105
--- /dev/null
+++ b/lout/msg.h
@@ -0,0 +1,39 @@
+#ifndef __MSG_H__
+#define __MSG_H__
+
+#include <stdio.h>
+
+#define prefs_show_msg 1
+
+#define D_STMT_START do
+#define D_STMT_END while (0)
+
+/*
+ * You can disable any MSG* macro by adding the '_' prefix.
+ */
+#define _MSG(...)
+#define _MSG_WARN(...)
+#define _MSG_ERR(...)
+
+
+#define MSG(...) \
+ D_STMT_START { \
+ if (prefs_show_msg){ \
+ printf(__VA_ARGS__); \
+ fflush (stdout); \
+ } \
+ } D_STMT_END
+
+#define MSG_WARN(...) \
+ D_STMT_START { \
+ if (prefs_show_msg) \
+ printf("** WARNING **: " __VA_ARGS__); \
+ } D_STMT_END
+
+#define MSG_ERR(...) \
+ D_STMT_START { \
+ if (prefs_show_msg) \
+ printf("** ERROR **: " __VA_ARGS__); \
+ } D_STMT_END
+
+#endif /* __MSG_H__ */
diff --git a/lout/object.cc b/lout/object.cc
index 7da124fa..9eec028e 100644
--- a/lout/object.cc
+++ b/lout/object.cc
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -186,11 +185,11 @@ int ConstString::hashValue()
int ConstString::compareTo(Comparable *other)
{
String *otherString = (String*)other;
- if(str && otherString->str)
+ if (str && otherString->str)
return strcmp(str, otherString->str);
- else if(str)
+ else if (str)
return 1;
- else if(otherString->str)
+ else if (otherString->str)
return -1;
else
return 0;
@@ -199,7 +198,7 @@ int ConstString::compareTo(Comparable *other)
int ConstString::hashValue(const char *str)
{
- if(str) {
+ if (str) {
int h = 0;
for (int i = 0; str[i]; i++)
h = (h * 256 + str[i]);
@@ -223,7 +222,7 @@ String::String (const char *str): ConstString (str ? strdup(str) : NULL)
String::~String ()
{
- if(str)
+ if (str)
delete str;
}
@@ -239,9 +238,9 @@ PairBase::PairBase(Object *first, Object *second)
PairBase::~PairBase()
{
- if(first)
+ if (first)
delete first;
- if(second)
+ if (second)
delete second;
}
@@ -251,7 +250,7 @@ bool PairBase::equals(Object *other)
return
// Identical?
- this == other ||
+ this == other || (
(// Both first parts are NULL, ...
(first == NULL && otherPair->first == NULL) ||
// ... or both first parts are not NULL and equal
@@ -260,18 +259,18 @@ bool PairBase::equals(Object *other)
// Same with second part.
((second == NULL && otherPair->second == NULL) ||
(second != NULL && otherPair->second != NULL
- && second->equals (otherPair->second)));
+ && second->equals (otherPair->second))));
}
int PairBase::hashValue()
{
int value = 0;
- if(first)
+ if (first)
value ^= first->hashValue();
- if(second)
+ if (second)
value ^= second->hashValue();
-
+
return value;
}
@@ -279,14 +278,14 @@ void PairBase::intoStringBuffer(misc::StringBuffer *sb)
{
sb->append("<pair: ");
- if(first)
+ if (first)
first->intoStringBuffer(sb);
else
sb->append("(nil)");
sb->append(",");
- if(second)
+ if (second)
second->intoStringBuffer(sb);
else
sb->append("(nil)");
@@ -298,9 +297,9 @@ size_t PairBase::sizeOf()
{
size_t size = 0;
- if(first)
+ if (first)
size += first->sizeOf();
- if(second)
+ if (second)
size += second->sizeOf();
return size;
diff --git a/lout/object.hh b/lout/object.hh
index 7d505c99..789542fe 100644
--- a/lout/object.hh
+++ b/lout/object.hh
@@ -40,7 +40,7 @@ class Pointer: public Object
{
private:
void *value;
-
+
public:
Pointer(void *value) { this->value = value; }
bool equals(Object *other);
@@ -93,9 +93,9 @@ public:
int hashValue();
int compareTo(Comparable *other);
void intoStringBuffer(misc::StringBuffer *sb);
-
+
inline const char *chars() { return str; }
-
+
static int hashValue(const char *str);
};
diff --git a/lout/signal.cc b/lout/signal.cc
index 46aae626..35c16fbb 100644
--- a/lout/signal.cc
+++ b/lout/signal.cc
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -38,7 +37,7 @@ Emitter::Emitter ()
Emitter::~Emitter ()
{
- for(Iterator<Receiver> it = receivers->iterator (); it.hasNext (); ) {
+ for (Iterator<Receiver> it = receivers->iterator (); it.hasNext (); ) {
Receiver *receiver = it.getNext ();
receiver->unconnectFrom (this);
}
@@ -77,7 +76,7 @@ void Emitter::connect (Receiver *receiver)
*/
void Emitter::emitVoid (int signalNo, int argc, Object **argv)
{
- for(Iterator <Receiver> it = receivers->iterator (); it.hasNext (); ) {
+ for (Iterator <Receiver> it = receivers->iterator (); it.hasNext (); ) {
Receiver *receiver = it.getNext();
emitToReceiver (receiver, signalNo, argc, argv);
}
@@ -93,7 +92,7 @@ bool Emitter::emitBool (int signalNo, int argc, Object **argv)
{
bool b = false, bt;
- for(Iterator <Receiver> it = receivers->iterator (); it.hasNext (); ) {
+ for (Iterator <Receiver> it = receivers->iterator (); it.hasNext (); ) {
Receiver *receiver = it.getNext();
// Note: All receivers are called, even if one returns true.
// Therefore, something like
@@ -118,7 +117,7 @@ Receiver::Receiver()
Receiver::~Receiver()
{
- for(Iterator<Emitter> it = emitters->iterator(); it.hasNext(); ) {
+ for (Iterator<Emitter> it = emitters->iterator(); it.hasNext(); ) {
Emitter *emitter = it.getNext();
emitter->unconnect (this);
}
diff --git a/lout/signal.hh b/lout/signal.hh
index c96247be..6b332203 100644
--- a/lout/signal.hh
+++ b/lout/signal.hh
@@ -23,7 +23,7 @@
*
* Typically, signals are grouped. To define a signal group \em bar for your
* class \em Foo, you have to define two classes, the emitter and the
- * receiver (BarEmitter and BarReceiver), and instanciate the emitter:
+ * receiver (BarEmitter and BarReceiver), and instantiate the emitter:
*
* \dot
* digraph G {
@@ -130,7 +130,7 @@
*
* <h4>Emitters</h4>
*
- * Emitters are typically instanciated one, for one object emitting the
+ * Emitters are typically instantiated one, for one object emitting the
* signals. In the example above, the class Foo will contain a field
* "BarEmitter barEmitter" (not as a pointer, "BarEmitter *barEmitter").
*
@@ -160,7 +160,7 @@
* // ...
* };
* \endcode
- *
+ *
* The constructor of Qix should then set \em qix:
*
* \code
@@ -217,7 +217,7 @@ private:
container::typed::List <Receiver> *receivers;
void unconnect (Receiver *receiver);
-
+
protected:
void emitVoid (int signalNo, int argc, Object **argv);
bool emitBool (int signalNo, int argc, Object **argv);