]>
git.saurik.com Git - wxWidgets.git/blob - demos/life/reader.cpp
ed6b875a3fe5374fec9f8fe615ffa649aac92fe3
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Life! pattern reader (writer coming soon)
4 // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
7 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ==========================================================================
12 // headers, declarations, constants
13 // ==========================================================================
15 // For compilers that support precompilation, includes "wx/wx.h".
16 #include "wx/wxprec.h"
26 #include "wx/txtstrm.h"
30 // ==========================================================================
32 // ==========================================================================
34 #define LIFE_CHECKVAL( msg ) \
37 wxMessageBox( msg, _("Error"), wxICON_EXCLAMATION | wxOK ); \
41 LifeReader::LifeReader(wxInputStream
& is
)
43 wxBufferedInputStream
buff_is(is
);
44 wxTextInputStream
text_is(buff_is
);
49 LIFE_CHECKVAL(_("Couldn't read any data"));
52 m_ok
= text_is
.ReadLine().Contains(wxT("#Life 1.05"));
53 LIFE_CHECKVAL(_("Error reading signature. Not a Life pattern?"));
56 m_description
= wxEmptyString
;
57 line
= text_is
.ReadLine();
58 while (buff_is
.IsOk() && line
.StartsWith(wxT("#D"), &rest
))
60 m_description
+= rest
.Trim(false);
61 m_description
+= wxT("\n");
62 line
= text_is
.ReadLine();
65 m_ok
= buff_is
.IsOk();
66 LIFE_CHECKVAL(_("Unexpected EOF while reading description"));
69 m_ok
= line
.StartsWith(wxT("#N"));
70 LIFE_CHECKVAL(_("Sorry, non-conway rules not supported yet"));
73 while (buff_is
.IsOk())
75 line
= ( text_is
.ReadLine() ).Trim();
79 if (line
.StartsWith(wxT("#P "), &rest
))