2010-06-16 12:53:56 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* 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>
|
2012-04-19 15:30:54 +00:00
|
|
|
#include <QDataStream>
|
2010-06-16 12:53:56 +00:00
|
|
|
|
2011-12-21 11:49:33 +00:00
|
|
|
namespace libqnono {
|
2012-04-19 15:30:54 +00:00
|
|
|
static const quint64 CNonogram_MAGIC = Q_UINT64_C(0x35a8bca32006c5a9);
|
2012-04-11 13:01:54 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
CNonogram::CNonogram() {
|
2012-04-11 13:01:54 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
CNonogram::CNonogram(const NonogramProblem & problem)
|
|
|
|
: m_problem(problem), m_marker(problem.size()) {
|
2012-04-11 13:01:54 +00:00
|
|
|
}
|
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
bool CNonogram::readFromStream(QDataStream & stream) {
|
2012-04-11 13:01:54 +00:00
|
|
|
quint64 magic;
|
|
|
|
stream >> magic;
|
2012-04-19 15:30:54 +00:00
|
|
|
if (CNonogram_MAGIC != magic || QDataStream::Ok != stream.status()) {
|
2012-04-11 13:01:54 +00:00
|
|
|
if (QDataStream::ReadPastEnd != stream.status()) stream.setStatus(QDataStream::ReadCorruptData);
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-21 11:49:33 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
NonogramProblem problem;
|
|
|
|
NonogramMarker marker;
|
2012-02-28 10:33:20 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
if (!problem.readFromStream(stream)) return false;
|
|
|
|
if (!marker.readFromStream(stream)) return false;
|
2012-02-28 10:33:20 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
if (problem.size() != marker.size()) {
|
|
|
|
stream.setStatus(QDataStream::ReadCorruptData);
|
2012-02-28 10:33:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
m_problem = problem;
|
|
|
|
m_marker = marker;
|
2012-02-28 10:33:20 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
void CNonogram::writeToStream(QDataStream & stream) const {
|
|
|
|
stream << CNonogram_MAGIC << m_problem << m_marker;
|
2010-06-16 12:53:56 +00:00
|
|
|
}
|
2011-12-21 11:49:33 +00:00
|
|
|
|
2012-04-19 15:30:54 +00:00
|
|
|
QDataStream & operator<<(QDataStream& stream, const libqnono::CNonogram& nonogram) {
|
2012-02-28 10:33:20 +00:00
|
|
|
nonogram.writeToStream(stream);
|
2011-12-21 11:49:33 +00:00
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDataStream & operator>>(QDataStream & stream, CNonogram & nonogram) {
|
2012-02-28 10:33:20 +00:00
|
|
|
nonogram.readFromStream(stream);
|
2011-12-21 11:49:33 +00:00
|
|
|
return stream;
|
|
|
|
}
|
2010-06-16 12:53:56 +00:00
|
|
|
}
|