From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- libxsd/xsd/cxx/tree/type-factory-map.hxx | 151 +++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 libxsd/xsd/cxx/tree/type-factory-map.hxx (limited to 'libxsd/xsd/cxx/tree/type-factory-map.hxx') diff --git a/libxsd/xsd/cxx/tree/type-factory-map.hxx b/libxsd/xsd/cxx/tree/type-factory-map.hxx new file mode 100644 index 0000000..8cf916e --- /dev/null +++ b/libxsd/xsd/cxx/tree/type-factory-map.hxx @@ -0,0 +1,151 @@ +// file : xsd/cxx/tree/type-factory-map.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX +#define XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX + +#include +#include +#include // std::auto_ptr +#include // std::size_t + +#include + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template + struct type_factory_map + { + typedef xml::qualified_name qualified_name; + typedef std::auto_ptr (*factory) (const xercesc::DOMElement&, + flags, + container*); + public: + type_factory_map (); + + void + register_type (const qualified_name& name, + factory, + bool override = true); + + void + register_element (const qualified_name& root, + const qualified_name& subst, + factory); + + std::auto_ptr + create (const C* name, // element name + const C* ns, // element namespace + factory static_type, + bool global, + bool qualified, + const xercesc::DOMElement&, + const qualified_name&, + flags, + container*) const; + + public: + factory + find (const qualified_name& name) const; + + private: + template + static std::auto_ptr + traits_adapter (const xercesc::DOMElement&, flags, container*); + + private: + typedef + std::map + type_map; + + // Map of (root-element to map of (subst-element to factory)). + // + typedef + std::map + subst_map; + + typedef + std::map + element_map; + + type_map type_map_; + element_map element_map_; + + private: + factory + find_substitution (const subst_map& start, + const qualified_name& name) const; + + // The name argument is as specified in xsi:type. + // + factory + find_type (const std::basic_string& name, + const xercesc::DOMElement&) const; + }; + + + // + // + template + struct type_factory_plate + { + static type_factory_map* map; + static std::size_t count; + + type_factory_plate (); + ~type_factory_plate (); + }; + + template + type_factory_map* type_factory_plate::map = 0; + + template + std::size_t type_factory_plate::count = 0; + + + // + // + template + inline type_factory_map& + type_factory_map_instance () + { + return *type_factory_plate::map; + } + + + // + // + template + std::auto_ptr + factory_impl (const xercesc::DOMElement&, flags, container*); + + // + // + template + struct type_factory_initializer + { + // Register type. + // + type_factory_initializer (const C* name, const C* ns); + + // Register element. + // + type_factory_initializer (const C* root_name, const C* root_ns, + const C* subst_name, const C* subst_ns); + }; + } + } +} + +#include + +#endif // XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX -- cgit v1.1