From 2615896faa646e5830abf2c269150e1165c66515 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Dec 2020 18:48:46 +0300 Subject: Switch to build2 --- libxsd/libxsd/cxx/tree/stream-extraction-map.txx | 331 +++++++++++++++++++++++ 1 file changed, 331 insertions(+) create mode 100644 libxsd/libxsd/cxx/tree/stream-extraction-map.txx (limited to 'libxsd/libxsd/cxx/tree/stream-extraction-map.txx') diff --git a/libxsd/libxsd/cxx/tree/stream-extraction-map.txx b/libxsd/libxsd/cxx/tree/stream-extraction-map.txx new file mode 100644 index 0000000..98d4c6d --- /dev/null +++ b/libxsd/libxsd/cxx/tree/stream-extraction-map.txx @@ -0,0 +1,331 @@ +// file : libxsd/cxx/tree/stream-extraction-map.txx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // stream_extraction_map + // + template + stream_extraction_map:: + stream_extraction_map () + { + // Register extractors for built-in non-fundamental types. + // + std::basic_string xsd (bits::xml_schema ()); + + + // anyType and anySimpleType. + // + register_type ( + qualified_name (bits::any_type (), xsd), + &extractor_impl, + false); + + typedef simple_type simple_type; + register_type ( + qualified_name (bits::any_simple_type (), xsd), + &extractor_impl, + false); + + + // Strings + // + typedef string string; + register_type ( + qualified_name (bits::string (), xsd), + &extractor_impl, + false); + + typedef normalized_string normalized_string; + register_type ( + qualified_name (bits::normalized_string (), xsd), + &extractor_impl, + false); + + typedef token token; + register_type ( + qualified_name (bits::token (), xsd), + &extractor_impl, + false); + + typedef name name; + register_type ( + qualified_name (bits::name (), xsd), + &extractor_impl, + false); + + typedef nmtoken nmtoken; + register_type ( + qualified_name (bits::nmtoken (), xsd), + &extractor_impl, + false); + + typedef nmtokens nmtokens; + register_type ( + qualified_name (bits::nmtokens (), xsd), + &extractor_impl, + false); + + typedef ncname ncname; + register_type ( + qualified_name (bits::ncname (), xsd), + &extractor_impl, + false); + + typedef language language; + register_type ( + qualified_name (bits::language (), xsd), + &extractor_impl, + false); + + + // ID/IDREF. + // + typedef id id; + register_type ( + qualified_name (bits::id (), xsd), + &extractor_impl, + false); + + typedef idref idref; + register_type ( + qualified_name (bits::idref (), xsd), + &extractor_impl, + false); + + typedef idrefs idrefs; + register_type ( + qualified_name (bits::idrefs (), xsd), + &extractor_impl, + false); + + + // URI. + // + typedef uri uri; + register_type ( + qualified_name (bits::any_uri (), xsd), + &extractor_impl, + false); + + + // Qualified name. + // + typedef qname qname; + register_type ( + qualified_name (bits::qname (), xsd), + &extractor_impl, + false); + + + // Binary. + // + typedef base64_binary base64_binary; + register_type ( + qualified_name (bits::base64_binary (), xsd), + &extractor_impl, + false); + + typedef hex_binary hex_binary; + register_type ( + qualified_name (bits::hex_binary (), xsd), + &extractor_impl, + false); + + + // Date/time. + // + typedef gday gday; + register_type ( + qualified_name (bits::gday (), xsd), + &extractor_impl, + false); + + typedef gmonth gmonth; + register_type ( + qualified_name (bits::gmonth (), xsd), + &extractor_impl, + false); + + typedef gyear gyear; + register_type ( + qualified_name (bits::gyear (), xsd), + &extractor_impl, + false); + + typedef gmonth_day gmonth_day; + register_type ( + qualified_name (bits::gmonth_day (), xsd), + &extractor_impl, + false); + + typedef gyear_month gyear_month; + register_type ( + qualified_name (bits::gyear_month (), xsd), + &extractor_impl, + false); + + typedef date date; + register_type ( + qualified_name (bits::date (), xsd), + &extractor_impl, + false); + + typedef time time; + register_type ( + qualified_name (bits::time (), xsd), + &extractor_impl, + false); + + typedef date_time date_time; + register_type ( + qualified_name (bits::date_time (), xsd), + &extractor_impl, + false); + + typedef duration duration; + register_type ( + qualified_name (bits::duration (), xsd), + &extractor_impl, + false); + + + // Entity. + // + typedef entity entity; + register_type ( + qualified_name (bits::entity (), xsd), + &extractor_impl, + false); + + typedef entities entities; + register_type ( + qualified_name (bits::entities (), xsd), + &extractor_impl, + false); + } + + template + void stream_extraction_map:: + register_type (const qualified_name& name, + extractor e, + bool replace) + { + if (replace || type_map_.find (name) == type_map_.end ()) + type_map_[name] = e; + } + + template + void stream_extraction_map:: + unregister_type (const qualified_name& name) + { + type_map_.erase (name); + } + + template + XSD_AUTO_PTR stream_extraction_map:: + extract (istream& s, flags f, container* c) + { + std::basic_string ns, name; + + // The namespace and name strings are pooled. + // + std::size_t id; + istream_common::as_size as_size (id); + s >> as_size; + + if (id != 0) + s.pool_string (id, ns); + else + { + s >> ns; + s.pool_add (ns); + } + + s >> as_size; + + if (id != 0) + s.pool_string (id, name); + else + { + s >> name; + s.pool_add (name); + } + + if (extractor e = find (qualified_name (name, ns))) + { + return e (s, f, c); + } + else + throw no_type_info (name, ns); + } + + template + typename stream_extraction_map::extractor + stream_extraction_map:: + find (const qualified_name& name) const + { + typename type_map::const_iterator i (type_map_.find (name)); + return i == type_map_.end () ? 0 : i->second; + } + + + // stream_extraction_plate + // + template + stream_extraction_plate:: + stream_extraction_plate () + { + if (count == 0) + map = new stream_extraction_map; + + ++count; + } + + template + stream_extraction_plate:: + ~stream_extraction_plate () + { + if (--count == 0) + delete map; + } + + // + // + template + XSD_AUTO_PTR + extractor_impl (istream& s, flags f, container* c) + { + return XSD_AUTO_PTR (new T (s, f, c)); + } + + + // stream_extraction_initializer + // + template + stream_extraction_initializer:: + stream_extraction_initializer (const C* name, const C* ns) + : name_ (name), ns_ (ns) + { + stream_extraction_map_instance ().register_type ( + xml::qualified_name (name, ns), &extractor_impl); + } + + template + stream_extraction_initializer:: + ~stream_extraction_initializer () + { + stream_extraction_map_instance ().unregister_type ( + xml::qualified_name (name_, ns_)); + } + } + } +} -- cgit v1.1