| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2009 by The qGo Project * |
| 3 | * * |
| 4 | * This file is part of qGo. * |
| 5 | * * |
| 6 | * qGo is free software: you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/> * |
| 18 | * or write to the Free Software Foundation, Inc., * |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | |
| 23 | #ifndef SGFPARSER_H |
| 24 | #define SGFPARSER_H |
| 25 | |
| 26 | #include "../defines.h" |
| 27 | #include "tree.h" |
| 28 | |
| 29 | #include <QtCore> |
| 30 | |
| 31 | class GameData; |
| 32 | |
| 33 | class SGFParser |
| 34 | { |
| 35 | public: |
| 36 | SGFParser(Tree *tree); |
| 37 | ~SGFParser(); |
| 38 | QString loadFile(const QString &fileName); |
| 39 | GameData * initGame(const QString &toParse, const QString &fileName); |
| 40 | |
| 41 | bool parse(const QString &fileName, const QString &filter=0); |
| 42 | |
| 43 | bool doParse(const QString &toParseStr); |
| 44 | bool doWrite(const QString &fileName, Tree *tree, GameData *gameData); |
| 45 | bool exportSGFtoClipB(QString *str, Tree *tree, GameData *gameData); |
| 46 | |
| 47 | protected: |
| 48 | int minPos(int n1, int n2, int n3); |
| 49 | bool corruptSgf(int where=0, QString reason=QString::null); |
| 50 | |
| 51 | bool parseProperty(const QString &toParse, const QString &prop, QString &result); |
| 52 | |
| 53 | void traverse(Move *t, GameData *gameData); |
| 54 | void writeGameHeader(GameData *gameData); |
| 55 | bool writeStream(Tree *tree, GameData *gameData); |
| 56 | |
| 57 | private: |
| 58 | bool setCodec(QString c = QString()); |
| 59 | |
| 60 | QTextStream *stream; |
| 61 | QTextCodec * readCodec; |
| 62 | bool isRoot; |
| 63 | Tree *tree; |
| 64 | bool loadedfromfile; |
| 65 | }; |
| 66 | |
| 67 | #endif |