[xsd-users] Extracting

SHAH, Sima, FM Sima.SHAH at rbos.com
Tue Dec 13 11:22:35 EST 2005


We don't have access to the auto_pointer.  The contents of the iterator
return a reference.  Is there a way to get to the pointer?

Thanks,
Sima

P.S. Your new feature and factory mechanism idea is an excellent idea but
we'd like to be able to do this for all classes not just subclasses.

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: 13 December 2005 15:57
To: SHAH, Sima, FM
Cc: 'xsd-users at codesynthesis.com'
Subject: Re: [xsd-users] Extracting


Hi,

SHAH, Sima, FM <Sima.SHAH at rbos.com> writes:

> I have an element defined as an xsi:type.  To extract it, I need to do 
> a dynamic cast which throws if not the correct type.
>
> Is there a way I can work out what the type is or a visitor pattern to 
> allow me to call a function given the correct type.

You can use dynamic_cast on a pointer instead of a reference. In that case
it will return 0 instead of throwing std::bad_cast. This is an effective way
to test if SomeType is-a SomeOtherType.

One extension that we are thinking about implementing is to allow you to
specify native C++ base classes for XML Schema types. For example, suppose
you have the following schema:

<complexType name="person" nativeBase="person_base">
  <sequence>
    <element name="name" type="xsd:string"/>
  </sequence>
</complexType>

<complexType name="superman">
  <complexContent>
    <extension base="person">
      <attribute name="can-fly" type="xsd:boolean" use="required"/>
    </extension>
  </complexContent>
</complexType>


And the person_base C++ class:

struct person_base
{
  ~person_base ();

  virtual
  ~print () = 0;
};

The generated code for the above schema fragment could look like this:

struct person: xml_schema::type, person_base
{
  string
  name () const;
};

struct superman: person
{
  bool
  can_fly () const;
};


Now, since print is pure virtual, you will need to implement those types:

struct person_impl: person
{
  virtual
  ~print ()
  {
    cout << "person " << name ();
  }
};

struct superman_impl: superman
{
  virtual
  ~print ()
  {
    cout << (can_fly () ? "flying superman " : "superman ") << name ();
  }
};

There would also be a factory mechanism that will allow one to instruct
parsing code to use person_impl and superman_impl for person and superman.
Is anybody interested in such a feature?


hth,
-boris


***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312.       Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.                                      
Authorised and regulated by the Financial Services Authority     
 
This e-mail message is confidential and for use by the                      
addressee only. If the message is received by anyone other             
than the addressee, please return the message to the sender          
by replying to it and then delete the message from your                    
computer. Internet e-mails are not necessarily secure. The               
Royal Bank of Scotland plc does not accept responsibility for          
changes made to this message after it was sent.                              
                                                                                                        
Whilst all reasonable care has been taken to avoid the                   
transmission of viruses, it is the responsibility of the recipient to        
ensure that the onward transmission, opening or use of this             
message and any attachments will not adversely affect its               
systems or data.  No responsibility is accepted by The Royal           
Bank of Scotland plc in this regard and the recipient should carry   
out such virus and other checks as it considers appropriate.           
                                                                                                               Visit our websites at:                                                                          
http://www.rbs.co.uk/CBFM                                                        
http://www.rbsmarkets.com                                                         
                                                                                                       ********************************************************************************




More information about the xsd-users mailing list