Tentative Randomless-Entropy variant.
[tagua/yd.git] / src / pgnparser.h
blob054608cc627e09e056d5584d991d4e1ec4f42dc3
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
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>
27 class QRegExp;
29 class PGN {
30 public:
31 class Move {
32 public:
33 int m_number;
34 QString m_move;
35 Move(int n, const QString& s)
36 : m_number(n), m_move(s) { }
38 class BeginVariation {};
39 class EndVariation {};
40 typedef boost::variant<Move, QString, BeginVariation, EndVariation> Entry;
42 private:
43 /* friend std::ostream& operator<<(std::ostream& os, const PGN& pgn);*/
44 QString m_result;
45 bool m_valid;
47 static QRegExp number, begin_var, end_var, comment, comment2,
48 wsPattern, tag, result, time, eol, move_tag, move;
50 static bool tryRegExp(QRegExp& re, const QString& str, int& offset);
51 bool parse(const QString& pgn);
52 public:
53 std::vector<Entry> m_entries;
54 std::map<QString, QString> m_tags;
55 explicit PGN(const QString&);
56 inline bool valid() const { return m_valid; }
57 inline uint size() const { return m_entries.size(); }
58 const Entry* operator[](int index) const { return &m_entries[index]; }
61 #endif // PGNPARSER_H