summaryrefslogtreecommitdiffstats
path: root/knights/pgn.h
blob: 7a0bc9178d208d38e4421ede0e97ac77c341a8a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/***************************************************************************
                          pgn.h  -  description
                             -------------------
    begin                : Mon Jul 30 2001
    copyright            : (C) 2003 by Troy Corbin Jr.
    email                : tcorbin@users.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PGN_H
#define PGN_H

#include <tdelocale.h>
#include <tdetempfile.h>
#include <tdeio/netaccess.h>
#include <tqobject.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqvaluelist.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqpainter.h>
#include "definitions.h"
#include "resource.h"
#include "knightsmap.h"
#include "match_param.h"

/**
  *@author Troy Corbin Jr.
  */

struct Annotation
{
	int RAV;
	TQString text;
};

typedef TQValueList<ChessMove> MoveList;
typedef KnightsMap<int, Annotation*> Annotations;

class tab_pgnView;

class pgn : public TQObject
{
	Q_OBJECT
  
	public:
		/* Standard PGN Tags */
		TQString 						TAG_Event;
		TQString 						TAG_Site;
		TQString 						TAG_Date;
		TQString 						TAG_Round;
		TQString 						TAG_White;
		TQString 						TAG_Black;
		TQString 						TAG_Result;
		TQString 						TAG_EventDate;
		TQString 						TAG_EventSponsor;
		TQString 						TAG_Section;
		TQString 						TAG_Stage;
		TQString 						TAG_Board;
		TQString 						TAG_WhiteTitle;
		TQString 						TAG_WhiteElo;
		TQString 						TAG_WhiteUSCF;
		TQString 						TAG_WhiteNA;
		TQString 						TAG_WhiteType;
		TQString 						TAG_BlackTitle;
		TQString 						TAG_BlackElo;
		TQString 						TAG_BlackUSCF;
		TQString 						TAG_BlackNA;
		TQString 						TAG_BlackType;
		TQString 						TAG_Opening;
		TQString 						TAG_Variation;
		TQString 						TAG_SubVariation;
		TQString 						TAG_ECO;
		TQString 						TAG_NIC;
		TQString 						TAG_Time;
		TQString 						TAG_UTCTime;
		TQString 						TAG_UTCDate;
		TQString 						TAG_TimeControl;
		TQString 						TAG_SetUp;
		TQString 						TAG_FEN;
		TQString							TAG_Termination;
		TQString							TAG_Annotator;
		TQString							TAG_Mode;
		TQString 						TAG_PlyCount;

		int									File_Position; // Used to scan PGN file
		TQStringList					Move_Data;

		/* The match_param */
		match_param					*Param;

												/* These are used in unfinished save games */
		int									whiteTime;
		int									blackTime;
		TCPList							whiteTCP;
		TCPList							blackTCP;

		TQString							CurrentURL;
		MoveList						Moves;
		Annotations					RAV;
		Annotations					annotations;
		TQStringList					Positions;
		unsigned int				currentIndex;

												pgn( resource *Rsrc=0, match_param *param=NULL );
												~pgn();
		void								clear( void );
		void								init( void );
		int									scan( void );
		bool								load( const int pos=0 );
		bool								save( TQString URL );
		bool								open( const TQString& URL );
		void								print( void );
		TQStringList*				notation( const int format=1 );
		void								close( void );
		static TQString			getNAG( int num );
		TQString							caption( void );

	signals:
		void								processMove( ChessMove );
		void								processSpecial( void );

	public slots:
		bool								loadNext( void );
		void								parseMatchParam( void );
		void								childViewDestroyed( void );

	private:
		resource						*Resource;
		tab_pgnView					*pgnView;
		TQString							tempFile;
		TQString							currentLine;
		TQFile								File;
		TQTextStream					Input;

		TQChar								getch( void );
		TQString							getword( void );
		void								clearTags( void );
		void								parseTag( void );
		void								parseAnnotation( const int fromRAVnum=0 );
		void								parseRAV( void );
		void								parseKnightsData( void );
};

#endif