summaryrefslogtreecommitdiff
path: root/ACE/ace/XML_Utils/XMLSchema/Writer.hpp
blob: 781432b8fda4ad91d0ff358ced3bb4c4088712db (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
148
149
150
151
152
153
154
155
156
// file      : XMLSchema/Writer.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
#ifndef XMLSCHEMA_WRITER_HPP
#define XMLSCHEMA_WRITER_HPP

#include <sstream>

#include <ace/XML_Utils/XSCRT/Writer.hpp>

#include <ace/XML_Utils/XMLSchema/Types.hpp>
#include <ace/XML_Utils/XMLSchema/Traversal.hpp>

#include <iostream>

namespace XMLSchema
{
  namespace Writer
  {
    template <typename T, typename C>
    struct FundamentalType : Traversal::Traverser<T>,
                             virtual XSCRT::Writer<C>
    {
      FundamentalType (XSCRT::XML::Element<C>& e)
          : XSCRT::Writer<C> (e)
      {
      }

      using XSCRT::Writer<C>::top_;
      using XSCRT::Writer<C>::attr_;

      virtual void
      traverse (T const& o)
      {
        using namespace XSCRT::XML;

        std::basic_ostringstream<C> os;

        os << o;

        if (Attribute<C>* a = attr_ ())
        {
          a->value (os.str ());
        }
        else
        {
          top_().value (os.str ());
        }
      }

    protected:
      virtual void
      traverse (T &t)
      {
        Traversal::Traverser<T>::traverse (t);
      }

      FundamentalType ()
      {
      }
    };

    template<typename C>
    struct FundamentalType <XSCRT::FundamentalType<bool>, C> :
      Traversal::Traverser<XSCRT::FundamentalType<bool> >,
      virtual XSCRT::Writer<C>
    {
      FundamentalType (XSCRT::XML::Element<C> &e)
        : XSCRT::Writer<C> (e)
      {
      }

      using XSCRT::Writer<C>::top_;
      using XSCRT::Writer<C>::attr_;

      virtual void
      traverse (XSCRT::FundamentalType<bool> const &o)
      {
        using namespace XSCRT::XML;

        std::basic_ostringstream<C> os;

        if (o)
          {
            os << "true";
          }
        else
          {
            os << "false";
          }

        if (Attribute<C>* a = attr_ ())
        {
          a->value (os.str ());
        }
        else
        {
          top_().value (os.str ());
        }
      }

    protected:
      virtual void
      traverse (XSCRT::FundamentalType<bool> &t)
      {
        Traversal::Traverser<XSCRT::FundamentalType<bool> >::traverse (t);
      }

      FundamentalType ()
      {
      }
    };


    template <typename C>
    struct IDREF : Traversal::Traverser<XMLSchema::IDREF<C> >,
                   virtual XSCRT::Writer<C>
    {
      IDREF (XSCRT::XML::Element<C>& e)
          : XSCRT::Writer<C> (e)
      {
      }

      virtual void
      traverse (
        typename Traversal::Traverser<XMLSchema::IDREF<C> >::Type const& o)
      {
        using namespace XSCRT::XML;

        if (Attribute<C>* a = XSCRT::Writer<C>::attr_ ())
        {
          a->value (o.id ());
        }
        else
        {
          XSCRT::Writer<C>::top_().value (o.id ());
        }
      }

    protected:

      virtual void
      traverse (typename Traversal::Traverser<XMLSchema::IDREF<C> >::Type &o)
      {
        Traversal::Traverser<XMLSchema::IDREF<C> >::traverse (o);
      }

      IDREF ()
      {
      }
    };
  }
}

#include <ace/XML_Utils/XMLSchema/Writer.ipp>

#endif  // XMLSCHEMA_WRITER_HPP