1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>InspIRCd: FileReader class Reference</title>
4 <link href="inspircd.css" rel="stylesheet" type="text/css">
6 <!-- Generated by Doxygen 1.3.3 -->
7 <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div>
8 <h1>FileReader Class Reference</h1>Caches a text file into memory and can be used to retrieve lines from it.
9 <a href="#_details">More...</a>
11 <code>#include <<a class="el" href="modules_8h-source.html">modules.h</a>></code>
13 Inherits <a class="el" href="classclassbase.html">classbase</a>.
15 <a href="classFileReader-members.html">List of all members.</a><table border=0 cellpadding=0 cellspacing=0>
17 <tr><td colspan=2><br><h2>Public Member Functions</h2></td></tr>
18 <tr><td class="memItemLeft" nowrap align=right valign=top> </td><td class="memItemRight" valign=bottom><a class="el" href="classFileReader.html#a0">FileReader</a> ()</td></tr>
20 <tr><td class="mdescLeft"> </td><td class="mdescRight">Default constructor. </em> <a href="#a0"></a><em><br><br></td></tr>
21 <tr><td class="memItemLeft" nowrap align=right valign=top> </td><td class="memItemRight" valign=bottom><a class="el" href="classFileReader.html#a1">FileReader</a> (std::string filename)</td></tr>
23 <tr><td class="mdescLeft"> </td><td class="mdescRight">Secondary constructor. </em> <a href="#a1"></a><em><br><br></td></tr>
24 <tr><td class="memItemLeft" nowrap align=right valign=top> </td><td class="memItemRight" valign=bottom><a class="el" href="classFileReader.html#a2">~FileReader</a> ()</td></tr>
26 <tr><td class="mdescLeft"> </td><td class="mdescRight">Default destructor. </em> <a href="#a2"></a><em><br><br></td></tr>
27 <tr><td class="memItemLeft" nowrap align=right valign=top>void </td><td class="memItemRight" valign=bottom><a class="el" href="classFileReader.html#a3">LoadFile</a> (std::string filename)</td></tr>
29 <tr><td class="mdescLeft"> </td><td class="mdescRight">Used to load a file. </em> <a href="#a3"></a><em><br><br></td></tr>
30 <tr><td class="memItemLeft" nowrap align=right valign=top>bool </td><td class="memItemRight" valign=bottom><a class="el" href="classFileReader.html#a4">Exists</a> ()</td></tr>
32 <tr><td class="mdescLeft"> </td><td class="mdescRight">Returns true if the file exists This function will return false if the file could not be opened. </em> <a href="#a4"></a><em><br><br></td></tr>
33 <tr><td class="memItemLeft" nowrap align=right valign=top>std::string </td><td class="memItemRight" valign=bottom><a class="el" href="classFileReader.html#a5">GetLine</a> (int x)</td></tr>
35 <tr><td class="mdescLeft"> </td><td class="mdescRight">Retrieve one line from the file. </em> <a href="#a5"></a><em><br><br></td></tr>
36 <tr><td class="memItemLeft" nowrap align=right valign=top>int </td><td class="memItemRight" valign=bottom><a class="el" href="classFileReader.html#a6">FileSize</a> ()</td></tr>
38 <tr><td class="mdescLeft"> </td><td class="mdescRight">Returns the size of the file in lines. </em> <a href="#a6"></a><em><br><br></td></tr>
39 <tr><td colspan=2><br><h2>Private Attributes</h2></td></tr>
40 <tr><td class="memItemLeft" nowrap align=right valign=top><a class="el" href="modules_8h.html#a31">file_cache</a> </td><td class="memItemRight" valign=bottom><a class="el" href="classFileReader.html#r0">fc</a></td></tr>
43 <hr><a name="_details"></a><h2>Detailed Description</h2>
44 Caches a text file into memory and can be used to retrieve lines from it.
46 This class contains methods for read-only manipulation of a text file in memory. Either use the constructor type with one parameter to load a file into memory at construction, or use the LoadFile method to load a file.
50 Definition at line <a class="el" href="modules_8h-source.html#l01236">1236</a> of file <a class="el" href="modules_8h-source.html">modules.h</a>.<hr><h2>Constructor & Destructor Documentation</h2>
51 <a name="a0" doxytag="FileReader::FileReader"></a><p>
52 <table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
55 <table cellpadding="0" cellspacing="0" border="0">
57 <td class="md" nowrap valign="top"> FileReader::FileReader </td>
58 <td class="md" valign="top">( </td>
59 <td class="mdname1" valign="top" nowrap> </td>
60 <td class="md" valign="top"> ) </td>
61 <td class="md" nowrap></td>
68 <table cellspacing=5 cellpadding=0 border=0>
78 This method does not load any file into memory, you must use the LoadFile method after constructing the class this way.
80 Definition at line <a class="el" href="modules_8cpp-source.html#l01023">1023</a> of file <a class="el" href="modules_8cpp-source.html">modules.cpp</a>.
82 <div class="fragment"><pre>01024 {
87 <a name="a1" doxytag="FileReader::FileReader"></a><p>
88 <table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
91 <table cellpadding="0" cellspacing="0" border="0">
93 <td class="md" nowrap valign="top"> FileReader::FileReader </td>
94 <td class="md" valign="top">( </td>
95 <td class="md" nowrap valign="top">std::string </td>
96 <td class="mdname1" valign="top" nowrap> <em>filename</em> </td>
97 <td class="md" valign="top"> ) </td>
98 <td class="md" nowrap></td>
105 <table cellspacing=5 cellpadding=0 border=0>
113 Secondary constructor.
115 This method initialises the class with a file loaded into it ready for GetLine and and other methods to be called. If the file could not be loaded, <a class="el" href="classFileReader.html#a6">FileReader::FileSize</a> returns 0.
117 Definition at line <a class="el" href="modules_8cpp-source.html#l01016">1016</a> of file <a class="el" href="modules_8cpp-source.html">modules.cpp</a>.
119 References <a class="el" href="modules_8h-source.html#l01238">fc</a>, and <a class="el" href="modules_8h-source.html#l00067">file_cache</a>.
121 <div class="fragment"><pre>01017 {
122 01018 <a class="code" href="modules_8h.html#a31">file_cache</a> c;
123 01019 readfile(c,filename.c_str());
124 01020 this-><a class="code" href="classFileReader.html#r0">fc</a> = c;
129 <a name="a2" doxytag="FileReader::~FileReader"></a><p>
130 <table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
133 <table cellpadding="0" cellspacing="0" border="0">
135 <td class="md" nowrap valign="top"> FileReader::~<a class="el" href="classFileReader.html">FileReader</a> </td>
136 <td class="md" valign="top">( </td>
137 <td class="mdname1" valign="top" nowrap> </td>
138 <td class="md" valign="top"> ) </td>
139 <td class="md" nowrap></td>
146 <table cellspacing=5 cellpadding=0 border=0>
156 This deletes the memory allocated to the file.
158 Definition at line <a class="el" href="modules_8cpp-source.html#l01035">1035</a> of file <a class="el" href="modules_8cpp-source.html">modules.cpp</a>.
160 <div class="fragment"><pre>01036 {
165 <hr><h2>Member Function Documentation</h2>
166 <a name="a4" doxytag="FileReader::Exists"></a><p>
167 <table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
170 <table cellpadding="0" cellspacing="0" border="0">
172 <td class="md" nowrap valign="top"> bool FileReader::Exists </td>
173 <td class="md" valign="top">( </td>
174 <td class="mdname1" valign="top" nowrap> </td>
175 <td class="md" valign="top"> ) </td>
176 <td class="md" nowrap></td>
183 <table cellspacing=5 cellpadding=0 border=0>
191 Returns true if the file exists This function will return false if the file could not be opened.
195 Definition at line <a class="el" href="modules_8cpp-source.html#l01039">1039</a> of file <a class="el" href="modules_8cpp-source.html">modules.cpp</a>.
197 References <a class="el" href="modules_8h-source.html#l01238">fc</a>.
199 <div class="fragment"><pre>01040 {
200 01041 <span class="keywordflow">if</span> (<a class="code" href="classFileReader.html#r0">fc</a>.size() == 0)
202 01043 <span class="keywordflow">return</span>(<span class="keyword">false</span>);
204 01045 <span class="keywordflow">else</span>
206 01047 <span class="keywordflow">return</span>(<span class="keyword">true</span>);
212 <a name="a6" doxytag="FileReader::FileSize"></a><p>
213 <table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
216 <table cellpadding="0" cellspacing="0" border="0">
218 <td class="md" nowrap valign="top"> int FileReader::FileSize </td>
219 <td class="md" valign="top">( </td>
220 <td class="mdname1" valign="top" nowrap> </td>
221 <td class="md" valign="top"> ) </td>
222 <td class="md" nowrap></td>
229 <table cellspacing=5 cellpadding=0 border=0>
237 Returns the size of the file in lines.
239 This method returns the number of lines in the read file. If it is 0, no lines have been read into memory, either because the file is empty or it does not exist, or cannot be opened due to permission problems.
241 Definition at line <a class="el" href="modules_8cpp-source.html#l01058">1058</a> of file <a class="el" href="modules_8cpp-source.html">modules.cpp</a>.
243 References <a class="el" href="modules_8h-source.html#l01238">fc</a>.
245 <div class="fragment"><pre>01059 {
246 01060 <span class="keywordflow">return</span> <a class="code" href="classFileReader.html#r0">fc</a>.size();
251 <a name="a5" doxytag="FileReader::GetLine"></a><p>
252 <table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
255 <table cellpadding="0" cellspacing="0" border="0">
257 <td class="md" nowrap valign="top"> std::string FileReader::GetLine </td>
258 <td class="md" valign="top">( </td>
259 <td class="md" nowrap valign="top">int </td>
260 <td class="mdname1" valign="top" nowrap> <em>x</em> </td>
261 <td class="md" valign="top"> ) </td>
262 <td class="md" nowrap></td>
269 <table cellspacing=5 cellpadding=0 border=0>
277 Retrieve one line from the file.
279 This method retrieves one line from the text file. If an empty non-NULL string is returned, the index was out of bounds, or the line had no data on it.
281 Definition at line <a class="el" href="modules_8cpp-source.html#l01051">1051</a> of file <a class="el" href="modules_8cpp-source.html">modules.cpp</a>.
283 References <a class="el" href="modules_8h-source.html#l01238">fc</a>.
285 <div class="fragment"><pre>01052 {
286 01053 <span class="keywordflow">if</span> ((x<0) || (x><a class="code" href="classFileReader.html#r0">fc</a>.size()))
287 01054 <span class="keywordflow">return</span> <span class="stringliteral">""</span>;
288 01055 <span class="keywordflow">return</span> <a class="code" href="classFileReader.html#r0">fc</a>[x];
293 <a name="a3" doxytag="FileReader::LoadFile"></a><p>
294 <table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
297 <table cellpadding="0" cellspacing="0" border="0">
299 <td class="md" nowrap valign="top"> void FileReader::LoadFile </td>
300 <td class="md" valign="top">( </td>
301 <td class="md" nowrap valign="top">std::string </td>
302 <td class="mdname1" valign="top" nowrap> <em>filename</em> </td>
303 <td class="md" valign="top"> ) </td>
304 <td class="md" nowrap></td>
311 <table cellspacing=5 cellpadding=0 border=0>
321 This method loads a file into the class ready for GetLine and and other methods to be called. If the file could not be loaded, <a class="el" href="classFileReader.html#a6">FileReader::FileSize</a> returns 0.
323 Definition at line <a class="el" href="modules_8cpp-source.html#l01027">1027</a> of file <a class="el" href="modules_8cpp-source.html">modules.cpp</a>.
325 References <a class="el" href="modules_8h-source.html#l01238">fc</a>, and <a class="el" href="modules_8h-source.html#l00067">file_cache</a>.
327 <div class="fragment"><pre>01028 {
328 01029 <a class="code" href="modules_8h.html#a31">file_cache</a> c;
329 01030 readfile(c,filename.c_str());
330 01031 this-><a class="code" href="classFileReader.html#r0">fc</a> = c;
335 <hr><h2>Member Data Documentation</h2>
336 <a name="r0" doxytag="FileReader::fc"></a><p>
337 <table class="mdTable" width="100%" cellpadding="2" cellspacing="0">
340 <table cellpadding="0" cellspacing="0" border="0">
342 <td class="md" nowrap valign="top"> <a class="el" href="modules_8h.html#a31">file_cache</a> <a class="el" href="classFileReader.html#r0">FileReader::fc</a><code> [private]</code>
347 <table cellspacing=5 cellpadding=0 border=0>
357 Definition at line <a class="el" href="modules_8h-source.html#l01238">1238</a> of file <a class="el" href="modules_8h-source.html">modules.h</a>.
359 Referenced by <a class="el" href="modules_8cpp-source.html#l01039">Exists()</a>, <a class="el" href="modules_8cpp-source.html#l01016">FileReader()</a>, <a class="el" href="modules_8cpp-source.html#l01058">FileSize()</a>, <a class="el" href="modules_8cpp-source.html#l01051">GetLine()</a>, and <a class="el" href="modules_8cpp-source.html#l01027">LoadFile()</a>. </td>
362 <hr>The documentation for this class was generated from the following files:<ul>
363 <li><a class="el" href="modules_8h-source.html">modules.h</a><li><a class="el" href="modules_8cpp-source.html">modules.cpp</a></ul>
364 <hr size="1"><address style="align: right;"><small>Generated on Thu May 12 22:59:02 2005 for InspIRCd by
365 <a href="http://www.doxygen.org/index.html">
366 <img src="doxygen.png" alt="doxygen" align="middle" border=0 >
367 </a>1.3.3 </small></address>