Cute Chess  0.1
econode.h
1 /*
2  This file is part of Cute Chess.
3  Copyright (C) 2008-2018 Cute Chess authors
4 
5  Cute Chess 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 3 of the License, or
8  (at your option) any later version.
9 
10  Cute Chess is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef ECONODE_H
20 #define ECONODE_H
21 
22 #include <QString>
23 #include <QMap>
24 #include "pgngame.h"
25 class QDataStream;
26 class PgnStream;
27 
43 class LIB_EXPORT EcoNode
44 {
45  public:
47  ~EcoNode();
48 
54  bool isLeaf() const;
59  EcoNode* child(const QString& sanMove) const;
64  QString ecoCode() const;
69  QString opening() const;
74  QString variation() const;
75 
77  static void initialize();
79  static void initialize(PgnStream& in);
84  static const EcoNode* root();
89  static const EcoNode* find(const QVector<PgnGame::MoveData>& moves);
91  static void write(const QString& fileName);
92 
93  private:
94  friend LIB_EXPORT QDataStream& operator<<(QDataStream& out, const EcoNode* node);
95  friend LIB_EXPORT QDataStream& operator>>(QDataStream& in, EcoNode*& node);
96 
97  EcoNode();
98  void addChild(const QString& sanMove, EcoNode* child);
99 
100  qint16 m_ecoCode;
101  qint32 m_opening;
102  QString m_variation;
103 
104  QMap<QString, EcoNode*> m_children;
105 };
106 
108 extern LIB_EXPORT QDataStream& operator<<(QDataStream& out, const EcoNode* node);
113 extern LIB_EXPORT QDataStream& operator>>(QDataStream& in, EcoNode*& node);
114 
115 #endif // ECONODE_H
A class for reading games in PGN format from a text stream.
Definition: pgnstream.h:42
A node in the ECO tree (Encyclopaedia of Chess Openings)
Definition: econode.h:43