// file      : xsde/cxx/parser/validating/idrefs-stl.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <xsde/cxx/pre.hxx>

#include <xsde/cxx/config.hxx>

#include <xsde/cxx/parser/validating/idrefs-stl.hxx>

namespace xsde
{
  namespace cxx
  {
    namespace parser
    {
      namespace validating
      {
        void idrefs_pimpl::
        _pre ()
        {
          seq_.clear ();
          idrefs_pskel::_pre ();
        }

        void idrefs_pimpl::
        _post ()
        {
          idrefs_pskel::_post ();

          // Should have at least one element.
          //
          if (!_context ().error_type () && seq_.size () < 1)
            _schema_error (schema_error::invalid_idrefs_value);
        }

        string_sequence idrefs_pimpl::
        post_idrefs ()
        {
          string_sequence r;
          r.swap (seq_);
          return r;
        }

        void idrefs_pimpl::
        _xsde_parse_item (const ro_string& s)
        {
          context& ctx = _context ();

          idref_pskel& p = parser_;

          p.pre ();

#ifndef XSDE_EXCEPTIONS
          if (!p._error_type ())
            p._pre_impl (ctx);
          else
            p._copy_error (ctx);
#else
          p._pre_impl (ctx);
#endif
          if (!ctx.error_type ())
            p._characters (s);

          if (!ctx.error_type ())
            p._post_impl ();

          if (!ctx.error_type ())
          {
            const std::string& x = p.post_idref ();

#ifndef XSDE_EXCEPTIONS
            if (!p._error_type ())
              seq_.push_back (x);
            else
              p._copy_error (ctx);
#else
            seq_.push_back (x);
#endif
          }
        }

        void idrefs_pimpl::
        _reset ()
        {
          idrefs_pskel::_reset ();
          parser_._reset ();
        }
      }
    }
  }
}

#include <xsde/cxx/post.hxx>
