[xsd-users] Pointers to references
Mathew Benson
mathew.benson at gmail.com
Sat Mar 1 21:03:26 EST 2014
I'm closer, but now I get a seg fault when it hits the dynamic_cast
statement. I added typid(...).name() on the object retrieved in the
example from the manual to see what type I was actually getting, and see:
N3xsd3cxx4tree5idrefIcNS1_6ncnameIcNS1_4nameIcNS1_5tokenIcNS1_17normalized_stringIcNS1_6stringIcNS1_11simple_typeINS1_5_typeEEEEEEEEEEEEES9_EE
Once I fixed the xsd file in my project, I verified I was finally getting
the same type as above, building confidence that it was finally working.
Here's my code:
space::xtce::ArgumentRefEntry::argumentRef_type&
argRef(argRefEntry[iArgRef].argumentRef());
std::cout << typeid(argRef).name() << std::endl;
space::xtce::ArgumentList::Argument_type& argObj
(dynamic_cast<space::xtce::ArgumentList::Argument_type&> (*argRef));
In the 3rd line above, I get a seg fault. Before I'm reminded to read that
section of the manual, I did read it and as far as I can tell, I'm
following the instructions as best I understand them. Why is it seg
faulting and how do you recommend debugging the seg fault?
On Sat, Mar 1, 2014 at 4:38 PM, Mathew Benson <mathew.benson at gmail.com>wrote:
> I found my problem. For my attributes that were supposed to be
> references, I kept them as a simpleType but added "<restriction
> base="IDREF"/> to the simpleType. That enforced references had
> corresponding ID's, but it didn't generate code that I expected. It
> returned the simpleType. I just set the attribute type to IDREF directly,
> rather than use a custom attribute. Now it works.
>
>
> On Sat, Mar 1, 2014 at 12:33 PM, Mathew Benson <mathew.benson at gmail.com>wrote:
>
>> I already found that section, but to avoid confusion I tried to faithly
>> perform the steps detailed in that section. The sample code doesn't work
>> for me out of the box, having problems just parsing the schema, compiling,
>> and unmarshalling the xml. Either I don't have my build environment setup
>> correctly, or the sample code in the manual is really incomplete code
>> snippets. For the benefit of anybody else that finds this post, I'm
>> attaching a tarball of my build project with a functioning example taken
>> from section 2.5.5 of the manual. I apologize if the attachment doesn't go
>> through. For a detailed example of what had failed and the changes
>> required, build the code exactly as found in the manual and diff that with
>> the example attached here. The xsd command to generate the .cpp and .h
>> file is:
>>
>> xsd cxx-tree --generate-serialization --generate-ostream --cxx-suffix
>> .cpp --hxx-suffix .h --fwd-suffix -fwd.h test.xsd
>>
>> I couldn't get the second half of the example to compile. Not that I
>> don't think that it should matter, but I didn't know what function to call
>> to unmarshall from a file and return a reference. Any attempt to use
>> "root_type&" like the example resulted in the following compiler error:
>> ../src/XSDTest.cpp:18:43: error: invalid initialization of non-const
>> reference of type 'test::root_type&' from an rvalue of type
>> 'std::auto_ptr<test::root_type>
>>
>> I also got an error on the following line from the example:
>>
>> object_type& obj (*ref);
>>
>> ../src/XSDTest.cpp:20:25: error: invalid initialization of reference of
>> type 'test::object_type&' from expression of type
>> 'xsd::cxx::tree::idref<char, xsd::cxx::tree::ncname<char,
>> xsd::cxx::tree::name<char, xsd::cxx::tree::token<char,
>> xsd::cxx::tree::normalized_string<char, xsd::cxx::tree::string<char,
>> xsd::cxx::tree::simple_type<xsd::cxx::tree::_type> > > > > >,
>> xsd::cxx::tree::_type>::ref_type {aka xsd::cxx::tree::_type}'
>>
>> I would really like to get that second half of the example working so I
>> don't have to cast.
>>
>> Lastly, using "root" as a variable name in the examples is probably not a
>> good idea when the example xsd file results in a class also called "root".
>> Its a bit confusing.
>>
>>
>> On Fri, Feb 28, 2014 at 11:19 PM, Boris Kolpackov <
>> boris at codesynthesis.com> wrote:
>>
>>> Hi Mathew,
>>>
>>> Mathew Benson <mathew.benson at gmail.com> writes:
>>>
>>> > Could you tell me the best way to retrieve
>>> > 'argumentTypeRef="IpAddressType"' given I have a pointer/reference to
>>> the
>>> > '<xtce:MetaCommand name="RCM_EnableOutput">' object?
>>>
>>> If you have an IDREF reference, then please read this section in the
>>> manual, it explains how to use them:
>>>
>>>
>>> http://codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.5.5
>>>
>>> If something is still not clear, please specify what exactly (i.e., "I
>>> tried foo and bar and biz did not work" instead of "tell me how to
>>> do foo").
>>>
>>> Boris
>>>
>>
>>
>
More information about the xsd-users
mailing list