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 
00152     void setCmdLineParameters( const CommandLineParametersMap & cmdlineparams ){
00153         _cmdlineparams = cmdlineparams ;
00154     }
00155 
00157     void parse() ;
00158 
00160     StringParameters* getParameters( const std::string& sectionName ) const ;
00161   
00162 
00163   protected:
00164 
00167     void parametersFromNode(TiXmlNode* section, std::pair<unsigned,unsigned>* typeCount=0) ;
00168 
00170     const char* getAttribute( TiXmlNode* node , const std::string& name ) ;
00171 
00174     void replacegroups(TiXmlNode* section) ;
00175     
00177     TiXmlNode* findElement( TiXmlNode* node , const std::string& type, 
00178                             const std::string& attribute, const std::string& value ) ;
00179 
00180 
00184     void processconditions( TiXmlNode* current , const std::string& conditions ) ;
00185 
00186 
00187     mutable StringParametersMap _map ;
00188     StringParameters* _current ;
00189     TiXmlDocument* _doc ;
00190 
00191     std::string _fileName ;
00192 
00193   private:
00194     XMLParser() ;
00195     bool _forCCheck; //boolean variable set to true if parser is used for consistency checking
00196 
00197     CommandLineParametersMap _cmdlineparams ;
00198 
00199   };
00200 
00201 } // end namespace marlin 
00202 #endif
00203 

Generated on Fri Mar 30 11:17:32 2012 for Marlin by  doxygen 1.4.7