/*
 * --- GSMP-COPYRIGHT-NOTE-BEGIN ---
 * 
 * This copyright note is auto-generated by ./scripts/Create-CopyPatch.
 * Please add additional copyright information _after_ the line containing
 * the GSMP-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
 * the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
 * 
 * GSMP: dam/include/SaveDataLexer.hh
 * General Sound Manipulation Program is Copyright (C) 2000 - 2004
 *   Valentin Ziegler and René Rebe
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2. A copy of the GNU General
 * Public License can be found in the file LICENSE.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT-
 * ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 * 
 * --- GSMP-COPYRIGHT-NOTE-END ---
 */

#ifndef DAM__SAVEDATALEXER_HH__
#define DAM__SAVEDATALEXER_HH__

#include "SaveDataFlexLexer.hh"
#include "WrapPointer.hh"

#include <string>
#include <fstream>


namespace DAM
{

  class SaveDataLexer : protected SaveDataFlexLexer
  {
  public:
    SaveDataLexer (std::istream& input);

    bool Operator () const { return true; } // Validy state

    const std::string& CustomType () const;
    const std::string& Master () const;
    const std::string& LastError () const { return last_error; }

    bool Eof () const { return eof; }
    int Line () const { return yylineno; }

    bool NextEntity (bool* error, std::string* id, int* version);
    bool RecoverToNextEntity (std::string* id, int* version);
    WrapPointer::save_id_t NextEntityElement (bool* error);

    bool OpenBlock ();
    bool CloseBlock ();
    bool SkipBlock ();

    bool OpenArray ();
    bool NextArrayItem (bool* error);

    bool SetInteger (int64_t* dst);
    bool SetFloat (double* dst);
    bool SetString (std::string* dst);
    bool SetPtr (WrapPointer* dst);

  protected:

    int NextToken ();
    bool Expect (int token, const char* text, bool tolerate_eof = false);

    std::string last_error;
    bool eof;
  };

} // end namespace DAM



/* include template implementation */
//#define DAM__SAVEDATALEXER_TMPL__
//#include "template/SaveDataLexer.tcc"
//#undef DAM__SAVEDATALEXER_TMPL__

#endif // DAM__SAVEDATALEXER_HH__
