2000-07-15 15:51:35 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: reader.cpp
|
|
|
|
// Purpose: Life! pattern reader (writer coming soon)
|
|
|
|
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
|
|
|
|
// Modified by:
|
|
|
|
// Created: Jan/2000
|
|
|
|
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
// headers, declarations, constants
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/txtstrm.h"
|
|
|
|
#include "reader.h"
|
|
|
|
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
// LifeReader
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
#define LIFE_CHECKVAL( msg ) \
|
|
|
|
if (!m_ok) \
|
|
|
|
{ \
|
|
|
|
wxMessageBox( msg, _("Error"), wxICON_EXCLAMATION | wxOK ); \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
|
|
|
LifeReader::LifeReader(wxInputStream& is)
|
|
|
|
{
|
2001-05-10 02:24:10 -04:00
|
|
|
wxBufferedInputStream buff_is(is);
|
|
|
|
wxTextInputStream text_is(buff_is);
|
2005-01-31 13:18:18 -05:00
|
|
|
wxString line, rest;
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
// check stream
|
|
|
|
m_ok = is.IsOk();
|
|
|
|
LIFE_CHECKVAL(_("Couldn't read any data"));
|
|
|
|
|
|
|
|
// read signature
|
|
|
|
m_ok = text_is.ReadLine().Contains(wxT("#Life 1.05"));
|
|
|
|
LIFE_CHECKVAL(_("Error reading signature. Not a Life pattern?"));
|
|
|
|
|
|
|
|
// read description
|
2005-01-31 13:18:18 -05:00
|
|
|
m_description = wxEmptyString;
|
2000-07-15 15:51:35 -04:00
|
|
|
line = text_is.ReadLine();
|
|
|
|
while (buff_is.IsOk() && line.StartsWith(wxT("#D"), &rest))
|
|
|
|
{
|
2004-05-27 13:38:07 -04:00
|
|
|
m_description += rest.Trim(false);
|
2000-07-15 15:51:35 -04:00
|
|
|
m_description += wxT("\n");
|
|
|
|
line = text_is.ReadLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ok = buff_is.IsOk();
|
|
|
|
LIFE_CHECKVAL(_("Unexpected EOF while reading description"));
|
|
|
|
|
|
|
|
// read rules
|
|
|
|
m_ok = line.StartsWith(wxT("#N"));
|
|
|
|
LIFE_CHECKVAL(_("Sorry, non-conway rules not supported yet"));
|
|
|
|
|
|
|
|
// read shape
|
|
|
|
while (buff_is.IsOk())
|
|
|
|
{
|
|
|
|
line = ( text_is.ReadLine() ).Trim();
|
|
|
|
|
2005-01-31 13:18:18 -05:00
|
|
|
if (!line.empty())
|
2000-07-15 15:51:35 -04:00
|
|
|
{
|
|
|
|
if (line.StartsWith(wxT("#P "), &rest))
|
|
|
|
m_shape.Add(rest);
|
|
|
|
else
|
|
|
|
m_shape.Add(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|