-- $Date: 2004/03/01 01:33:04 $
-- $Revision: 1.5 $
-- $Author: jcrocholl $

with Token_Readers; use Token_Readers;

package body Music.Barlines.MusicXML is

   -- Read barline data from an XML reader.
   function Read_Barline
     (XML : access XML_Reader-- Use this XML reader.
     return Barline_Access     -- The newly created barline.
   is
      Location  : Location_Enum := Right;
      Bar_Style : Bar_Style_Enum;
   begin
      if not End_Of_Tag(XML) then
         Assert_Attribute_Name(XML, "location");
         Read_Attribute_Value(XML);
         Location := To_Location_Enum(Get_Token(XML));
      end if;
      Exit_Tag(XML);

      while Descend(XML) loop
         Exit_Tag(XML);
         if Context_Is(XML, "bar-style") then
            Bar_Style := To_Bar_Style_Enum(Read_Data(XML));
         else
            XML_Expect_Error(XML, "/barline", "bar-style");
         end if;
         Exit_Element(XML);
      end loop;
      Exit_Tag(XML); -- </barline>

      return Create(Location, Bar_Style);
   end Read_Barline;

   -- Write barline data to an XML writer.
   procedure Write_Barline
     (XML  : access XML_Writer-- Use this XML writer.
      This : access Barline)    -- Write this barline.
   is
   begin
      Start_Element(XML, "barline", "location", To_XML(Get_Location(This)'Img));
      Write_Element(XML, "bar-style", To_XML(Get_Bar_Style(This)'Img));
      Close_Element(XML, "barline");
   end Write_Barline;

end Music.Barlines.MusicXML;