Marlin  1.10.0
 All Classes Namespaces Functions Variables Enumerations Friends Pages
Parser.h
1 #ifndef Parser_h
2 #define Parser_h 1
3 
4 //#include "lcio.h"
5 #include "IParser.h"
6 #include "StringParameters.h"
7 #include "marlin/Exceptions.h"
8 
9 #include <fstream>
10 #include <string>
11 #include <iostream>
12 
13 namespace marlin{
14 
15 class LCTokenizer ;
16 
17 
18 typedef std::map< std::string , StringParameters* > StringParametersMap ;
19 
20 
36 class Parser : public IParser {
37 
38 
39 public:
40 
41 
42  // Parser(const std::string[] & namespaces ) ;
43  // void parse( const std::string& fileName )
44 
45  Parser( const std::string& fileName ) ;
46  virtual ~Parser() ;
47 
48  StringParameters* getParameters( const std::string& sectionName ) const ;
49 
51  void setCmdLineParameters( const CommandLineParametersMap & ){
52  throw ParseException( "dynamic command line options only supported for xml steering files" ) ;
53  }
54 
55 
58  void parse() ;
59 
60 
61 protected:
62 
66  int readNextValidLine( std::string& str , std::istream& stream) ;
67 
68 
69  mutable StringParametersMap _map ;
70  StringParameters* _current ;
71 
72  std::string _fileName ;
73 
74 private:
75  Parser() ;
76 
77 };
78 
79 
80 
81 
82 
86 
87  std::vector< std::string >& _tokens ;
88  char _del ;
89  char _last ;
90  public:
91 
92  LCTokenizer( std::vector< std::string >& tokens, char del ) : _tokens(tokens) , _del(del), _last(del) {
93  }
94 
95 
96  void operator()(const char& c) {
97 
98  if( c != _del ) {
99 
100  if( _last == _del ) {
101  _tokens.push_back("") ;
102  }
103  _tokens.back() += c ;
104  result() ;
105  }
106  _last = c ;
107 
108  }
109 
110  ~LCTokenizer(){
111  }
112 
113  std::vector<std::string> & result() {
114 
115  return _tokens ;
116 
117  }
118 };
119 
120 
121 } // end namespace marlin
122 #endif
ParseException used for parse errors, e.g.
Definition: Exceptions.h:16
Interface for a parser of a steering file to be used with marlin.
Definition: IParser.h:18
Simple parser class for Marlin.
Definition: Parser.h:36
void setCmdLineParameters(const CommandLineParametersMap &)
set command line parameters
Definition: Parser.h:51
Helper class for Parser.
Definition: Parser.h:85
int readNextValidLine(std::string &str, std::istream &stream)
Helper method that reads the next line from a stream that is not empty or starts with a '#'...
Definition: Parser.cc:132
void parse()
Parse the input file.
Definition: Parser.cc:16
StringParameters * getParameters(const std::string &sectionName) const
Return the StringParameters defined for this section of the steering file.
Definition: Parser.cc:113
Simple parameters class for Marlin.
Definition: StringParameters.h:34