[xsd-users] Constructors

Jean-Francois Dube jf at magnu.polymtl.ca
Fri Feb 24 16:42:51 EST 2006


  Would it be possible for the derived object to receive a base class 
object as argument at construction.

For instance, in the polymorphism example, the superman_type class would 
also have the following for constructor:

superman_type (person_type const&, can_fly::type const&);

This little example shows how it would be useful. I have a myPerson 
class and a derived mySuperman class, and I use wrappers to transfert 
the content of my objects into xsd person_type and superman_type for 
serialization, as such:

//////////////////////////////////////////////////////

// wrapper for the base class
person_type PersonWrapper::toXsd( myPersonType& const )
{
    // create a xsd person_type handler for my own myPersonType object
}

// wrapper for the derived class
superman_type SupermanWrapper::toXsd( mySupermanType& const my_hero )
{
    // take care of the Clark Kent part
    person_type a_xsd_person ( PersonWrapper::toXsd(my_hero) ) ;

    // add the superhero part
    superman_type a_xsd_superman ( a_xsd_person, my_hero.getCanFly() ) ;
   
    // then add optional and sequence properties for superman_type, if any

    return a_xsd_superman;  // I could use new and auto_ptr....
}

//////////////////////////////////////////////////////

That way, we don't have to duplicate the code that relates to the base 
class in the derived class wrapper.

Also, is there a reason to prevent the generated handlers from having a 
default constructor?

I understand that the current constructors prevent us from generating 
incomplete objects (per schema), but it would be convenient to be able 
to transfert all data to the xsd handlers using the standard accessors.

It the previous example, it would have given the option of creating an 
empty superman_type (using the default contructor) outside of the 
wrapper and to pass it by reference to the wrapper (where it could be 
filled using the accessors).

I also suspect that the constructor calls can become quite confusing for 
large objects.




More information about the xsd-users mailing list