Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Parser.h
Go to the documentation of this file.
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 
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  std::shared_ptr<StringParameters> getParameters( const std::string& sectionName ) const ;
49 
52  throw ParseException( "dynamic command line options only supported for xml steering files" ) ;
53  }
54 
55 
58  void parse() ;
59 
61  void write(const std::string& fname) const ;
62 
63 
64 protected:
65 
69  int readNextValidLine( std::string& str , std::istream& stream) ;
70 
71 
74 
76 
77 private:
78  Parser() = delete;
79  Parser(const marlin::Parser&) = delete;
80  Parser& operator=(const marlin::Parser&) = delete;
81 
82 };
83 
84 
85 
86 
87 
91 
93  char _del ;
94  char _last ;
95  size_t _max ;
96  public:
97 
98  LCTokenizer( std::vector< std::string >& tokens, char del, size_t max=-1 ) : _tokens(tokens) , _del(del), _last(del), _max(max) {
99  }
100 
101 
102  void operator()(const char& c) {
103 
104  if( c != _del or _tokens.size() >= _max ) {
105 
106  if( _last == _del and _tokens.size() < _max ) {
107  _tokens.push_back("") ;
108  }
109  _tokens.back() += c ;
110  result() ;
111  }
112  _last = c ;
113 
114  }
115 
117  }
118 
120 
121  return _tokens ;
122 
123  }
124 };
125 
126 
127 } // end namespace marlin
128 #endif
std::shared_ptr< StringParameters > getParameters(const std::string &sectionName) const
Return the StringParameters defined for this section of the steering file.
Definition: Parser.cc:113
std::string _fileName
Definition: Parser.h:75
ParseException used for parse errors, e.g.
Definition: Exceptions.h:16
Parser()=delete
Interface for a parser of a steering file to be used with marlin.
Definition: IParser.h:19
STL class.
STL class.
virtual ~Parser()
Definition: Parser.cc:12
Simple parser class for Marlin.
Definition: Parser.h:36
STL class.
void setCmdLineParameters(const CommandLineParametersMap &)
set command line parameters
Definition: Parser.h:51
T push_back(T...args)
Helper class for Parser.
Definition: Parser.h:90
std::map< std::string, std::shared_ptr< StringParameters > > StringParametersMap
Definition: Parser.h:15
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 &#39;#&#39;...
Definition: Parser.cc:132
std::vector< std::string > & _tokens
Definition: Parser.h:92
StringParametersMap _map
Definition: Parser.h:72
T size(T...args)
void parse()
Parse the input file.
Definition: Parser.cc:16
Parser & operator=(const marlin::Parser &)=delete
void write(const std::string &fname) const
Write down the parsed file in a new file.
Definition: Parser.cc:163
T back(T...args)
LCTokenizer(std::vector< std::string > &tokens, char del, size_t max=-1)
Definition: Parser.h:98
void operator()(const char &c)
Definition: Parser.h:102
StringParameters * _current
Definition: Parser.h:73
Simple parameters class for Marlin.
std::vector< std::string > & result()
Definition: Parser.h:119