1 | // file : xsd/cxx/tree/stream-extraction-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_STREAM_EXTRACTION_MAP_HXX |
---|
7 | #define XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX |
---|
8 | |
---|
9 | #include <map> |
---|
10 | #include <memory> // std::auto_ptr |
---|
11 | |
---|
12 | #include <xsd/cxx/tree/elements.hxx> |
---|
13 | #include <xsd/cxx/tree/istream.hxx> |
---|
14 | #include <xsd/cxx/xml/qualified-name.hxx> |
---|
15 | |
---|
16 | namespace xsd |
---|
17 | { |
---|
18 | namespace cxx |
---|
19 | { |
---|
20 | namespace tree |
---|
21 | { |
---|
22 | template <typename S, typename C> |
---|
23 | struct stream_extraction_map |
---|
24 | { |
---|
25 | typedef xml::qualified_name<C> qualified_name; |
---|
26 | typedef std::auto_ptr<type> (*extractor) ( |
---|
27 | istream<S>&, flags, container*); |
---|
28 | |
---|
29 | public: |
---|
30 | stream_extraction_map (); |
---|
31 | |
---|
32 | void |
---|
33 | register_type (const qualified_name& name, |
---|
34 | extractor, |
---|
35 | bool override = true); |
---|
36 | |
---|
37 | std::auto_ptr<type> |
---|
38 | extract (istream<S>&, flags, container*); |
---|
39 | |
---|
40 | public: |
---|
41 | extractor |
---|
42 | find (const qualified_name& name) const; |
---|
43 | |
---|
44 | private: |
---|
45 | typedef std::map<qualified_name, extractor> type_map; |
---|
46 | |
---|
47 | type_map type_map_; |
---|
48 | }; |
---|
49 | |
---|
50 | // |
---|
51 | // |
---|
52 | template<unsigned long id, typename S, typename C> |
---|
53 | struct stream_extraction_plate |
---|
54 | { |
---|
55 | static stream_extraction_map<S, C>* map; |
---|
56 | static unsigned long count; |
---|
57 | |
---|
58 | stream_extraction_plate (); |
---|
59 | ~stream_extraction_plate (); |
---|
60 | }; |
---|
61 | |
---|
62 | template<unsigned long id, typename S, typename C> |
---|
63 | stream_extraction_map<S, C>* stream_extraction_plate<id, S, C>::map = 0; |
---|
64 | |
---|
65 | template<unsigned long id, typename S, typename C> |
---|
66 | unsigned long stream_extraction_plate<id, S, C>::count = 0; |
---|
67 | |
---|
68 | |
---|
69 | // |
---|
70 | // |
---|
71 | template<unsigned long id, typename S, typename C> |
---|
72 | inline stream_extraction_map<S, C>& |
---|
73 | stream_extraction_map_instance () |
---|
74 | { |
---|
75 | return *stream_extraction_plate<id, S, C>::map; |
---|
76 | } |
---|
77 | |
---|
78 | // |
---|
79 | // |
---|
80 | template<typename S, typename X> |
---|
81 | std::auto_ptr<type> |
---|
82 | extractor_impl (istream<S>&, flags, container*); |
---|
83 | |
---|
84 | |
---|
85 | template<unsigned long id, typename S, typename C, typename X> |
---|
86 | struct stream_extraction_initializer |
---|
87 | { |
---|
88 | stream_extraction_initializer (const C* name, const C* ns); |
---|
89 | }; |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | #include <xsd/cxx/tree/stream-extraction-map.txx> |
---|
95 | |
---|
96 | #endif // XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX |
---|