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:
2025-08-22 13:58:05 -04:00
parent f6841f59e0
commit e4f1102e32
8 changed files with 38 additions and 32 deletions

View File

@ -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 (" }");
}

View File

@ -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; }

View File

@ -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);

View File

@ -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();
};