qcross/libqnono/cnonogram.cpp

73 lines
2.7 KiB
C++
Raw Normal View History

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>
#include <QDataStream>
2010-06-16 12:53:56 +00:00
namespace libqnono {
static const quint64 CNonogram_MAGIC = Q_UINT64_C(0x35a8bca32006c5a9);
2012-04-11 13:01:54 +00:00
CNonogram::CNonogram() {
2012-04-11 13:01:54 +00:00
}
CNonogram::CNonogram(const NonogramProblem & problem)
: m_problem(problem), m_marker(problem.size()) {
2012-04-11 13:01:54 +00:00
}
bool CNonogram::readFromStream(QDataStream & stream) {
2012-04-11 13:01:54 +00:00
quint64 magic;
stream >> magic;
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;
}
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;
2010-06-16 12:53:56 +00:00
}
QDataStream & operator<<(QDataStream& stream, const libqnono::CNonogram& nonogram) {
nonogram.writeToStream(stream);
return stream;
}
QDataStream & operator>>(QDataStream & stream, CNonogram & nonogram) {
nonogram.readFromStream(stream);
return stream;
}
2010-06-16 12:53:56 +00:00
}