AmpTools
ConfigFileParser.h
Go to the documentation of this file.
1 //******************************************************************************
2 // This file is part of AmpTools, a package for performing Amplitude Analysis
3 //
4 // Copyright Trustees of Indiana University 2010, all rights reserved
5 //
6 // This software written by Matthew Shepherd, Ryan Mitchell, and
7 // Hrayr Matevosyan at Indiana University, Bloomington
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
11 // are met:
12 // 1. Redistributions of source code must retain the above copyright
13 // notice and author attribution, this list of conditions and the
14 // following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright
16 // notice and author attribution, this list of conditions and the
17 // following disclaimer in the documentation and/or other materials
18 // provided with the distribution.
19 // 3. Neither the name of the University nor the names of its contributors
20 // may be used to endorse or promote products derived from this software
21 // without specific prior written permission.
22 //
23 // Creation of derivative forms of this software for commercial
24 // utilization may be subject to restriction; written permission may be
25 // obtained from the Trustees of Indiana University.
26 //
27 // INDIANA UNIVERSITY AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES,
28 // EXPRESS OR IMPLIED. By way of example, but not limitation, INDIANA
29 // UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCANTABILITY OR
30 // FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS SOFTWARE OR
31 // DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS,
32 // OR OTHER RIGHTS. Neither Indiana University nor the authors shall be
33 // held liable for any liability with respect to any claim by the user or
34 // any other party arising from use of the program.
35 //******************************************************************************
36 
37 
88 #if !defined(CONFIGFILEPARSER)
89 #define CONFIGFILEPARSER
90 
91 #include <utility>
92 #include <string>
93 #include <vector>
94 #include <map>
95 #include <set>
96 #include <complex>
98 
99 using namespace std;
100 
101 class ConfigFileLine;
102 
103 
105 {
106 
107  public:
108 
114 
115 
120  ConfigFileParser(const string& configFile);
121 
122 
127  ConfigFileParser(istream& input);
128 
129 
136  void readConfigFile(const string& configFile);
137 
138 
145  void readConfigFile(istream& input);
146 
147 
153 
154 
159  ConfigurationInfo* getConfigurationInfo() {return m_configurationInfo;}
160 
161 
167  const vector<ConfigFileLine>& getConfigFileLines() const {return m_configFileLines;}
168 
169 
174  void displayConfigFile() const;
175 
176 
181  static void setVerboseParsing(bool verboseParsing = false)
182  {m_verboseParsing = verboseParsing;}
183 
184 
185 
186  private:
187 
188 
189  // read from a given file
190 
191  vector<ConfigFileLine> readConfigFileLines(const string& configFile) const;
192 
193 
194  // read from a stream
195 
196  vector<ConfigFileLine> readConfigFileLines(istream& input) const;
197 
198 
199  // expand the "include" and "define" statements
200 
201  vector<ConfigFileLine> expandConfigFileLines(vector<ConfigFileLine> configFileLines) const;
202 
203 
204  // set up the ConfigurationInfo object
205 
206  void setupConfigurationInfo();
207 
208 
209  // Do checks on the syntax, check keywords, etc.
210 
211  void checkSyntax() const;
212 
213 
214  // Do the setup for each keyword
215 
216  void doFit (const ConfigFileLine& line);
217  void doKeyword (const ConfigFileLine& line);
218  void doReaction (const ConfigFileLine& line);
219  void doParameter (const ConfigFileLine& line);
220  void doData (const ConfigFileLine& line);
221  void doNormInt (const ConfigFileLine& line);
222  void doSum (const ConfigFileLine& line);
223  void doAmplitude (const ConfigFileLine& line);
224  void doInitialize (const ConfigFileLine& line);
225  void doPermute (const ConfigFileLine& line);
226  void doConstrain (const ConfigFileLine& line);
227  void doScale (const ConfigFileLine& line);
228 
229 
230  // Member data
231 
232  string m_fitName;
233  string m_configFile;
234  set<string> m_userKeywords;
235  static bool m_verboseParsing;
236  vector<ConfigFileLine> m_configFileLines;
237  ConfigurationInfo* m_configurationInfo;
238 
239 
240 };
241 
242 
243 inline istream& operator>>( istream& input, ConfigFileParser& parser ){
244  parser.readConfigFile( input ); return input;
245 }
246 
247 
260 {
261 
262  public:
263 
264  ConfigFileLine(const string& fileName, int lineNumber, const string& line);
265 
266  string line() const {return m_line;}
267  string fileName() const {return m_fileName;}
268  int lineNumber() const {return m_lineNumber;}
269  string keyword() const {return m_keyword;}
270  vector<string> arguments() const {return m_arguments;}
271  bool comment() const {return m_comment;}
272 
273  void printLine() const {cout << "(" << m_lineNumber << ") " <<
274  m_fileName << " >> " <<
275  m_line << endl;}
276 
277  void printArguments() const {cout << "KEYWORD: " << m_keyword << endl;
278  cout << "ARGUMENTS: " << endl;
279  for ( unsigned int i = 0; i < m_arguments.size(); i++){
280  cout << m_arguments[i] << endl;}}
281 
282  void flushDefinition(const string& word, const vector<string>& definition);
283 
284  private:
285 
286  string m_line;
287  string m_fileName;
288  int m_lineNumber;
289  string m_keyword;
290  vector<string> m_arguments;
291  bool m_comment;
292 
293 };
294 
295 
296 #endif
ConfigurationInfo * getConfigurationInfo()
string fileName() const
void readConfigFile(const string &configFile)
int lineNumber() const
string line() const
bool comment() const
static void setVerboseParsing(bool verboseParsing=false)
string keyword() const
const vector< ConfigFileLine > & getConfigFileLines() const
void printArguments() const
istream & operator>>(istream &input, ConfigFileParser &parser)
vector< string > arguments() const
void printLine() const