[xsd-users] Polymorphic problems.

Boris Kolpackov boris at codesynthesis.com
Tue Dec 2 07:31:38 EST 2008


Hi Bill,

Bill Pringlemeir <bpringle at sympatico.ca> writes:

> In the type-serializer-map.hxx and type-serializer-map.hxx, there is a
> map typed to,
> 
>    typedef
>    std::map<const type_id*, type_info, type_id_comparator>
>    type_map;
> 
> The STL map only need a function like the 'before' implementation.
> The problem (or so I believe) is that code like,
> 
>    type_serializer_map::find (const type_id& tid) const
>    {
>       typename type_map::const_iterator i (type_map_.find (&tid));
>       return i == type_map_.end () ? 0 : &i->second;
>    }
> 
> 
> The &tid is taking a pointer to satisify the 'const type_id*' of the
> map.  However, the pointer value (memory address) of the typeid(x) is
> not always binary.  This can be true if different shared libaries are
> used and the compiler has several RTTI structures for identical type
> infos.

The pointers to std::type_info are only used to store references to the
objects and not to compare them. If you look at the implementation of
type_id_comparator (passed as the third template argument to std::map),
you will see that it compares the two objects using the before()
function provided by type_info:

struct type_id_comparator
{
  bool
  operator() (const type_id* x, const type_id* y) const
  {
    return x->before (*y);
  }
};

This means that even if the type_info object in the map and the one
passed to find() are different, the map search should still work
properly (provided the C++ implementation is conformant).


> We are having platform dependent problems with polymorphic
> serialization and from debugging, this seems to be the problem.

Which platform is it? If it is Windows, then it could be the
issue with DLLs and/or the executable having separate maps.
This problem can be resolved with the help of the --export-maps
and --import-maps options. See their documentation in the XSD
Compiler Command Line Manual for details:

http://www.codesynthesis.com/projects/xsd/documentation/xsd.xhtml

Boris




More information about the xsd-users mailing list