summaryrefslogtreecommitdiff
path: root/lout/object.cc
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-03-05 11:34:03 +0100
committerSebastian Geerken <devnull@localhost>2013-03-05 11:34:03 +0100
commit9c98b3c16041ebd41aabbb82e71d424a940a1d47 (patch)
tree496d8b2648a5ad072a2d78b932a4129e7d3dd12d /lout/object.cc
parent49ad0b5252190ffbfb4511131af2032f7f341a60 (diff)
Comparable is now subclass of Object (not pseudo-interface anymore). The old solution would have made RTTI neccessary to work correctly.
Diffstat (limited to 'lout/object.cc')
-rw-r--r--lout/object.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/lout/object.cc b/lout/object.cc
index 85a908b9..059564c0 100644
--- a/lout/object.cc
+++ b/lout/object.cc
@@ -106,6 +106,29 @@ size_t Object::sizeOf()
return sizeof(Object*);
}
+// ----------------
+// Comparable
+// ----------------
+
+/**
+ * \brief This static method may be used as compare function for qsort(3), for
+ * an array of Object* (Object*[] or Object**).
+ */
+int Comparable::compareFun(const void *p1, const void *p2)
+{
+ Comparable *c1 = *(Comparable**)p1;
+ Comparable *c2 = *(Comparable**)p2;
+
+ if (c1 && c2)
+ return ((c1)->compareTo(c2));
+ else if (c1)
+ return 1;
+ else if (c2)
+ return -1;
+ else
+ return 0;
+}
+
// -------------
// Pointer
// -------------