]>
git.saurik.com Git - wxWidgets.git/blob - demos/life/reader.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Life! pattern reader (writer coming soon)
4 // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
8 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ==========================================================================
13 // headers, declarations, constants
14 // ==========================================================================
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/txtstrm.h"
31 // ==========================================================================
33 // ==========================================================================
35 #define LIFE_CHECKVAL( msg ) \
38 wxMessageBox( msg, _("Error"), wxICON_EXCLAMATION | wxOK ); \
42 LifeReader::LifeReader(wxInputStream
& is
)
44 wxBufferedInputStream
buff_is(is
);
45 wxTextInputStream
text_is(buff_is
);
50 LIFE_CHECKVAL(_("Couldn't read any data"));
53 m_ok
= text_is
.ReadLine().Contains(wxT("#Life 1.05"));
54 LIFE_CHECKVAL(_("Error reading signature. Not a Life pattern?"));
57 m_description
= wxEmptyString
;
58 line
= text_is
.ReadLine();
59 while (buff_is
.IsOk() && line
.StartsWith(wxT("#D"), &rest
))
61 m_description
+= rest
.Trim(false);
62 m_description
+= wxT("\n");
63 line
= text_is
.ReadLine();
66 m_ok
= buff_is
.IsOk();
67 LIFE_CHECKVAL(_("Unexpected EOF while reading description"));
70 m_ok
= line
.StartsWith(wxT("#N"));
71 LIFE_CHECKVAL(_("Sorry, non-conway rules not supported yet"));
74 while (buff_is
.IsOk())
76 line
= ( text_is
.ReadLine() ).Trim();
80 if (line
.StartsWith(wxT("#P "), &rest
))