[xsd-users] comparison question

Boris Kolpackov boris at codesynthesis.com
Fri Jun 27 04:13:27 EDT 2008


Hi Ray,

Rizzuto, Raymond <Raymond.Rizzuto at sig.com> writes:

> operator== would have to e a virtual member function - I'm not sure if 
> that is allowed or not.

I think this is allowed though you will have to use the same type
for the right-hand-side operand in order for the virtual mechanism
to work. A cleaner approach would be to provide a virtual compare()
function which is called by operator==(). Overall, it will be way
too heavy-weight for the common cases since most comparisons won't
need rtti/virtual function mechanism (polymorphism is normally used
only in a handful of places).

Generally, the generated comparison operators are provided as a
quick-and-dirty member-wise comparison for simple cases (I am still
not sure it was a good idea to provide them at all). In some cases
this semantics can be completely wrong. Applications that need
comparison for any non-trivial cases (e.g., polymorphic objects)
should provide their own comparison operators.

In your particular case it may be easier to compare the XML
representations (e.g., by serializing them to strings) instead
of the object models (e.g., do XML->OM1->XML1->OM2->XML2 and
compare XML1 and XML2 instead of OM1 and OM2).

Boris




More information about the xsd-users mailing list