Refactored TurnTest.
[tagua/yd.git] / src / pgnparser.h
blobfcca88028123c2f8751bdbe57ab0eaa3b2a1ab61
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef PGNPARSER_H
12 #define PGNPARSER_H
14 #include <vector>
15 #include <map>
16 #include <iosfwd>
17 #ifdef Q_CC_MSVC
18 #pragma warning( push )
19 #pragma warning( disable : 4100 )
20 #include <boost/variant.hpp>
21 #pragma warning( pop )
22 #else
23 #include <boost/variant.hpp>
24 #endif
25 #include <QString>
26 #include "algebraicnotation.h"
28 class QRegExp;
30 class PGN {
31 public:
32 class Move {
33 public:
34 int m_number;
35 QString m_move;
36 Move(int n, const QString& s)
37 : m_number(n), m_move(s) { }
39 class BeginVariation {};
40 class EndVariation {};
41 typedef boost::variant<Move, QString, BeginVariation, EndVariation> Entry;
43 private:
44 /* friend std::ostream& operator<<(std::ostream& os, const PGN& pgn);*/
45 QString m_result;
46 bool m_valid;
48 static QRegExp number, begin_var, end_var, comment, comment2,
49 wsPattern, tag, result, time, eol, move_tag, move;
51 static bool tryRegExp(QRegExp& re, const QString& str, int& offset);
52 bool parse(const QString& pgn);
53 public:
54 std::vector<Entry> m_entries;
55 std::map<QString, QString> m_tags;
56 explicit PGN(const QString&);
57 inline bool valid() const { return m_valid; }
58 inline uint size() const { return m_entries.size(); }
59 const Entry* operator[](int index) const { return &m_entries[index]; }
62 #endif // PGNPARSER_H