aboutsummaryrefslogtreecommitdiff
path: root/lout/object.hh
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.hh
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.hh')
-rw-r--r--lout/object.hh30
1 files changed, 28 insertions, 2 deletions
diff --git a/lout/object.hh b/lout/object.hh
index 9df69987..fd612863 100644
--- a/lout/object.hh
+++ b/lout/object.hh
@@ -34,6 +34,32 @@ public:
};
/**
+ * \brief Instances of a sub class of may be compared (less, greater).
+ *
+ * Used for sorting etc.
+ */
+class Comparable: public Object
+{
+public:
+ /**
+ * \brief Compare two objects c1 and c2.
+ *
+ * Return a value < 0, when c1 is less than c2, a value > 0, when c1
+ * is greater than c2, or 0, when c1 and c2 are equal.
+ *
+ * If c1.equals(c2) (as defined in Object), c1.compareTo(c2) must
+ * be 0, but, unlike you may expect, the reversed is not
+ * necessarily true. This method returns 0, if, according to the
+ * rules for sorting, there is no difference, but there may still
+ * be differences (not relevant for sorting), which "equals" will
+ * care about.
+ */
+ virtual int compareTo(Comparable *other) = 0;
+
+ static int compareFun(const void *p1, const void *p2);
+};
+
+/**
* \brief An object::Object wrapper for void pointers.
*/
class Pointer: public Object
@@ -63,7 +89,7 @@ public:
/**
* \brief An object::Object wrapper for int's.
*/
-class Integer: public Object, misc::Comparable
+class Integer: public Comparable
{
int value;
@@ -82,7 +108,7 @@ public:
*
* As opposed to object::String, the char array is not copied.
*/
-class ConstString: public Object, misc::Comparable
+class ConstString: public Comparable
{
protected:
const char *str;