TShape identifies a portion of the data

The code in this example defines TShape, a derived class of MGraphic, that delegates all its MGraphic calls to another MGraphic that it owns. TShape uses a TGlobalID to distinguish TShape instances from each other. IsEqual and comparison operators use only this ID, and not the wrapped MGraphic, to perform comparisons.

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 };
      };
IsEqual, Hash, operator==, 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;
      }

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker