1 | // file : xsd/cxx/tree/type-factory-map.hxx |
---|
2 | // author : Boris Kolpackov <boris@codesynthesis.com> |
---|
3 | // copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC |
---|
4 | // license : GNU GPL v2 + exceptions; see accompanying LICENSE file |
---|
5 | |
---|
6 | #ifndef XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX |
---|
7 | #define XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX |
---|
8 | |
---|
9 | #include <map> |
---|
10 | #include <string> |
---|
11 | #include <memory> // std::auto_ptr |
---|
12 | |
---|
13 | #include <xercesc/dom/DOMElement.hpp> |
---|
14 | |
---|
15 | #include <xsd/cxx/tree/elements.hxx> |
---|
16 | #include <xsd/cxx/xml/qualified-name.hxx> |
---|
17 | |
---|
18 | namespace xsd |
---|
19 | { |
---|
20 | namespace cxx |
---|
21 | { |
---|
22 | namespace tree |
---|
23 | { |
---|
24 | template <typename C> |
---|
25 | struct type_factory_map |
---|
26 | { |
---|
27 | typedef xml::qualified_name<C> qualified_name; |
---|
28 | typedef std::auto_ptr<type> (*factory) (const xercesc::DOMElement&, |
---|
29 | flags, |
---|
30 | container*); |
---|
31 | public: |
---|
32 | type_factory_map (); |
---|
33 | |
---|
34 | void |
---|
35 | register_type (const qualified_name& name, |
---|
36 | factory, |
---|
37 | bool override = true); |
---|
38 | |
---|
39 | void |
---|
40 | register_element (const qualified_name& root, |
---|
41 | const qualified_name& subst, |
---|
42 | factory); |
---|
43 | |
---|
44 | std::auto_ptr<type> |
---|
45 | create (const C* name, // element name |
---|
46 | const C* ns, // element namespace |
---|
47 | factory static_type, |
---|
48 | bool global, |
---|
49 | bool qualified, |
---|
50 | const xercesc::DOMElement&, |
---|
51 | const qualified_name&, |
---|
52 | flags, |
---|
53 | container*) const; |
---|
54 | |
---|
55 | public: |
---|
56 | factory |
---|
57 | find (const qualified_name& name) const; |
---|
58 | |
---|
59 | private: |
---|
60 | template <typename X> |
---|
61 | static std::auto_ptr<type> |
---|
62 | traits_adapter (const xercesc::DOMElement&, flags, container*); |
---|
63 | |
---|
64 | private: |
---|
65 | typedef |
---|
66 | std::map<qualified_name, factory> |
---|
67 | type_map; |
---|
68 | |
---|
69 | // Map of (root-element to map of (subst-element to factory)). |
---|
70 | // |
---|
71 | typedef |
---|
72 | std::map<qualified_name, factory> |
---|
73 | subst_map; |
---|
74 | |
---|
75 | typedef |
---|
76 | std::map<qualified_name, subst_map> |
---|
77 | element_map; |
---|
78 | |
---|
79 | type_map type_map_; |
---|
80 | element_map element_map_; |
---|
81 | |
---|
82 | private: |
---|
83 | factory |
---|
84 | find_substitution (const subst_map& start, |
---|
85 | const qualified_name& name) const; |
---|
86 | |
---|
87 | // The name argument is as specified in xsi:type. |
---|
88 | // |
---|
89 | factory |
---|
90 | find_type (const std::basic_string<C>& name, |
---|
91 | const xercesc::DOMElement&) const; |
---|
92 | }; |
---|
93 | |
---|
94 | |
---|
95 | // |
---|
96 | // |
---|
97 | template<unsigned long id, typename C> |
---|
98 | struct type_factory_plate |
---|
99 | { |
---|
100 | static type_factory_map<C>* map; |
---|
101 | static unsigned long count; |
---|
102 | |
---|
103 | type_factory_plate (); |
---|
104 | ~type_factory_plate (); |
---|
105 | }; |
---|
106 | |
---|
107 | template<unsigned long id, typename C> |
---|
108 | type_factory_map<C>* type_factory_plate<id, C>::map = 0; |
---|
109 | |
---|
110 | template<unsigned long id, typename C> |
---|
111 | unsigned long type_factory_plate<id, C>::count = 0; |
---|
112 | |
---|
113 | |
---|
114 | // |
---|
115 | // |
---|
116 | template<unsigned long id, typename C> |
---|
117 | inline type_factory_map<C>& |
---|
118 | type_factory_map_instance () |
---|
119 | { |
---|
120 | return *type_factory_plate<id, C>::map; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | // |
---|
125 | // |
---|
126 | template<typename X> |
---|
127 | std::auto_ptr<type> |
---|
128 | factory_impl (const xercesc::DOMElement&, flags, container*); |
---|
129 | |
---|
130 | // |
---|
131 | // |
---|
132 | template<unsigned long id, typename C, typename X> |
---|
133 | struct type_factory_initializer |
---|
134 | { |
---|
135 | // Register type. |
---|
136 | // |
---|
137 | type_factory_initializer (const C* name, const C* ns); |
---|
138 | |
---|
139 | // Register element. |
---|
140 | // |
---|
141 | type_factory_initializer (const C* root_name, const C* root_ns, |
---|
142 | const C* subst_name, const C* subst_ns); |
---|
143 | }; |
---|
144 | } |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | #include <xsd/cxx/tree/type-factory-map.txx> |
---|
149 | |
---|
150 | #endif // XSD_CXX_TREE_TYPE_FACTORY_MAP_HXX |
---|