diff options
Diffstat (limited to 'src/xmlreader.h')
| -rw-r--r-- | src/xmlreader.h | 133 | 
1 files changed, 133 insertions, 0 deletions
| diff --git a/src/xmlreader.h b/src/xmlreader.h new file mode 100644 index 0000000..a8a81f0 --- /dev/null +++ b/src/xmlreader.h | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | #ifndef XMLREADER | ||
| 2 | #define XMLREADER | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #include "xmldocument.h" | ||
| 6 | #include "flexbuf.h" | ||
| 7 | |||
| 8 | /** | ||
| 9 | * Takes care of reading in xml formatted data from a file. This could/should | ||
| 10 | * be made more arbitrary in the future so that we can read the data from any | ||
| 11 | * source. This is actually made quite simple already since all data read in | ||
| 12 | * is handled by one single helper function and then palced into a FlexBuf for | ||
| 13 | * easy access by the other functions. The FlexBuf also allows for block | ||
| 14 | * reading from disk, which improves speed by a noticable amount. | ||
| 15 | * <br> | ||
| 16 | * There are also some extra features implemented that allow you to break the | ||
| 17 | * standard XML reader specs and eliminate leading and trailing whitespace in | ||
| 18 | * all read content. This is useful in situations where you allow additional | ||
| 19 | * whitespace in the files to make them easily human readable. The resturned | ||
| 20 | * content will be NULL in sitautions where all content between nodes was | ||
| 21 | * stripped. | ||
| 22 | *@author Mike Buland | ||
| 23 | */ | ||
| 24 | class XmlReader : public XmlDocument | ||
| 25 | { | ||
| 26 | public: | ||
| 27 | /** | ||
| 28 | * Create a standard XmlReader. The optional parameter bStrip allows you to | ||
| 29 | * create a reader that will strip out all leading and trailing whitespace | ||
| 30 | * in content, a-la html. | ||
| 31 | *@param bStrip Strip out leading and trailing whitespace? | ||
| 32 | */ | ||
| 33 | XmlReader( bool bStrip=false ); | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Destroy this XmlReader. | ||
| 37 | */ | ||
| 38 | ~XmlReader(); | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Get the error code if an error happened. | ||
| 42 | *@returns The error code (I don't know what they are either) | ||
| 43 | */ | ||
| 44 | int getError(); | ||
| 45 | |||
| 46 | /** | ||
| 47 | * Report an error to something, this is a really strange mechanism and | ||
| 48 | * should probably just be replaced with the multi-log system. | ||
| 49 | *@param sError The error to report. | ||
| 50 | */ | ||
| 51 | void reportError( const char *sError ); | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Build a document based on some kind of input. This is called | ||
| 55 | * automatically by the constructor. | ||
| 56 | */ | ||
| 57 | bool buildDoc(); | ||
| 58 | |||
| 59 | private: | ||
| 60 | /** | ||
| 61 | * This is called by the low level automoton in order to get the next | ||
| 62 | * character. This function should return a character at the current | ||
| 63 | * position plus nIndex, but does not increment the current character. | ||
| 64 | *@param nIndex The index of the character from the current stream position. | ||
| 65 | *@returns A single character at the requested position, or 0 for end of | ||
| 66 | * stream. | ||
| 67 | */ | ||
| 68 | virtual char getChar( int nIndex = 0 ) = 0; | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Called to increment the current stream position by a single character. | ||
| 72 | */ | ||
| 73 | virtual void usedChar() = 0; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Automoton function: is whitespace. | ||
| 77 | *@param chr A character | ||
| 78 | *@returns True if chr is whitespace, false otherwise. | ||
| 79 | */ | ||
| 80 | bool isws( char chr ); | ||
| 81 | |||
| 82 | /** | ||
| 83 | * Automoton function: ws. Skips sections of whitespace. | ||
| 84 | *@returns True if everything was ok, False for end of stream. | ||
| 85 | */ | ||
| 86 | bool ws(); | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Automoton function: node. Processes an XmlNode | ||
| 90 | *@returns True if everything was ok, False for end of stream. | ||
| 91 | */ | ||
| 92 | bool node(); | ||
| 93 | |||
| 94 | /** | ||
| 95 | * Automoton function: startNode. Processes the begining of a node. | ||
| 96 | *@returns True if everything was ok, False for end of stream. | ||
| 97 | */ | ||
| 98 | bool startNode(); | ||
| 99 | |||
| 100 | /** | ||
| 101 | * Automoton function: name. Processes the name of a node. | ||
| 102 | *@returns True if everything was ok, False for end of stream. | ||
| 103 | */ | ||
| 104 | bool name(); | ||
| 105 | |||
| 106 | char getEscape(); | ||
| 107 | |||
| 108 | /** | ||
| 109 | * Automoton function: paramlist. Processes a list of node params. | ||
| 110 | *@returns True if everything was ok, False for end of stream. | ||
| 111 | */ | ||
| 112 | bool paramlist(); | ||
| 113 | |||
| 114 | /** | ||
| 115 | * Automoton function: param. Processes a single parameter. | ||
| 116 | *@returns True if everything was ok, False for end of stream. | ||
| 117 | */ | ||
| 118 | bool param(); | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Automoton function: content. Processes node content. | ||
| 122 | *@returns True if everything was ok, False for end of stream. | ||
| 123 | */ | ||
| 124 | bool content(); | ||
| 125 | |||
| 126 | FlexBuf fbContent; /**< buffer for the current node's content. */ | ||
| 127 | FlexBuf fbParamName; /**< buffer for the current param's name. */ | ||
| 128 | FlexBuf fbParamValue; /**< buffer for the current param's value. */ | ||
| 129 | bool bStrip; /**< Are we stripping whitespace? */ | ||
| 130 | int nError; /**< Is there an error? */ | ||
| 131 | }; | ||
| 132 | |||
| 133 | #endif | ||
