Tarrasch Chess GUI / src / GamesCache.h

 * Games Cache - Abstracted interface to  a list of games
 *  Author:  Bill Forster
 *  Licence: See licencing information in ChessPosition.cpp
 *  Copyright 2010, Triple Happy Ltd.  All rights reserved.
#include "GameDocument.h"
#include <time.h> // time_t

// PgnDialog class declaration
class GamesCache
    std::vector<GameDocument>  gds;
    std::vector<int>           col_flags;
    std::string                pgn_filename;
    int game_nbr;
    bool renumber;
    bool file_irrevocably_modified;

    GamesCache() { state=STARTUP; renumber=false; resume_previous_window=false; loaded=false; top_item=0;
                    file_irrevocably_modified=false; }
    void Debug( const char *intro_message );
    bool Load( std::string &filename );
    bool Reload() { return Load(pgn_filename); }
    bool Load( FILE *pgn_file );
    void LoadLine(  GameDocument &gd, int fposn, const char *line );
    bool FileCreate( std::string &filename, GameDocument &gd );
    void FileSave( GamesCache *gc_clipboard );
    void FileSaveAs( std::string &filename, GamesCache *gc_clipboard );
    void FileSaveInner( GamesCache *gc_clipboard, FILE *pgn_in, FILE *pgn_out );
    bool IsLoaded();
    bool IsSynced();
    void KillResumePreviousWindow()
    void PrepareResumePreviousWindow( int top_item ) 
        resume_previous_window=true; this->top_item = top_item;
    bool IsResumingPreviousWindow( int &top_item )
        top_item=this->top_item; return resume_previous_window; 

private:     // Helpers
    enum {STARTUP,HEADER,INGAME} state;
    bool resume_previous_window;
    int  top_item;
    bool loaded;
    int  pgn_handle;

    // Check whether text s is a valid header, return true if it is,
    //  add info to a GameDocument, optionally clearing it first
    bool Tagline( GameDocument &gd,  const char *s );

#endif    // GAMES_CACHE_H