[xsde-users] Re: Determine whether an object model supports polymorphism

Thomas Frenzel (TomSun) tftomsun at streamteam.de
Tue Oct 20 10:58:41 EDT 2009


Hi Boris,

Quote 1:
I am also having a hard time imagining where would such a test be  
useful. I can see where checking if a particular type (as opposed  
to the whole object model) is polymorphic can be useful. Can you  
tell us a bit more about what you are trying to achieve?  

I've implemented a template class called "XmlManager<TData,TParser,TSerializer>" that takes the xsde generated ObjectModel class, the Serializer (*_saggr) class and the Parserclass  (*_paggr)  as the type parameters. This template class provides functions like WriteToFile(string), ReadFromFile(string), WriteToStream(iostream), ReadFromStream(iostream). 

The XmlManager should work for all xsde generated classes, equal if they use polymorphism or not (i use both variants within the same process). 

Within the XmlManager template class i need the information whether the given object model class uses polymorphism or not in 3 cases (currently the boolean m_polymorphic  indicates if the object model uses polymorphism):

...
TParser parser;
      xml_schema::document_pimpl documentParser(
        parser.root_parser (), parser.root_name (),m_polymorphic);
...

...
 TSerializer serializer;
    xml_schema::document_simpl documentSerializer (
      serializer.root_serializer (), serializer.root_name (),m_polymorphic);
...

...
 if(m_polymorphic)
    {
      documentSerializer.add_prefix("xsi","http://www.w3.org/2001/XMLSchema-instance");
    }
...

At the moment i have always to pass to the constructor of my XmlManager the polymorphic flag. The main idea of the XmlManager is, that nobody needs to know anything about the way how the objects will be serialized/deserialized in the background, also not whether polymorphism is used or not. Additional to the XmlManager i've implemented some nice macros that resolves the serializer and parser class for me so that i only need to pass the generated object model class to serialize/deserialize it. My final code lokes like that:

(MySuperman is the generated class for the xml root object):
...
MySuperman* mySupermanInstance = XML_MANAGER(MySuperman)->ReadFromFile("C:\\temp.xml");
XML_MANAGER(MySuperman)->WriteToFile("C:\\temp_out.xml");
...



Quote 2:
I sent an email outlining the design and asked for feedback but  
haven't heard back. So I figured that you must have gotten pulled  
into something else. Perhaps the email just got lots. Here it is   
in the archives:

oh, this was a misunderstanding. I didn't know, that you wait for a feedback. Yes the implementation looks sufficient for my needs. I am happy as long as i can convert  from the string representation to the numeric representation and vice versa. Maybe an constructor overload that takes the string/char* would be useful, too. It would be nice if you could post the cpp file of your color example.


  _____  

From: Boris Kolpackov [mailto:boris at codesynthesis.com]
To: Thomas Frenzel (TomSun) [mailto:tftomsun at streamteam.de]
Cc: xsde-users at codesynthesis.com
Sent: Tue, 20 Oct 2009 15:24:31 +0200
Subject: Re: Determine whether an object model supports polymorphism

Hi Thomas,
  
  Thomas Frenzel (TomSun) <tftomsun at streamteam.de> writes:
  
  > is there any possibility to determine whether a xml object model has 
  > been generated with polymorphism support? I would like to have a static 
  > bool on the generated object model or the generated parser/serializer 
  > classes. Something like:
  > 
  > bool MyGeneratedRoot.SupportsPolymorphism()
  > 
  > or bool MyGeneratedRoot_paggr.SupportsPolymorphism()
  
  No, there is no such thing at the moment. The closest you can get is
  to check for the XSDE_POLYMORPHIC macro which indicates that the
  runtime library has been built with polymorphism support. However,
  it is still possible to compile the schemas without polymorphism
  support by specifying the --runtime-polymorphic option instead of
  --generate-polymorphic.
  
  I am also having a hard time imagining where would such a test be
  useful. I can see where checking if a particular type (as opposed
  to the whole object model) is polymorphic can be useful. Can you
  tell us a bit more about what you are trying to achieve?
  
  > Btw. you wanted to provide a beta version including the code 
  > generation of enumerations. I am still interested in that beta. :)
  
  I sent an email outlining the design and asked for feedback but
  haven't heard back. So I figured that you must have gotten pulled
  into something else. Perhaps the email just got lots. Here it is 
  in the archives:
  
  http://www.codesynthesis.com/pipermail/xsde-users/2009-October/000158.html
  
  If you can let me know what you think, I can go ahead and implement
  this.
  
  Boris
    


More information about the xsde-users mailing list