Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

XMLParser.h

00001 #ifndef XMLParser_h
00002 #define XMLParser_h 1
00003 
00004 #include "IParser.h"
00005 #include "StringParameters.h"
00006 
00007 #include <fstream>
00008 #include <string>
00009 #include <iostream>
00010 
00011 class TiXmlNode ;
00012 class TiXmlDocument ;
00013 
00014 namespace marlin{
00015 
00016   typedef std::map< std::string ,  StringParameters* > StringParametersMap ;
00017 
00104   class XMLParser : public IParser {
00105   
00106 
00107   public:
00108 
00109 
00112     class LCTokenizer{
00113 
00114       std::vector< std::string >& _tokens ;
00115       char _del ;
00116       char _last ;
00117     public:
00118 
00119       LCTokenizer( std::vector< std::string >& tokens, char del ) : _tokens(tokens) , _del(del), _last(del) {
00120       }
00121 
00122 
00123       void operator()(const char& c) { 
00124 
00125         if( c != _del  ) {
00126 
00127           if( _last == _del  ) {
00128             _tokens.push_back("") ; 
00129           }
00130           _tokens.back() += c ;
00131           result() ;
00132         }
00133         _last = c ;
00134 
00135       } 
00136 
00137       ~LCTokenizer(){
00138       }
00139   
00140       std::vector<std::string> & result()  { 
00141     
00142         return _tokens ; 
00143     
00144       }
00145     };
00146   
00147 
00148     XMLParser( const std::string& fileName, bool forCCheck=false ) ;
00149     virtual ~XMLParser() ; 
00150 
00151 
00153     void parse() ;
00154 
00156     StringParameters* getParameters( const std::string& sectionName ) const ;
00157   
00158 
00159   protected:
00160 
00163     void parametersFromNode(TiXmlNode* section, std::pair<unsigned,unsigned>* typeCount=0) ;
00164 
00166     const char* getAttribute( TiXmlNode* node , const std::string& name ) ;
00167 
00170     void replacegroups(TiXmlNode* section) ;
00171     
00173     TiXmlNode* findElement( TiXmlNode* node , const std::string& type, 
00174                             const std::string& attribute, const std::string& value ) ;
00175 
00176 
00180     void processconditions( TiXmlNode* current , const std::string& conditions ) ;
00181 
00182 
00183     mutable StringParametersMap _map ;
00184     StringParameters* _current ;
00185     TiXmlDocument* _doc ;
00186 
00187     std::string _fileName ;
00188 
00189   private:
00190     XMLParser() ;
00191     bool _forCCheck; //boolean variable set to true if parser is used for consistency checking
00192 
00193   };
00194 
00195 } // end namespace marlin 
00196 #endif
00197 

Generated on Mon Jan 12 09:48:52 2009 for Marlin by doxygen 1.3.5