00001 /* 00002 * $Revision: 2299 $ 00003 * 00004 * last checkin: 00005 * $Author: gutwenger $ 00006 * $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 00007 ***************************************************************/ 00008 00043 #ifdef _MSC_VER 00044 #pragma once 00045 #endif 00046 00047 #ifndef OGDF_DINO_XML_SCANNER_H 00048 #define OGDF_DINO_XML_SCANNER_H 00049 00050 #include <ogdf/fileformats/DinoLineBuffer.h> 00051 00052 namespace ogdf { 00053 00054 //--------------------------------------------------------- 00055 // X m l T o k e n 00056 //--------------------------------------------------------- 00061 enum XmlToken { 00062 openingBracket, 00063 closingBracket, 00064 questionMark, 00065 exclamationMark, 00066 minus, 00067 slash, 00068 equalSign, 00069 identifier, 00070 attributeValue, 00071 quotedValue, 00072 endOfFile, 00073 invalidToken, 00074 noToken 00075 00076 }; // enum XmlToken 00077 00078 00079 //--------------------------------------------------------- 00080 // D i n o X m l S c a n n e r 00081 //--------------------------------------------------------- 00085 class OGDF_EXPORT DinoXmlScanner { 00086 00087 private: 00088 00089 // Pointer to the line buffer 00090 DinoLineBuffer *m_pLineBuffer; 00091 00092 // String which contains the characters of the current token 00093 // Its size is limited to DinoLineBuffer::c_maxStringLength 00094 char *m_pCurrentTokenString; 00095 00096 public: 00097 // construction 00098 DinoXmlScanner(const char *fileName); 00099 00100 // destruction: destroys the parse tree 00101 ~DinoXmlScanner(); 00102 00103 // This function represents the core of the scanner. It scans the input 00104 // and returns the identified token. After performing getNextToken() the 00105 // token is "consumed", i.e. the line buffer pointer already points to the 00106 // next token. 00107 // The scanned string is deposited in m_pCurrentTokenString, hence it is 00108 // available via getCurrentTokenString() 00109 XmlToken getNextToken(); 00110 00111 // Returns the current token string 00112 inline const char *getCurrentTokenString(){ 00113 return m_pCurrentTokenString; 00114 } 00115 00116 // This function provides a lookahead to the next token; 00117 // the token is NOT consumed like it is the case for getNextToken() 00118 XmlToken testNextToken(); 00119 00120 // This function provides a lookahead to the nextnext token; 00121 // the tokens are NOT consumed like it is the case for getNextToken() 00122 XmlToken testNextNextToken(); 00123 00124 // Skips until the searchCharacter is found; 00125 // 00126 // If skipOverSearchCharacter is set true the currentPosition will be set 00127 // BEHIND the search character 00128 // otherwise the pointer currentPosition points TO the searchCharacter 00129 // 00130 // Returns true if the searchCharacter is found 00131 // Returns false if file ends before the searchCharacter is found 00132 bool skipUntil(char searchCharacter, bool skipOverSearchCharacter = true); 00133 00134 // Skips until '>' is found (> is consumed) 00135 // Nested brackets are taken into account 00136 // Returns true if matching bracket has been found; false otherwise 00137 bool skipUntilMatchingClosingBracket(); 00138 00139 // Reads until the searchCharacter is found; the string starting at the current 00140 // position and ending at the position where the search character is found 00141 // is deposited in m_pCurrentTokenString. 00142 // If includeSearchCharacter is false (default) the search character is 00143 // not contained; otherwise it is contained 00144 // 00145 // Returns true if the searchCharacter is found 00146 // Returns false if file ends before the searchCharacter is found 00147 bool readStringUntil(char searchCharacter, bool includeSearchCharacter = false); 00148 00149 // Returns line number of the most recently read line of the input file 00150 inline int getInputFileLineCounter() const { 00151 return m_pLineBuffer->getInputFileLineCounter(); 00152 } 00153 00154 // This function tests the scanner by reading the complete 00155 // input file and printing the identified token to stdout 00156 void test(); 00157 00158 }; // class DinoXmlScanner 00159 00160 } // end namespace ogdf 00161 00162 #endif