diff options
Diffstat (limited to 'src/old/xmlfilereader.cpp')
-rw-r--r-- | src/old/xmlfilereader.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/old/xmlfilereader.cpp b/src/old/xmlfilereader.cpp new file mode 100644 index 0000000..ed674a8 --- /dev/null +++ b/src/old/xmlfilereader.cpp | |||
@@ -0,0 +1,58 @@ | |||
1 | #include "xmlfilereader.h" | ||
2 | #include "exceptions.h" | ||
3 | #include <string.h> | ||
4 | |||
5 | XmlFileReader::XmlFileReader( const char *sFile, bool bStrip ) | ||
6 | : XmlReader( bStrip ) | ||
7 | { | ||
8 | fh = fopen( sFile, "rt" ); | ||
9 | |||
10 | if( fh == NULL ) | ||
11 | { | ||
12 | throw XmlException("Couldn't open file: %s", sFile ); | ||
13 | //nError = 1; | ||
14 | } | ||
15 | else | ||
16 | { | ||
17 | buildDoc(); | ||
18 | } | ||
19 | } | ||
20 | |||
21 | XmlFileReader::~XmlFileReader() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | char XmlFileReader::getChar( int nIndex ) | ||
26 | { | ||
27 | // Make sure we always have a little data left in the buffer | ||
28 | if( fbDataIn.getLength() <= nIndex+1 && fh ) | ||
29 | { | ||
30 | int nBytes = fbDataIn.getCapacity()-1; | ||
31 | char *buf = new char[nBytes]; | ||
32 | int nRead = fread( buf, 1, nBytes, fh ); | ||
33 | fbDataIn.appendData( buf, nRead ); | ||
34 | delete[] buf; | ||
35 | |||
36 | if( nRead < nBytes ) | ||
37 | { | ||
38 | fclose( fh ); | ||
39 | fh = NULL; | ||
40 | } | ||
41 | } | ||
42 | if( fbDataIn.getLength() >= nIndex+1 ) | ||
43 | { | ||
44 | return fbDataIn.getData()[nIndex]; | ||
45 | } | ||
46 | else | ||
47 | { | ||
48 | throw XmlException("End of XML stream read."); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | void XmlFileReader::usedChar( int nAmnt ) | ||
53 | { | ||
54 | if( fbDataIn.getLength()-nAmnt >= 0 ) | ||
55 | { | ||
56 | fbDataIn.usedData( nAmnt ); | ||
57 | } | ||
58 | } | ||