[xsd-users] Ostream operator for optional containers

Rance Kirtley rkirtley at asinc.com
Wed Aug 6 09:51:32 EDT 2008


Boris

            I'm using version XSD XML Schema to C++ compiler 3.1.1.a7 and
have a minor problem with ostream operator generator code not handling
optional container types correctly.  For example the schema

 

  <xs:complexType name="ValuePathType">

    <xs:choice>

      <xs:sequence>

        <xs:choice>

          <xs:element name="Attribute" type="NameType" />

          <xs:element name="RemoteAttribute" type="LocationType" />

        </xs:choice>

        <xs:choice minOccurs="0">

          <xs:element name="Offset" type="xs:integer" />

          <xs:element name="TimeStamp" type="xs:time" />

        </xs:choice>

      </xs:sequence>

      <xs:element name="Literal">

        <xs:complexType>

          <xs:group ref="ValueGroup" />

        </xs:complexType>

      </xs:element>

    </xs:choice>

  </xs:complexType>

 

generates the code

 

::std::ostream&

operator<< (::std::ostream& o, const ValuePathType& i)

{

  if (i.Attribute ())

  {

    o << ::std::endl << "Attribute: " << *i.Attribute ();

  }

 

  if (i.RemoteAttribute ())

  {

    o << ::std::endl << "RemoteAttribute: " << *i.RemoteAttribute ();

  }

 

  if (i.Offset ())

  {

    o << ::std::endl << "Offset: " << *i.Offset ();

  }

 

  if (i.TimeStamp ())

  {

    o << ::std::endl << "TimeStamp: " << *i.TimeStamp ();

  }

 

  if (i.Literal ())

  {

    o << ::std::endl << "Literal: " << *i.Literal ();

  }

 

  return o;

}

 

We get compile errors because the TimeStamp is in an optional container.  My
work-around is to further qualify the statement; eg

    o << ::std::endl << "TimeStamp: " <<  (*i.TimeStamp ()).hours();

 

 

Not a big issue, just reporting.

            Rance

 

 




More information about the xsd-users mailing list