]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/textfile.tex
Added OnKeyDown, OnKeyUp.
[wxWidgets.git] / docs / latex / wx / textfile.tex
CommitLineData
7f561143
VZ
1% automatically generated by HelpGen from textfile.tex at 10/Jan/99 18:47:37
2\section{\class{wxTextFile}}\label{wxtextfile}
3
4The wxTextFile is a simple class which allows to work with text files on line by
5line basis. It also understands the differences in line termination characters
6under different platforms and will not do anything bad to files with "non
7native" line termination sequences - in fact, it can be also used to modify the
8text files and chaneg the line termination characters from one type (say DOS) to
9another (say Unix).
10
11One word of warning: the class is not at all optimized for big files and so it
12will load the file entirely into memory when opened. Of course, you should not
13work in this way with large files (as an estimation, anything over 1 Megabyte is
14surely too big for this class). On the other hand, it is not a serious
15limitation for the small files like configuration files or programs sources
16which are well handled by wxTextFile.
17
18The typical things you may do with wxTextFile in order are:
dface61c 19
7f561143
VZ
20\begin{itemize}\itemsep=0pt
21\item Create and open it: this is done with \helpref{Open}{wxtextfileopen}
22function which opens the file (name may be specified either as Open argument or
23in the constructor), reads its contents in memory and closes it. If all of these
24operations are successful, Open() will return TRUE and FALSE on error.
25\item Work with the lines in the file: this may be done either with "direct
26access" functions like \helpref{GetLineCount}{wxtextfilegetlinecount} and
27\helpref{GetLine}{wxtextfilegetline} ({\it operator[]} does exactly the same
28but looks more like array addressing) or with "sequential access" functions
29which include \helpref{GetFirstLine}{wxtextfilegetfirstline}/
30\helpref{GetNextLine}{wxtextfilegetnextline} and also
dface61c 31\helpref{GetLastLine}{wxtextfilegetlastline}/\helpref{GetPrevLine}{wxtextfilegetprevline}.
7f561143
VZ
32For the sequential access functions the current line number is maintained: it is
33returned by \helpref{GetCurrentLine}{wxtextfilegetcurrentline} and may be
34changed with \helpref{GoToLine}{wxtextfilegotoline}.
35\item Add/remove lines to the file: \helpref{AddLine}{wxtextfileaddline} and
36\helpref{InsertLine}{wxtextfileinsertline} add new lines while
37\helpref{RemoveLine}{wxtextfileremoveline} deletes the existing ones.
38\item Save your changes: notice that the changes you do to the file will {\bf
39not} be saved automatically, calling \helpref{Close}{wxtextfileclose} or doing
40nothing discards them! To save the chanegs you must explicitly call
41\helpref{Write}{wxtextfilewrite} - here, you may also change the line
42termination type if you wish.
43\end{itemize}
44
45\wxheading{See also:}
46
47\helpref{wxFile}{wxfile}
48
49\wxheading{Derived from}
50
51No base class
52
53\wxheading{Data structures}
54
55The following constants identify the line termination type:
56\begin{verbatim}
57enum wxTextFileType
58{
59 wxTextFileType_None, // incomplete (the last line of the file only)
60 wxTextFileType_Unix, // line is terminated with 'LF' = 0xA = 10 = '\n'
61 wxTextFileType_Dos, // 'CR' 'LF'
62 wxTextFileType_Mac // 'CR' = 0xD = 13 = '\r'
63}
64\end{verbatim}
65
66\latexignore{\rtfignore{\wxheading{Members}}}
67
68\membersection{wxTextFile::wxTextFile}\label{wxtextfilectordef}
69\constfunc{}{wxTextFile}{\void}
70
71Default constructor, use Open(string) to initialize the object.
72
73\membersection{wxTextFile::wxTextFile}\label{wxtextfilector}
dface61c 74
7f561143
VZ
75\constfunc{}{wxTextFile}{\param{const wxString\& }{strFile}}
76
77Constructor does not load the file into memory, use Open() to do it.
78
79\membersection{wxTextFile::Exists}\label{wxtextfileexists}
dface61c 80
7f561143
VZ
81\constfunc{bool}{Exists}{\void}
82
83Return TRUE if file exists - the name of the file should have been specified
84in the constructor before calling Exists().
85
86\membersection{wxTextFile::Open}\label{wxtextfileopen}
dface61c 87
7f561143
VZ
88\constfunc{bool}{Open}{\void}
89
90Open() opens the file with the name which was given in the \helpref{constructor}{wxtextfilector}
91and also loads file in memory on success.
92
93\membersection{wxTextFile::Open}\label{wxtextfileopenname}
dface61c 94
7f561143
VZ
95\constfunc{bool}{Open}{\param{const wxString\& }{strFile}}
96
97Same as \helpref{Open()}{wxtextfileopen} but allows to specify the file name
98(must be used if the default constructor was used to create the object).
99
100\membersection{wxTextFile::Close}\label{wxtextfileclose}
dface61c 101
7f561143
VZ
102\constfunc{bool}{Close}{\void}
103
104Closes the file and frees memory, {\bf losing all changes}. Use \helpref{Write()}{wxtextfilewrite}
105if you want to save them.
106
107\membersection{wxTextFile::IsOpened}\label{wxtextfileisopened}
dface61c 108
7f561143
VZ
109\constfunc{bool}{IsOpened}{\void}
110
111Returns TRUE if the file is currently opened.
112
113\membersection{wxTextFile::GetLineCount}\label{wxtextfilegetlinecount}
dface61c 114
7f561143
VZ
115\constfunc{size\_t}{GetLineCount}{\void}
116
117Get the number of lines in the file.
118
119\membersection{wxTextFile::GetLine}\label{wxtextfilegetline}
dface61c 120
7f561143
VZ
121\constfunc{wxString\&}{GetLine}{\param{size\_t }{n}}
122
123Retrieves the line number {\it n} from the file. The returned line may be
124modified but you shouldn't add line terminator at the end - this will be done
125by wxTextFile.
126
dface61c
JS
127\membersection{wxTextFile::operator[]}\label{wxtextfileoperatorarray}
128
7f561143
VZ
129\constfunc{wxString\&}{operator[]}{\param{size\_t }{n}}
130
131The same as \helpref{GetLine}{wxtextfilegetline}.
132
133\membersection{wxTextFile::GetCurrentLine}\label{wxtextfilegetcurrentline}
dface61c 134
7f561143
VZ
135\constfunc{size\_t}{GetCurrentLine}{\void}
136
137Returns the current line: it has meaning only when you're using
138GetFirstLine()/GetNextLine() functions, it doesn't get updated when
139you're using "direct access" functions like GetLine(). GetFirstLine() and
140GetLastLine() also change the value of the current line, as well as
141GoToLine().
142
143\membersection{wxTextFile::GoToLine}\label{wxtextfilegotoline}
dface61c 144
7f561143
VZ
145\constfunc{void}{GoToLine}{\param{size\_t }{n}}
146
147Changes the value returned by \helpref{GetCurrentLine}{wxtextfilegetcurrentline}
148and used by \helpref{GetFirstLine()}{wxtextfilegetfirstline}()/\helpref{GetNextLine()}{wxtextfilegetnextline}.
149
150\membersection{wxTextFile::Eof}\label{wxtextfileeof}
dface61c 151
7f561143
VZ
152\constfunc{bool}{Eof}{\void}
153
154Returns TRUE if the current line is the last one.
155
156\membersection{wxTextFile::GetFirstLine}\label{wxtextfilegetfirstline}
dface61c 157
7f561143
VZ
158\constfunc{wxString\&}{GetFirstLine}{\void}
159
160This method together with \helpref{GetNextLine()}{wxtextfilegetnextline}
161allows more "iterator-like" traversal of the list of lines, i.e. you may
162write something like:
163
164\begin{verbatim}
165for ( str = GetFirstLine(); !Eof(); str = GetNextLine() )
166{
167 // do something with the current line in str
168}
169\end{verbatim}
170
171\membersection{wxTextFile::GetNextLine}\label{wxtextfilegetnextline}
dface61c 172
7f561143
VZ
173\func{wxString\&}{GetNextLine}{\void}
174
175Gets the next line (see \helpref{GetFirstLine}{wxtextfilegetfirstline} for
176the example).
177
178\membersection{wxTextFile::GetPrevLine}\label{wxtextfilegetprevline}
dface61c 179
7f561143
VZ
180\func{wxString\&}{GetPrevLine}{\void}
181
182Gets the previous line in the file.
183
184\membersection{wxTextFile::GetLastLine}\label{wxtextfilegetlastline}
dface61c 185
7f561143
VZ
186\func{wxString\&}{GetLastLine}{\void}
187
188Gets the last line of the file.
189
190\membersection{wxTextFile::GetLineType}\label{wxtextfilegetlinetype}
dface61c 191
7f561143
VZ
192\constfunc{wxTextFileType}{GetLineType}{\param{size\_t }{n}}
193
194Get the type of the line (see also \helpref{GetEOL}{wxtextfilegeteol})
195
196\membersection{wxTextFile::GuessType}\label{wxtextfileguesstype}
dface61c 197
7f561143
VZ
198\constfunc{wxTextFileType}{GuessType}{\void}
199
200Guess the type of file (which is supposed to be opened). If sufficiently
201many lines of the file are in DOS/Unix/Mac format, the corresponding value will
202be returned. If the detection mechanism fails wxTextFileType\_None is returned.
203
204\membersection{wxTextFile::GetName}\label{wxtextfilegetname}
dface61c 205
7f561143
VZ
206\constfunc{const char*}{GetName}{\void}
207
208Get the name of the file.
209
210\membersection{wxTextFile::AddLine}\label{wxtextfileaddline}
dface61c 211
7f561143
VZ
212\constfunc{void}{AddLine}{\param{const wxString\& }{str}, \param{wxTextFileType }{type = typeDefault}}
213
214Adds a line to the end of file.
215
216\membersection{wxTextFile::InsertLine}\label{wxtextfileinsertline}
dface61c 217
7f561143
VZ
218\constfunc{void}{InsertLine}{\param{const wxString\& }{str}, \param{size\_t }{n}, \param{wxTextFileType }{type = typeDefault}}
219
220Insert a line before the line number {\it n}.
221
222\membersection{wxTextFile::RemoveLine}\label{wxtextfileremoveline}
dface61c 223
7f561143
VZ
224\constfunc{void}{RemoveLine}{\param{size\_t }{n}}
225
226Delete one line from the file.
227
228\membersection{wxTextFile::Write}\label{wxtextfilewrite}
dface61c 229
7f561143
VZ
230\constfunc{bool}{Write}{\param{wxTextFileType }{typeNew = wxTextFileType\_None}}
231
232Change the file on disk. The {\it typeNew} parameter allows to change the
233file format (default argument means "don't change type") and may be used to
234convert, for example, DOS files to Unix.
235
236\membersection{wxTextFile::GetEOL}\label{wxtextfilegeteol}
dface61c 237
7f561143
VZ
238\constfunc{static const char*}{GetEOL}{\param{wxTextFileType }{type = typeDefault}}
239
240Get the line termination string corresponding to given constant. {\it typeDefault} is
241the value defined during the compilation and corresponds to the native format of the
242platform, i.e. it will be wxTextFileType\_Dos under Windows, wxTextFileType\_Unix under
243Unix and wxTextFileType\_Mac under Mac.
244
245\membersection{wxTextFile::\destruct{wxTextFile}}\label{wxtextfiledtor}
dface61c 246
7f561143
VZ
247\constfunc{}{\destruct{wxTextFile}}{\void}
248
249Destructor does nothing.
dface61c 250