diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-12-18 18:48:46 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-02-24 22:20:33 +0300 |
commit | a8ce5c380c69539fe0c7c62c397634d9d0c9fde2 (patch) | |
tree | c8db5c9b99416ca4686af953387f474af15bc92e /xsd-examples/cxx/tree/polymorphism/driver.cxx | |
parent | 7420f85ea19b0562ffdd8123442f32bc8bac1267 (diff) |
Switch to build2
Diffstat (limited to 'xsd-examples/cxx/tree/polymorphism/driver.cxx')
-rw-r--r-- | xsd-examples/cxx/tree/polymorphism/driver.cxx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/xsd-examples/cxx/tree/polymorphism/driver.cxx b/xsd-examples/cxx/tree/polymorphism/driver.cxx new file mode 100644 index 0000000..6458170 --- /dev/null +++ b/xsd-examples/cxx/tree/polymorphism/driver.cxx @@ -0,0 +1,59 @@ +// file : cxx/tree/polymorphism/driver.cxx +// copyright : not copyrighted - public domain + +#include <memory> // std::unique_ptr +#include <iostream> + +#include "supermen.hxx" + +using std::cerr; +using std::endl; +using std::unique_ptr; + +int +main (int argc, char* argv[]) +{ + if (argc != 2) + { + cerr << "usage: " << argv[0] << " supermen.xml" << endl; + return 1; + } + + try + { + unique_ptr<supermen> sm (supermen_ (argv[1])); + + supermen copy (*sm); // Dynamic types are preserved in copies. + + // Print what we've got. + // + for (supermen::person_const_iterator i (copy.person ().begin ()); + i != copy.person ().end (); + ++i) + { + cerr << i->name (); + + if (const superman* s = dynamic_cast<const superman*> (&*i)) + { + if (s->can_fly ()) + cerr << ", flying superman"; + else + cerr << ", superman"; + } + + cerr << endl; + } + + // Serialize back to XML. + // + xml_schema::namespace_infomap map; + map[""].schema = "supermen.xsd"; + + supermen_ (std::cout, copy, map); + } + catch (const xml_schema::exception& e) + { + cerr << e << endl; + return 1; + } +} |