AW: [xsd-users] abstract type and its c++ equivalent

Klima Georg G.Klima at durst-online.at
Wed Apr 24 03:17:45 EDT 2013


Hi, just a "minor" correction:

void* i = dynamic_cast<DPrnCal::xalignDescriptor_vt*>(pd.get()); is NOT working, as it would be expected (gets optimized away)

but with std::cout << dynamic_cast<DPrnCal::xalignDescriptor_vt*>(pd.get()) << std::endl; (that isn't optimized away or reorder)
a valid pointer is printed to cout!

Best regards
GEorg 


-----Ursprüngliche Nachricht-----
Von: xsd-users-bounces at codesynthesis.com [mailto:xsd-users-bounces at codesynthesis.com] Im Auftrag von Klima Georg
Gesendet: Dienstag, 23. April 2013 17:38
An: Boris Kolpackov
Cc: xsd-users at codesynthesis.com
Betreff: AW: [xsd-users] abstract type and its c++ equivalent

Hi Boris,

Thank you for the fast response!

>> I'm having troubles understanding why an abstract schema type isn't 
>> mapped to an abstract / pure virtual / not instantiable class type in
>> c++?
>
>It is not a good idea to add a pure virtual function (e.g., d-tor) to class that is otherwise non-polymorphic. That would result in code bloat. However, I don't see any harm in making all its c-tors >protected so that they are inaccessible from user code. I've added this item to the TODO list for the next release.
>
>
>> My motivation for this problem is that I'm implementing a visitor 
>> pattern and so can't implement pure virtual functions within classes 
>> of schema abstract types.
>
>I don't see why this is a problem. Just leave the "visiting" functions for abstract types as pure virtual?

Doing so, it didn't compile because of the new/instantiation in the clone function of the "abstract" base type.
But also it may have been caused by another fault of mine too, I forgot to set --polymorphic-type-all!!!

What brings me to another very strange problem:
Setting --polymorphic-type-all enables me what I want to do, implement an intrinsic visitor (accept methods "patched" into the generated code, by sort of aspect oriented programming - introduction).
But even with the clean unmodified/un-patched  code I do get an error:

XAlignDescriptorSimpleFrameSample.xml
terminate called after throwing an instance of 'xsd::cxx::tree::no_type_info<char>'
  what():  no type information available for a type

if I just do this:

#include <memory>   // std::auto_ptr
#include <iostream>
//#include <typeinfo>

#include "XAlignDescriptor.hxx"

int main(int argc, char **argv) {

	std::cout << argv[1] << std::endl;
	std::auto_ptr<DPrnCal::patternDescriptor_at> pd(DPrnCal::PatternDefinition(argv[1])); //<-- exception happens here
//	void* i = dynamic_cast<DPrnCal::xalignDescriptor_vt*>(pd.get());

	std::cout << "Done." << std::endl;
	return 0;
}

Removing the comment from the rtti code, that in effect (at least for this main method) does nothing:

#include <memory>   // std::auto_ptr
#include <iostream>
#include <typeinfo>

#include "XAlignDescriptor.hxx"

int main(int argc, char **argv) {

	std::cout << argv[1] << std::endl;
	std::auto_ptr<DPrnCal::patternDescriptor_at> pd(DPrnCal::PatternDefinition(argv[1]));
	void* i = dynamic_cast<DPrnCal::xalignDescriptor_vt*>(pd.get());

	std::cout << "Done." << std::endl;
	return 0;
}

It works with following output:

XAlignDescriptorSimpleFrameSample.xml
Done.

And the pointer i is valid if printed out!


The exception gets thrown in type-factory-map.txx line 401


And I don't understand this behaviour. The only thing I can think of is an initialisation problem concerning the RTTI and derived code!

If you need more info I could send you the schema + xml test files directly, including the xsd parameters used.......

Xsd version: 3.3.0
Xerces version: 3.1.1

Thanks
Georg





More information about the xsd-users mailing list