diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2012-05-31 12:37:36 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2012-05-31 12:37:36 +0000 |
commit | 7965ec7125e1c1a5f99d4100119ee432c761e5e3 (patch) | |
tree | d9141a1f13a39b8cb9d7433fa660ff1c50901dcf /ACE/ace/XML_Utils/XMLSchema/Writer.hpp | |
parent | ea0bc78173bf8d6f993f903288531fd9fdaf0854 (diff) | |
download | ATCD-7965ec7125e1c1a5f99d4100119ee432c761e5e3.tar.gz |
Thu May 31 12:31:31 UTC 2012 Johnny Willemsen <jwillemsen@remedy.nl>
Migrated more files from DAnCE to ACE, updated code that uses it
Diffstat (limited to 'ACE/ace/XML_Utils/XMLSchema/Writer.hpp')
-rw-r--r-- | ACE/ace/XML_Utils/XMLSchema/Writer.hpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/ACE/ace/XML_Utils/XMLSchema/Writer.hpp b/ACE/ace/XML_Utils/XMLSchema/Writer.hpp new file mode 100644 index 00000000000..753a941e75e --- /dev/null +++ b/ACE/ace/XML_Utils/XMLSchema/Writer.hpp @@ -0,0 +1,159 @@ +// file : XMLSchema/Writer.hpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#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> +#include <ace/XML_Utils/XMLSchema/Writer.tpp> + +#endif // XMLSCHEMA_WRITER_HPP |