// file      : xsd/cxx/parser.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_PARSER_HXX
#define XSD_CXX_PARSER_HXX

#include <xsd/cxx/xml.hxx>

namespace xsd
{
  namespace cxx
  {
    template <typename C>
    class parser
    {
    public:
      parser (xml::element<C> const& e)
          : e_ (e.dom_element ()->getChildNodes ()), ei_ (0),
            a_ (e.dom_element ()->getAttributes ()), ai_ (0)
      {
      }

      bool
      more_elements () const
      {
        return e_->getLength () > ei_;
      }

      xml::element<C>
      next_element ()
      {
        return xml::element<C> (
          dynamic_cast<xercesc::DOMElement*> (e_->item (ei_++)));
      }

      bool
      more_attributes () const
      {
        return a_->getLength () > ai_;
      }

      xml::attribute<C>
      next_attribute ()
      {
        return xml::attribute<C> (
          dynamic_cast<xercesc::DOMAttr*> (a_->item (ai_++)));
      }

    private:
      parser (parser const&);

      parser&
      operator= (parser const&);

    private:
      xercesc::DOMNodeList const* e_;
      unsigned long ei_;

      xercesc::DOMNamedNodeMap const* a_;
      unsigned long ai_;
    };
  }
}

#include <xsd/cxx/parser.txx>

#endif  // XSD_CXX_PARSER_HXX
