// Quality.h #ifndef Quality_H #define Quality_H // Quality is an abtract base class for indicating quality. The // meaning of quality and the number and types of objects for which // the quality is evaluated are defined by derived classes. // // Quality provides two public methods: // 1. is_valid() returns true if the quality is acceptable // 2. is_better_than(const Quality&) returns true if the current // quality is better than the arguemnt. // // A quality is typically constructed from two objects but more // or less are possible. The quality might indicate the nearness // or overlap between the objects. // // Examples include the distance between two points, the distance // between a point and a line and the overlap volume between // N spheres. In any case, better coul be defined as a smaller // or larger value. // // For most applications where it is not neccessary to discriminate // between qualities of different types, the concrete classes // InvalidQuality and SimpleQuality can be used instead of introducing // a new subclass. The former is always invalid and the latter is // always valid and uses a double (smaller is better) as the measure // of quality. // class Quality { private: // methods // User-supplied comparison. // Return true if the current quality is better than the argument. // This is used by the method is_better_than. // It is guaranteed that both qualities are valid and of the same // type. virtual bool _is_better_than(const Quality& quality) const =0; public: // methods // return the type virtual void* get_type() const =0; // Is the distance between the pair in the allowed range? // Override this if neccessary. virtual bool is_valid() const; // Is this quality better than the specified one? // A valid quality is always better than an invalid one. // Return false if both are invalid. // Return false if the qualities are valid and of different type. // Do not override this method--use _is_better_than. bool is_better_than(const Quality& quality) const; }; #endif