// file      : xsd/cxx/tree/exceptions.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_EXCEPTIONS_HXX
#define XSD_CXX_TREE_EXCEPTIONS_HXX

#include <string>
#include <exception> // std::exception

namespace xsd
{
  namespace cxx
  {
    namespace tree
    {
      //
      //
      struct exception: virtual std::exception
      {
      };

      //
      //
      struct invalid_instance: virtual exception
      {
        virtual char const*
        what () const throw ()
        {
          return "instance document is not valid";
        }
      };

      //
      //
      template <typename C>
      struct unexpected_element: virtual exception
      {
        virtual
        ~unexpected_element () throw ()
        {
        }

        unexpected_element (std::basic_string<C> const& element,
                            std::basic_string<C> const& expected)
            : element_ (element),
              expected_ (expected)
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "unexpected element encountered";
        }

        std::basic_string<C> const&
        element () const
        {
          return element_;
        }

        // Space-separated list of names of expected elements.
        //
        std::basic_string<C> const&
        expected () const
        {
          return expected_;
        }

      private:
        std::basic_string<C> element_;
        std::basic_string<C> expected_;
      };

      //
      //
      template <typename C>
      struct unexpected_attribute: virtual exception
      {
        virtual
        ~unexpected_attribute () throw ()
        {
        }

        unexpected_attribute (std::basic_string<C> const& attribute,
                              std::basic_string<C> const& expected)
            : attribute_ (attribute),
              expected_ (expected)
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "unexpected attribute encountered";
        }

        std::basic_string<C> const&
        attribute () const
        {
          return attribute_;
        }

        // Space-separated list of names of expected attributes.
        //
        std::basic_string<C> const&
        expected () const
        {
          return expected_;
        }

      private:
        std::basic_string<C> attribute_;
        std::basic_string<C> expected_;
      };

      //
      //
      template <typename C>
      struct unexpected_enumerator: virtual exception
      {
        virtual
        ~unexpected_enumerator () throw ()
        {
        }

        unexpected_enumerator (std::basic_string<C> const& enumerator,
                               std::basic_string<C> const& expected)
            : enumerator_ (enumerator),
              expected_ (expected)
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "unexpected enumerator encountered";
        }

        std::basic_string<C> const&
        enumerator () const
        {
          return enumerator_;
        }

        // Space-separated list of names of expected enumerators.
        //
        std::basic_string<C> const&
        expected () const
        {
          return expected_;
        }

      private:
        std::basic_string<C> enumerator_;
        std::basic_string<C> expected_;
      };


      //
      //
      template <typename C>
      struct duplicate_id: virtual exception
      {
        virtual
        ~duplicate_id () throw ()
        {
        }

        duplicate_id (std::basic_string<C> const& id)
            : id_ (id)
        {
        }

        virtual char const*
        what () const throw ()
        {
          return "duplicate id";
        }

        std::basic_string<C> const&
        id () const
        {
          return id_;
        }

      private:
        std::basic_string<C> id_;
      };
    }
  }
}

#endif  // XSD_CXX_TREE_EXCEPTIONS_HXX
