TShape replaces MGraphic where it was used in previous examples.
Here is the portion of TShape's interface specific to TShape.
class TShape : public MGraphic
{
public:
TShape(MGraphic* graphicToAdopt);
// Other constructors, destructor, operator= omitted...
// Getters and setters omitted...
// MGraphic protocol omitted...
// Streaming omitted...
virtual Boolean IsEqual(const MCollectible*) const;
virtual long Hash() const;
Boolean operator== (const TShape&) const;
Boolean operator!= (const TShape&) const;
private:
MGraphic* fGraphic;
TGlobalID fUniqueID;
enum { kOriginalVersion };
};
==, and operator != all use fUniqueID only. The implementation of IsEqual is typical.
Boolean TShape::IsEqual(const MCollectible* other) const
{
if (GetClassNameAsToken() == other->GetClassNameAsToken()) {
return fUniqueID == ((const TShape*)other)->fUniqueID;
}
return FALSE;
}