diff options
Diffstat (limited to 'lout')
-rw-r--r-- | lout/object.cc | 26 | ||||
-rw-r--r-- | lout/object.hh | 17 |
2 files changed, 43 insertions, 0 deletions
diff --git a/lout/object.cc b/lout/object.cc index 74328d22..e4e0152a 100644 --- a/lout/object.cc +++ b/lout/object.cc @@ -211,6 +211,32 @@ int Integer::compareTo(Comparable *other) return value - ((Integer*)other)->value; } +// ------------- +// Boolean +// ------------- + +bool Boolean::equals(Object *other) +{ + bool value2 = ((Boolean*)other)->value; + // TODO Does "==" work? + return (value && value2) || (!value && value2); +} + +int Boolean::hashValue() +{ + return value ? 1 : 0; +} + +void Boolean::intoStringBuffer(misc::StringBuffer *sb) +{ + sb->append(value ? "true" : "false"); +} + +int Boolean::compareTo(Comparable *other) +{ + return (value ? 1 : 0) - (((Boolean*)other)->value ? 1 : 0); +} + // ----------------- // ConstString // ----------------- diff --git a/lout/object.hh b/lout/object.hh index 5a4935c5..3ba7b590 100644 --- a/lout/object.hh +++ b/lout/object.hh @@ -138,6 +138,23 @@ public: /** + * \brief An object::Object wrapper for bool's. + */ +class Boolean: public Comparable +{ + bool value; + +public: + Boolean(bool value) { this->value = value; } + bool equals(Object *other); + int hashValue(); + void intoStringBuffer(misc::StringBuffer *sb); + int compareTo(Comparable *other); + inline bool getValue() { return value; } +}; + + +/** * \brief An object::Object wrapper for constant strings (char*). * * As opposed to object::String, the char array is not copied. |