Luiza  v03-01
XMLParser.h
1 #ifndef XMLParser_h
2 #define XMLParser_h 1
3 
4 #include "IParser.h"
5 #include "StringParameters.h"
6 
7 #include <fstream>
8 #include <string>
9 #include <iostream>
10 
11 class TiXmlNode ;
12 class TiXmlDocument ;
13 
14 namespace luiza{
15 
16  typedef std::map< std::string , StringParameters* > StringParametersMap ;
17 
104  class XMLParser : public IParser {
105 
106 
107  public:
108 
109 
112  class LCTokenizer{
113 
114  std::vector< std::string >& _tokens ;
115  char _del ;
116  char _last ;
117  public:
118 
119  LCTokenizer( std::vector< std::string >& tokens, char del ) : _tokens(tokens) , _del(del), _last(del) {
120  }
121 
122 
123  void operator()(const char& c) {
124 
125  if( c != _del ) {
126 
127  if( _last == _del ) {
128  _tokens.push_back("") ;
129  }
130  _tokens.back() += c ;
131  result() ;
132  }
133  _last = c ;
134 
135  }
136 
137  ~LCTokenizer(){
138  }
139 
140  std::vector<std::string> & result() {
141 
142  return _tokens ;
143 
144  }
145  };
146 
147 
148  XMLParser( const std::string& fileName, bool forCCheck=false ) ;
149  virtual ~XMLParser() ;
150 
152  void setCmdLineParameters( const CommandLineParametersMap & cmdlineparams ){
153  _cmdlineparams = cmdlineparams ;
154  }
155 
157  void parse() ;
158 
160  StringParameters* getParameters( const std::string& sectionName ) const ;
161 
162 
163  protected:
164 
167  void parametersFromNode(TiXmlNode* section, std::pair<unsigned,unsigned>* typeCount=0) ;
168 
170  const char* getAttribute( TiXmlNode* node , const std::string& name ) ;
171 
174  void replacegroups(TiXmlNode* section) ;
175 
177  TiXmlNode* findElement( TiXmlNode* node , const std::string& type,
178  const std::string& attribute, const std::string& value ) ;
179 
180 
184  void processconditions( TiXmlNode* current , const std::string& conditions ) ;
185 
186 
187  mutable StringParametersMap _map ;
188  StringParameters* _current ;
189  TiXmlDocument* _doc ;
190 
191  std::string _fileName ;
192 
193  private:
194  XMLParser() ;
195  bool _forCCheck; //boolean variable set to true if parser is used for consistency checking
196 
197  CommandLineParametersMap _cmdlineparams ;
198 
199  };
200 
201 } // end namespace marlin
202 #endif
203 
void parse()
Definition: XMLParser.cc:23
Definition: IParser.h:18
void setCmdLineParameters(const CommandLineParametersMap &cmdlineparams)
Definition: XMLParser.h:152
Definition: XMLParser.h:104
StringParameters * getParameters(const std::string &sectionName) const
Definition: XMLParser.cc:378
Definition: XMLParser.h:112
Definition: tinyxml.h:1366
const char * getAttribute(TiXmlNode *node, const std::string &name)
Definition: XMLParser.cc:247
void parametersFromNode(TiXmlNode *section, std::pair< unsigned, unsigned > *typeCount=0)
Definition: XMLParser.cc:268
void replacegroups(TiXmlNode *section)
Definition: XMLParser.cc:450
TiXmlNode * findElement(TiXmlNode *node, const std::string &type, const std::string &attribute, const std::string &value)
Definition: XMLParser.cc:496
Namespace for Luiza framework.
Definition: CCCollection.h:6
Definition: tinyxml.h:425
void processconditions(TiXmlNode *current, const std::string &conditions)
Definition: XMLParser.cc:391