]>
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 // ==========================================================================
17 #pragma implementation "reader.h"
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
31 #include "wx/txtstrm.h"
35 // ==========================================================================
37 // ==========================================================================
39 #define LIFE_CHECKVAL( msg ) \
42 wxMessageBox( msg, _("Error"), wxICON_EXCLAMATION | wxOK ); \
46 LifeReader::LifeReader(wxInputStream
& is
)
48 wxBufferedInputStream
buff_is(is
);
49 wxTextInputStream
text_is(buff_is
);
54 LIFE_CHECKVAL(_("Couldn't read any data"));
57 m_ok
= text_is
.ReadLine().Contains(wxT("#Life 1.05"));
58 LIFE_CHECKVAL(_("Error reading signature. Not a Life pattern?"));
61 m_description
= wxT("");
62 line
= text_is
.ReadLine();
63 while (buff_is
.IsOk() && line
.StartsWith(wxT("#D"), &rest
))
65 m_description
+= rest
.Trim(FALSE
);
66 m_description
+= wxT("\n");
67 line
= text_is
.ReadLine();
70 m_ok
= buff_is
.IsOk();
71 LIFE_CHECKVAL(_("Unexpected EOF while reading description"));
74 m_ok
= line
.StartsWith(wxT("#N"));
75 LIFE_CHECKVAL(_("Sorry, non-conway rules not supported yet"));
78 while (buff_is
.IsOk())
80 line
= ( text_is
.ReadLine() ).Trim();
84 if (line
.StartsWith(wxT("#P "), &rest
))