Open
Graph Drawing
Framework

 v.2010.10
 

DinoXmlScanner.h

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