00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef XANACONFIGPARSER_H
00011 #define XANACONFIGPARSER_H
00012
00013 #include "XANADOO/XANAConfig/interface/XANAConfigFileLine.h"
00014 #include "TROOT.h"
00015 #include "TObject.h"
00016
00017 #include <stdio.h>
00018 #include <stdexcept>
00019 #include <vector>
00020 #include <iostream>
00021
00022 class XANAConfigParser: public TObject {
00023 public:
00024
00025
00026 FILE *config_file;
00027
00028
00029 XANAConfigParser();
00030
00031
00032 bool init(const char *fileName=0);
00033
00034
00035 virtual ~XANAConfigParser();
00036
00037
00038 void appendLine(XANAConfigFileLine *line);
00039
00040
00041 bool deleteLine(const char *name, const char *scope=0);
00042
00043
00044 bool overrideOption(const char *name, std::list<std::string> &values,
00045 const char *scope=0);
00046
00047
00048 bool isDefined(const char *name) const;
00049
00050
00051 int readIntOption(const char *name) const throw(const char *);
00052
00053
00054 double readDoubleOption(const char *name) const throw(const char *);
00055
00056
00057 const char *readStringOption(const char *name) const throw(const char *);
00058
00059
00060 std::vector<int> readIntListOption(const char *name) const throw(const char *);
00061
00062
00063 std::vector<double> readDoubleListOption(const char *name)
00064 const throw(const char *);
00065
00066
00067 const std::list<std::string> readStringListOption(const char *name)
00068 const throw(const char *);
00069
00070
00071
00072
00073
00075 int getOptionListSize(const char *name) const{
00076 std::string s(name);
00077 LineIterator I=configLines.begin();
00078 while (I != configLines.end()) {
00079 if((*I)->isOption(s)){
00080 return (*I)->getValues().size();
00081 }
00082 I++;
00083 }
00084 return 0;
00085 }
00086
00087
00092 bool readIntOption(const char *name, int &value, int entry=0) const{
00093 value=0;
00094 if(entry>=getOptionListSize(name)) return false;
00095 value=readIntListOption(name)[entry];
00096 return true;
00097 }
00098
00099
00104 bool readDoubleOption(const char *name, double &value, int entry=0) const{
00105 value=0;
00106 if(entry>=getOptionListSize(name)) return false;
00107 value=readDoubleListOption(name)[entry];
00108 return true;
00109 }
00110
00111
00117 bool readStringOption(const char *name, const char *value, int entry=0)const{
00118 if(entry>=getOptionListSize(name)) return false;
00119 const std::list<std::string> l=readStringListOption(name);
00120 std::list<std::string>::const_iterator I=l.begin();
00121 for(int i=0; i<entry; i++) I++;
00122 strcpy(value, (const char *)((*I).c_str()));
00123 return true;
00124 }
00125
00126
00127 void print() const;
00128
00129 private:
00130
00131 std::list<XANAConfigFileLine *> configLines;
00132
00135 typedef std::list<XANAConfigFileLine *>::const_iterator LineIterator;
00136
00137 ClassDef(XANAConfigParser,0)
00138
00139 };
00140
00141
00142
00143 R__EXTERN XANAConfigParser *gConfigParser;
00144
00145 #endif // #ifndef XANACONFIGPARSER_H