[xsde-users] XSDE : choice_arm function code generation question

Yegnaram, Shrikant SYegnaram at cls-bank.com
Wed Feb 9 00:36:14 EST 2022


Hi
We have an internal XSD for which we are generating C++ code using XSDE tool - xsde-3.2.0-x86_64-linux-gnu .
We are using following options for code generation
cxx-hybrid  --generate-parser --generate-aggregate --generate-inline --omit-default-attributes  --generate-serializer

Our XSD snippet is as below :
<xs:complexType name="XYZ_CONTROL_CLASS">
<xs:sequence>
<xs:element name="clsGteVmaMessage" type="XYZ_CONTROL_MESSAGES"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="XYZ_COM_INPUT_CLASS">
<xs:sequence>
<xs:element name="__switch" type="XYZ_COM_INPUT_MESSAGES"/>
<xs:choice>
<!--1,com_input-->
<xs:element name="comInput" type="XYZ_COM_INPUT_MESSAGE"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="CLS_GTS_SES_INPUT_CLASS">
<xs:sequence>
<xs:element name="__switch" type="ABC_INPUT_CLASS"/>
<xs:choice>
<xs:element name="splitResubmission" type="XYZ_RESUBMITTED_SPLIT"/>
<xs:element name="rescind" type="XYZ_RESCIND" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:element name="XYZMessage" type="XYZMessageClass"/>
<xs:complexType name="XYZMessageClass">
<xs:sequence>
<xs:element name="__switch" type="XYZ_MSG_CLASSES"/>
<xs:choice>
<!--0,gc_vma_class_control-->
<xs:element name="control" type="XYZ_CONTROL_CLASS"/>
<!--2,gc_vma_class_com_input-->
<xs:element name="comInput" type="XYZ_COM_INPUT_CLASS"/>
<!--7,gc_vma_class_abc_input-->
<xs:element name="abcInputClass" type="ABC_INPUT_CLASS"/>
<!--15,gc_vma_class_notification-->
<xs:element name="notification" type="XYZ_NOTIFICATION_CLASS"/>
...
...
</xs:choice>


The xmlevents.hxx generated is as in below snippet

class XYZMessageClass
{
...

    private:
    ::xmlevents::XYZ_MSG_CLASSES __switch_;
    union
    {
      union
      {
        size_t align_;
        char data_[sizeof (::xmlevents::XYZ_CONTROL_CLASS)];
      } control_;
      ::xmlevents::XYZ_COM_INPUT_CLASS* comInput_;
      ::xmlevents::ABC_INPUT_CLASS* abcInputClass_;
      ::xmlevents::XYZ_NOTIFICATION_CLASS* notification_;

...
};

The corresponding xmlevents.cxx snippet of code is as below

  void XYZMessageClass::
  choice_arm (choice_arm_tag x)
  {
    if (this->choice_arm_ == x)
      return;

    switch (this->choice_arm_)
    {
      case control_tag:
      {
        typedef ::xmlevents::XYZ_CONTROL_CLASS _dtor;
        reinterpret_cast< ::xmlevents::XYZ_CONTROL_CLASS& > (this->choice_.control_).~_dtor ();
        break;
      }
      case comInput_tag:
      {
        delete this->choice_.comInput_;
        break;
      }
      case abcInputClass_tag:
      {
        delete this->choice_.abcInputClass_;
        break;
      }

     ...

    this->choice_arm_ = choice_arm_tag (57);

    switch (x)
    {
      case control_tag:
      {
        new (&this->choice_.control_) ::xmlevents::XYZ_CONTROL_CLASS;
        break;
      }
      case comInput_tag:
      {
        this->choice_.comInput_ = 0;
        break;
      }
      case abcInputClass_tag:
      {
        this->choice_.abcInputClass_ = 0;
        break;
      }

    ...

    this->choice_arm_ = x;
}


The question here is regarding elements like XYZMessage.comInput are not allocated / deallocated  memory in the choice_arm function like XYZMessage.control field.
Our question is huge and cannot share entire details .
We are trying to understand why XSDE is not generating code to allocate/deallocate memory for XYZMessage.comInput like XYZMessage.control field in the choice_arm function.

We would want to know

  1.  Why is XSDE creating union {align,data_} for some of the classes in the xs:choice and not for others? We would like to understand this better.
  2.  If we can change the default behaviour to generate allocate/deallocate memory code for all such enums using any XSDE code generation options in choice_arm function
  3.  What is the ideal way to create these objects for serialization

Thanks,
Shrikant Yegnaram

CLS Classification: Confidential Information

This email was classified by Yegnaram, Shrikant on Wednesday, February 9, 2022 12:35:05 AM

CLS is committed to protecting and safeguarding your personal data. Our privacy notice<https://www.cls-group.com/privacy> provides you with information about how we process and protect your personal data. We aim to ensure direct marketing is reasonable, proportionate and of relevance to you. However, if you no longer want to receive direct marketing from us please email dpo at cls-services.com<mailto:dpo at cls-services.com>.

************************************************************************************
WARNING:
This message contains confidential information and is intended only for the individual named.  If you are not the named addressee, you should not disseminate, distribute or copy this e-mail.  Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.

E-mails are not encrypted and cannot be guaranteed to be secure or error-free, as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.  The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of this e-mail transmission.  If verification is required, please request a hard copy version.

************************************************************************************
WARNING:
This message contains confidential information and is intended only for the individual named.  If you are not the named addressee, you should not disseminate, distribute or copy this e-mail.  Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.

E-mails are not encrypted and cannot be guaranteed to be secure or error-free, as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.  The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of this e-mail transmission.  If verification is required, please request a hard copy version.

CLS is committed to protecting and safeguarding your personal data. Our privacy notice ( https://www.cls-group.com/privacy) provides you with information about how we process and protect your personal data. We aim to ensure direct marketing is reasonable, proportionate and of relevance to you. However, if you no longer want to receive direct marketing from us please email dpo at cls-services.com


More information about the xsde-users mailing list