// file      : xsd/cxx/tree/serialization.hxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSD_CXX_TREE_SERIALIZATION_HXX
#define XSD_CXX_TREE_SERIALIZATION_HXX

#include <sstream>

#include <xsd/cxx/xml/dom/elements.hxx>
#include <xsd/cxx/xml/dom/serialization.hxx>

#include <xsd/cxx/tree/types.hxx>

namespace xsd
{
  namespace cxx
  {
    namespace tree
    {
      template <typename X, typename C>
      void
      operator<< (xml::dom::element<C>& e, X const& x)
      {
        std::basic_ostringstream<C> os;
        os << x;
        e.value (os.str ());
      }

      template <typename X, typename C>
      void
      operator<< (xml::dom::attribute<C>& a, X const& x)
      {
        std::basic_ostringstream<C> os;
        os << x;
        a.value (os.str ());
      }

      // Specialization for fundamental_base.
      //

      template <typename X, typename C>
      void
      operator<< (xml::dom::element<C>& e, fundamental_base<X> const& x)
      {
        e << static_cast<X const&> (x);
      }

      template <typename X, typename C>
      void
      operator<< (xml::dom::attribute<C>& a, fundamental_base<X> const& x)
      {
        a << static_cast<X const&> (x);
      }
    }
  }
}

#endif  // XSD_CXX_TREE_SERIALIZATION_HXX
