aboutsummaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/tree/element-map.hxx
blob: 4eb7adba2ab3a9ef457bbbbbb82a29bd8baaa89c (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// file      : xsd/cxx/tree/element-map.hxx
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSD_CXX_TREE_ELEMENT_MAP_HXX
#define XSD_CXX_TREE_ELEMENT_MAP_HXX

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

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

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

namespace xsd
{
  namespace cxx
  {
    namespace tree
    {
      /**
       * @brief Root element map.
       *
       * This class allows uniform parsing/serialization of multiple
       * root elements via the element_type base class.
       *
       * @nosubgrouping
       */
      template <typename C, typename T>
      class element_map
      {
      public:
        /**
         * @brief Common base class for all element types.
         */
        typedef tree::element_type<C, T> element_type;

        /**
         * @brief Parse a DOM element.
         *
         * @param e A DOM element to parse.
         * @param f Flags to create the new element object with.
         * @return An automatic pointer to the new element object.
         */
        static XSD_AUTO_PTR<element_type>
        parse (const xercesc::DOMElement& e, flags f = 0);

        /**
         * @brief Serialize an element object to a DOM element.
         *
         * @param e A DOM element to serialize to.
         * @param x An element object to serialize.
         */
        static void
        serialize (xercesc::DOMElement& e, const element_type& x);

      public:
        //@cond

        typedef xml::qualified_name<C> qualified_name;

        typedef XSD_AUTO_PTR<element_type>
        (*parser) (const xercesc::DOMElement&, flags f);

        typedef void
        (*serializer) (xercesc::DOMElement&, const element_type&);

        static void
        register_parser (const qualified_name&, parser);

        static void
        register_serializer (const qualified_name&, serializer);

      public:
        struct map_entry
        {
          map_entry () : parser_ (0), serializer_ (0) {}

          parser parser_;
          serializer serializer_;
        };

        typedef
        std::map<qualified_name, map_entry>
        map;

        static map* map_;
        static std::size_t count_;

      private:
        element_map ();

        //@endcond
      };

      //@cond

      template <typename C, typename T>
      typename element_map<C, T>::map* element_map<C, T>::map_ = 0;

      template <typename C, typename T>
      std::size_t element_map<C, T>::count_ = 0;

      template <typename C, typename T>
      struct element_map_init
      {
        element_map_init ();
        ~element_map_init ();
      };

      //
      //
      template<typename T, typename C, typename B>
      XSD_AUTO_PTR<element_type<C, B> >
      parser_impl (const xercesc::DOMElement&, flags);

      template<typename T, typename C, typename B>
      struct parser_init
      {
        parser_init (const std::basic_string<C>& name,
                     const std::basic_string<C>& ns);
      };

      //
      //
      template<typename T, typename C, typename B>
      void
      serializer_impl (xercesc::DOMElement&, const element_type<C, B>&);

      template<typename T, typename C, typename B>
      struct serializer_init
      {
        serializer_init (const std::basic_string<C>& name,
                         const std::basic_string<C>& ns);
      };

      //@endcond
    }
  }
}

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

#endif // XSD_CXX_TREE_ELEMENT_MAP_HXX