[xsd-users] unexpected_enumerator

Lars laasunde at hotmail.com
Thu Mar 3 07:23:09 EST 2016


Hello,
 
We have used codesynthesis 4.0 to generated C++ code for a long time. Recently we needed to add an enumerator to that schema. However the generated C++ code now throws an unexpected_enumerator exception when loading an xml. We have use oxygen to validate the xml file against the updated schema and it is valid. So for some reason the C++ code does not like the updated schema.
 
Here is the schema addition;
<xs:element name="Type" >
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:enumeration value="aaa"/>
      <xs:enumeration value="bbb"/>
      <xs:enumeration value="ccc"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>
 Debugging the exception I found the below generated C++ code: Type::value Type::
_xsd_Type_convert () const
{
  ::xsd::cxx::tree::enum_comparator< char > c (_xsd_Type_literals_);
  const value* i (::std::lower_bound (
                    _xsd_Type_indexes_,
                    _xsd_Type_ + 3,
                    *this,
                    c));

  //******************************************************
  // Debugging code
  //******************************************************
  xsd::cxx::tree::_type lhs(_xsd_Type_literals_[*i]); // empty
  xsd::cxx::tree::_type rhs(*this); // contains value "bbb"
  bool comp = (lhs != rhs);             // equals true
  //******************************************************

  if (i == _xsd_Type_indexes_ + 3 || _xsd_Type_literals_[*i] != *this)
  {
    throw ::xsd::cxx::tree::unexpected_enumerator < char > (*this);
  }

  return *i;
}

const char* const Type::
_xsd_Type_literals_[3] =
{
  "aaa",
  "bbb",
  "ccc"
};

const Type::value Type::
_xsd_Type_indexes_[3] =
{
  ::Domain::App_1::Type::ccc,
  ::Domain::App_1::Type::aaa,
  ::Domain::App_1::Type::bbb
};
   The second part of the if statement is evalated to true which causes the exception. However viewing the _xsd_Type_literals_[*i] and *this part with the debugger they both appear to contain the same value. Stepping into the expression it looks like _xsd_Type_literals_[*i] is converted into a xsd::cxx:tree::_type using the template<typename C> _type(const C* s); constructor. This constructor ignores the string and creates an empty instance. That means the left-hand-side of the expression loses it value in the type convertion. Any comparisson after that will be faulty.  What can cause this behaviour? Have we configured codesynthesis incorrectly ? Appreciate any input on the matter.  kind regards, Lars  		 	   		  


More information about the xsd-users mailing list