Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / ACE / ace / XML_Utils / XMLSchema / Writer.hpp
blobc7d5f1e3900ff293d9c88d6b1d876df318e0d7ae
1 // file : XMLSchema/Writer.hpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
3 #ifndef XMLSCHEMA_WRITER_HPP
4 #define XMLSCHEMA_WRITER_HPP
6 #include <sstream>
8 #include <ace/XML_Utils/XSCRT/Writer.hpp>
10 #include <ace/XML_Utils/XMLSchema/Types.hpp>
11 #include <ace/XML_Utils/XMLSchema/Traversal.hpp>
13 #include <iostream>
15 namespace XMLSchema
17 namespace Writer
19 template <typename T, typename C>
20 struct FundamentalType : Traversal::Traverser<T>,
21 virtual XSCRT::Writer<C>
23 FundamentalType (XSCRT::XML::Element<C>& e)
24 : XSCRT::Writer<C> (e)
28 using XSCRT::Writer<C>::top_;
29 using XSCRT::Writer<C>::attr_;
31 virtual void
32 traverse (T const& o)
34 using namespace XSCRT::XML;
36 std::basic_ostringstream<C> os;
38 os << o;
40 if (Attribute<C>* a = attr_ ())
42 a->value (os.str ());
44 else
46 top_().value (os.str ());
50 protected:
51 virtual void
52 traverse (T &t)
54 Traversal::Traverser<T>::traverse (t);
57 FundamentalType () = default;
60 template<typename C>
61 struct FundamentalType <XSCRT::FundamentalType<bool>, C> :
62 Traversal::Traverser<XSCRT::FundamentalType<bool> >,
63 virtual XSCRT::Writer<C>
65 FundamentalType (XSCRT::XML::Element<C> &e)
66 : XSCRT::Writer<C> (e)
70 using XSCRT::Writer<C>::top_;
71 using XSCRT::Writer<C>::attr_;
73 virtual void
74 traverse (XSCRT::FundamentalType<bool> const &o)
76 using namespace XSCRT::XML;
78 std::basic_ostringstream<C> os;
80 if (o)
82 os << "true";
84 else
86 os << "false";
89 if (Attribute<C>* a = attr_ ())
91 a->value (os.str ());
93 else
95 top_().value (os.str ());
99 protected:
100 virtual void
101 traverse (XSCRT::FundamentalType<bool> &t)
103 Traversal::Traverser<XSCRT::FundamentalType<bool> >::traverse (t);
106 FundamentalType () = default;
110 template <typename C>
111 struct IDREF : Traversal::Traverser<XMLSchema::IDREF<C> >,
112 virtual XSCRT::Writer<C>
114 IDREF (XSCRT::XML::Element<C>& e)
115 : XSCRT::Writer<C> (e)
119 virtual void
120 traverse (
121 typename Traversal::Traverser<XMLSchema::IDREF<C> >::Type const& o)
123 using namespace XSCRT::XML;
125 if (Attribute<C>* a = XSCRT::Writer<C>::attr_ ())
127 a->value (o.id ());
129 else
131 XSCRT::Writer<C>::top_().value (o.id ());
135 protected:
137 virtual void
138 traverse (typename Traversal::Traverser<XMLSchema::IDREF<C> >::Type &o)
140 Traversal::Traverser<XMLSchema::IDREF<C> >::traverse (o);
143 IDREF () = default;
148 #endif // XMLSCHEMA_WRITER_HPP