summaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/tree/stream-extraction-map.hxx
blob: f57c435e57e427accc5b5677104bf715def8e6d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// file      : xsd/cxx/tree/stream-extraction-map.hxx
// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX
#define XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX

#include <map>
#include <memory>  // std::auto_ptr/unique_ptr
#include <cstddef> // std::size_t

#include <xsd/cxx/config.hxx> // XSD_AUTO_PTR

#include <xsd/cxx/tree/elements.hxx>
#include <xsd/cxx/tree/istream.hxx>
#include <xsd/cxx/xml/qualified-name.hxx>

namespace xsd
{
  namespace cxx
  {
    namespace tree
    {
      template <typename S, typename C>
      struct stream_extraction_map
      {
        typedef xml::qualified_name<C> qualified_name;
        typedef XSD_AUTO_PTR<type> (*extractor) (
          istream<S>&, flags, container*);

      public:
        stream_extraction_map ();

        void
        register_type (const qualified_name& name,
                       extractor,
                       bool replace = true);

        void
        unregister_type (const qualified_name& name);

        XSD_AUTO_PTR<type>
        extract (istream<S>&, flags, container*);

      public:
        extractor
        find (const qualified_name& name) const;

      private:
        typedef std::map<qualified_name, extractor> type_map;

        type_map type_map_;
      };

      //
      //
      template<unsigned long id, typename S, typename C>
      struct stream_extraction_plate
      {
        static stream_extraction_map<S, C>* map;
        static std::size_t count;

        stream_extraction_plate ();
        ~stream_extraction_plate ();
      };

      template<unsigned long id, typename S, typename C>
      stream_extraction_map<S, C>* stream_extraction_plate<id, S, C>::map = 0;

      template<unsigned long id, typename S, typename C>
      std::size_t stream_extraction_plate<id, S, C>::count = 0;


      //
      //
      template<unsigned long id, typename S, typename C>
      inline stream_extraction_map<S, C>&
      stream_extraction_map_instance ()
      {
        return *stream_extraction_plate<id, S, C>::map;
      }

      //
      //
      template<typename S, typename T>
      XSD_AUTO_PTR<type>
      extractor_impl (istream<S>&, flags, container*);


      template<unsigned long id, typename S, typename C, typename T>
      struct stream_extraction_initializer
      {
        stream_extraction_initializer (const C* name, const C* ns);
        ~stream_extraction_initializer ();

      private:
        const C* name_;
        const C* ns_;
      };
    }
  }
}

#include <xsd/cxx/tree/stream-extraction-map.txx>

#endif // XSD_CXX_TREE_STREAM_EXTRACTION_MAP_HXX