Some of the Object::equals
now are const correct.
There's more to do. Why make this const-correct, instead of ditch it? Because whatever I replace it with has to be ready for const correctness.
This commit is contained in:
@ -47,15 +47,17 @@ Iterator::~Iterator()
|
||||
{
|
||||
}
|
||||
|
||||
bool Iterator::equals (Object *other)
|
||||
bool
|
||||
Iterator::equals( const Object *const other ) const
|
||||
{
|
||||
Iterator *otherIt = (Iterator*)other;
|
||||
Iterator *const otherIt = const_cast< Iterator * >( dynamic_cast< const Iterator * >( other ) );
|
||||
return
|
||||
this == otherIt ||
|
||||
(getWidget() == otherIt->getWidget() && compareTo(otherIt) == 0);
|
||||
(const_cast< Iterator * >( this )->getWidget() == otherIt->getWidget() && const_cast< Iterator * >( this )->compareTo(otherIt) == 0);
|
||||
}
|
||||
|
||||
void Iterator::intoStringBuffer(misc::StringBuffer *sb)
|
||||
void
|
||||
Iterator::intoStringBuffer(misc::StringBuffer *sb) const
|
||||
{
|
||||
sb->append ("{ widget = ");
|
||||
//widget->intoStringBuffer (sb);
|
||||
@ -68,7 +70,7 @@ void Iterator::intoStringBuffer(misc::StringBuffer *sb)
|
||||
Content::maskIntoStringBuffer (mask, sb);
|
||||
|
||||
sb->append (", content = ");
|
||||
Content::intoStringBuffer (&content, sb);
|
||||
Content::intoStringBuffer (const_cast< Content * >( &content ), sb);
|
||||
|
||||
sb->append (" }");
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ private:
|
||||
Content::Type mask;
|
||||
|
||||
public:
|
||||
bool equals (Object *other);
|
||||
void intoStringBuffer(lout::misc::StringBuffer *sb);
|
||||
bool equals (const Object *other) const override;
|
||||
void intoStringBuffer(lout::misc::StringBuffer *sb) const override;
|
||||
|
||||
inline Widget *getWidget () { return widget; }
|
||||
inline Content *getContent () { return &content; }
|
||||
|
@ -155,7 +155,7 @@ bool StyleAttrs::sizeDiffs (StyleAttrs *otherStyle)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StyleAttrs::equals (object::Object *other) {
|
||||
bool StyleAttrs::equals (const object::Object *other) const {
|
||||
StyleAttrs *otherAttrs = (StyleAttrs *) other;
|
||||
|
||||
return this == otherAttrs ||
|
||||
@ -398,7 +398,7 @@ void Style::copyAttrs (StyleAttrs *attrs)
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
bool FontAttrs::equals(object::Object *other)
|
||||
bool FontAttrs::equals(const object::Object *other) const
|
||||
{
|
||||
FontAttrs *otherAttrs = (FontAttrs*)other;
|
||||
return
|
||||
@ -456,7 +456,7 @@ bool Font::exists (Layout *layout, const char *name)
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
bool ColorAttrs::equals(object::Object *other)
|
||||
bool ColorAttrs::equals(const object::Object *other) const
|
||||
{
|
||||
ColorAttrs *oc = (ColorAttrs*)other;
|
||||
return this == oc || (color == oc->color);
|
||||
|
@ -508,7 +508,7 @@ public:
|
||||
int top, right, bottom, left;
|
||||
|
||||
inline void setVal(int val) { top = right = bottom = left = val; }
|
||||
inline bool equals (Box *other) {
|
||||
inline bool equals (const Box *other) const {
|
||||
return top == other->top &&
|
||||
right == other->right &&
|
||||
bottom == other->bottom &&
|
||||
@ -603,7 +603,7 @@ public:
|
||||
inline bool hasBackground ()
|
||||
{ return backgroundColor != NULL || backgroundImage != NULL; }
|
||||
|
||||
bool equals (lout::object::Object *other);
|
||||
bool equals (const lout::object::Object *other) const override;
|
||||
int hashValue ();
|
||||
};
|
||||
|
||||
@ -688,7 +688,7 @@ public:
|
||||
FontVariant fontVariant;
|
||||
FontStyle style;
|
||||
|
||||
bool equals(lout::object::Object *other);
|
||||
bool equals(const lout::object::Object *other) const override;
|
||||
int hashValue();
|
||||
};
|
||||
|
||||
@ -742,7 +742,7 @@ public:
|
||||
|
||||
inline int getColor () { return color; }
|
||||
|
||||
bool equals(lout::object::Object *other);
|
||||
bool equals(const lout::object::Object *other) const override;
|
||||
int hashValue();
|
||||
};
|
||||
|
||||
|
@ -313,7 +313,7 @@ int List::size ()
|
||||
return numElements;
|
||||
}
|
||||
|
||||
bool List::equals(Object *other)
|
||||
bool List::equals(const Object *other) const
|
||||
{
|
||||
List *otherList = (List*)other;
|
||||
Node *node1 = first, *node2 = otherList->first;
|
||||
|
@ -242,7 +242,7 @@ public:
|
||||
List(bool ownerOfObjects);
|
||||
~List();
|
||||
|
||||
bool equals(Object *other);
|
||||
bool equals(const Object *other) const override;
|
||||
int hashValue();
|
||||
|
||||
int size ();
|
||||
@ -451,8 +451,8 @@ public:
|
||||
Collection () { this->base = NULL; }
|
||||
~Collection () { if (this->base) delete this->base; }
|
||||
|
||||
bool equals(Object *other)
|
||||
{ return this->base->equals (((Collection<T>*)other)->base); }
|
||||
bool equals(const Object *other) const override
|
||||
{ return this->base->equals (((const Collection<T>*)other)->base); }
|
||||
|
||||
int hashValue() { return this->base->hashValue (); }
|
||||
|
||||
|
@ -48,7 +48,8 @@ Object::~Object()
|
||||
* this makes casting of "other" safe. Typically, an implementation should
|
||||
* check this == other first, the caller can assume a fast implementation.
|
||||
*/
|
||||
bool Object::equals(Object *other)
|
||||
bool
|
||||
Object::equals( const Object *const other ) const
|
||||
{
|
||||
misc::assertNotReached ();
|
||||
return false;
|
||||
@ -149,7 +150,7 @@ StandardComparator standardComparator;
|
||||
// Pointer
|
||||
// -------------
|
||||
|
||||
bool Pointer::equals(Object *other)
|
||||
bool Pointer::equals(const Object *other) const
|
||||
{
|
||||
return value == ((Pointer*)other)->value;
|
||||
}
|
||||
@ -187,7 +188,7 @@ void Pointer::intoStringBuffer(misc::StringBuffer *sb)
|
||||
// Integer
|
||||
// -------------
|
||||
|
||||
bool Integer::equals(Object *other)
|
||||
bool Integer::equals(const Object *other) const
|
||||
{
|
||||
return value == ((Integer*)other)->value;
|
||||
}
|
||||
@ -213,7 +214,7 @@ int Integer::compareTo(Comparable *other)
|
||||
// Boolean
|
||||
// -------------
|
||||
|
||||
bool Boolean::equals(Object *other)
|
||||
bool Boolean::equals(const Object *other) const
|
||||
{
|
||||
bool value2 = ((Boolean*)other)->value;
|
||||
// TODO Does "==" work?
|
||||
@ -239,7 +240,7 @@ int Boolean::compareTo(Comparable *other)
|
||||
// ConstString
|
||||
// -----------------
|
||||
|
||||
bool ConstString::equals(Object *other)
|
||||
bool ConstString::equals(const Object *other) const
|
||||
{
|
||||
ConstString *otherString = (ConstString*)other;
|
||||
return
|
||||
@ -317,7 +318,7 @@ PairBase::~PairBase()
|
||||
delete second;
|
||||
}
|
||||
|
||||
bool PairBase::equals(Object *other)
|
||||
bool PairBase::equals(const Object *other) const
|
||||
{
|
||||
PairBase *otherPair = (PairBase*)other;
|
||||
|
||||
@ -347,7 +348,7 @@ int PairBase::hashValue()
|
||||
return value;
|
||||
}
|
||||
|
||||
void PairBase::intoStringBuffer(misc::StringBuffer *sb)
|
||||
void PairBase::intoStringBuffer(misc::StringBuffer *sb) const
|
||||
{
|
||||
sb->append("<pair: ");
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "misc.hh"
|
||||
|
||||
namespace lout {
|
||||
@ -25,7 +27,8 @@ class Object
|
||||
{
|
||||
public:
|
||||
virtual ~Object();
|
||||
virtual bool equals(Object *other);
|
||||
virtual bool equals(const Object *other) const;
|
||||
virtual bool equals(Object *other) final { return equals( &std::as_const( *other ) ); }
|
||||
virtual int hashValue();
|
||||
virtual Object *clone();
|
||||
virtual void intoStringBuffer(misc::StringBuffer *sb) const;
|
||||
@ -103,7 +106,7 @@ private:
|
||||
|
||||
public:
|
||||
Pointer(void *value) { this->value = value; }
|
||||
bool equals(Object *other);
|
||||
bool equals(const Object *other) const override;
|
||||
int hashValue();
|
||||
void intoStringBuffer(misc::StringBuffer *sb);
|
||||
inline void *getValue() { return value; }
|
||||
@ -129,7 +132,7 @@ class Integer: public Comparable
|
||||
|
||||
public:
|
||||
Integer(int value) { this->value = value; }
|
||||
bool equals(Object *other);
|
||||
bool equals(const Object *other) const override;
|
||||
int hashValue();
|
||||
void intoStringBuffer(misc::StringBuffer *sb);
|
||||
int compareTo(Comparable *other);
|
||||
@ -146,7 +149,7 @@ class Boolean: public Comparable
|
||||
|
||||
public:
|
||||
Boolean(bool value) { this->value = value; }
|
||||
bool equals(Object *other);
|
||||
bool equals(const Object *other) const override;
|
||||
int hashValue();
|
||||
void intoStringBuffer(misc::StringBuffer *sb);
|
||||
int compareTo(Comparable *other);
|
||||
@ -166,7 +169,7 @@ protected:
|
||||
|
||||
public:
|
||||
ConstString(const char *str) { this->str = str; }
|
||||
bool equals(Object *other);
|
||||
bool equals(const Object *other) const override;
|
||||
int hashValue();
|
||||
int compareTo(Comparable *other);
|
||||
void intoStringBuffer(misc::StringBuffer *sb);
|
||||
@ -201,9 +204,9 @@ public:
|
||||
PairBase(Object *first, Object *second);
|
||||
~PairBase();
|
||||
|
||||
bool equals(Object *other);
|
||||
bool equals(const Object *other) const override;
|
||||
int hashValue();
|
||||
void intoStringBuffer(misc::StringBuffer *sb);
|
||||
void intoStringBuffer(misc::StringBuffer *sb) const override;
|
||||
size_t sizeOf();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user