73 lines
2.7 KiB
C++
73 lines
2.7 KiB
C++
/***************************************************************************
|
|
* Copyright (C) 2008 by Oliver Groß *
|
|
* z.o.gross@gmx.de *
|
|
* *
|
|
* 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. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program; if not, write to the *
|
|
* Free Software Foundation, Inc., *
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
***************************************************************************/
|
|
#include "cnonogram.h"
|
|
#include <QImage>
|
|
#include <QDataStream>
|
|
|
|
namespace libqnono {
|
|
static const quint64 CNonogram_MAGIC = Q_UINT64_C(0x35a8bca32006c5a9);
|
|
|
|
CNonogram::CNonogram() {
|
|
}
|
|
|
|
CNonogram::CNonogram(const NonogramProblem & problem)
|
|
: m_problem(problem), m_marker(problem.size()) {
|
|
}
|
|
|
|
bool CNonogram::readFromStream(QDataStream & stream) {
|
|
quint64 magic;
|
|
stream >> magic;
|
|
if (CNonogram_MAGIC != magic || QDataStream::Ok != stream.status()) {
|
|
if (QDataStream::ReadPastEnd != stream.status()) stream.setStatus(QDataStream::ReadCorruptData);
|
|
return false;
|
|
}
|
|
|
|
NonogramProblem problem;
|
|
NonogramMarker marker;
|
|
|
|
if (!problem.readFromStream(stream)) return false;
|
|
if (!marker.readFromStream(stream)) return false;
|
|
|
|
if (problem.size() != marker.size()) {
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
|
return false;
|
|
}
|
|
|
|
m_problem = problem;
|
|
m_marker = marker;
|
|
|
|
return true;
|
|
}
|
|
|
|
void CNonogram::writeToStream(QDataStream & stream) const {
|
|
stream << CNonogram_MAGIC << m_problem << m_marker;
|
|
}
|
|
|
|
QDataStream & operator<<(QDataStream& stream, const libqnono::CNonogram& nonogram) {
|
|
nonogram.writeToStream(stream);
|
|
return stream;
|
|
}
|
|
|
|
QDataStream & operator>>(QDataStream & stream, CNonogram & nonogram) {
|
|
nonogram.readFromStream(stream);
|
|
return stream;
|
|
}
|
|
}
|