00001 #ifndef MODULESREADER__HH_
00002 #define MODULESREADER__HH_
00003 #include <string>
00004 #include <fstream>
00005 #include <vector>
00006 #include <iostream>
00007
00008
00009 #include "ModulesOptions.h"
00010
00011 namespace modules{
00012 class reader;
00013 }
00014
00015 class modules::reader{
00016
00017
00018 typedef std::vector<std::string> OptionsList;
00019 typedef std::map<std::string,modules::options* > SectionsList;
00020 typedef std::vector<std::pair<std::string, modules::options*> > ModuleList;
00021 typedef std::map<std::string,int > ModuleCounts;
00022 enum OptionMode_t { kSet , kAppend };
00023 struct Option_t {
00024 OptionMode_t mode;
00025 std::string key;
00026 std::string value;
00027 };
00028
00029 public:
00030
00031 reader():fShouldPrint(false),fDebugAll(false),fDumpContents(false),fDumpInputFile(false){};
00032
00033
00034 virtual ~reader(){};
00035
00036 public:
00037 int ReadFile(const char* name);
00038 void PrintAllOptions()const;
00039 int HowMany(const std::string& name)const;
00040 bool DumpInputFile()const {return fDumpInputFile;}
00041
00042 size_t GetNumModules()const{return fModules.size();};
00043 std::string GetModule(unsigned int i)const{return fModules[i].first;};
00044 modules::options* GetOptions(unsigned int i)const{return fModules[i].second;};
00045 void SetDebug();
00046 void SetDebugAll();
00047
00048 private:
00049 int OpenFile(const char* name, std::ifstream& infile);
00050 bool AddSection(const std::string& name,const std::string& type="");
00051 int AddModule(std::string line);
00052 void ProcessGlobalOption(Option_t opt);
00053 void AddOption(const std::string& module, const Option_t& opt){ AddOption(fAllOptions[module],opt); }
00054 void AddOption(const std::string& module, const std::string& flag){ AddOption(fAllOptions[module],flag); }
00055 void AddOption(modules::options* module, const Option_t& opt);
00056 void AddOption(modules::options* module, const std::string& flag);
00057 void AddOptionAll(const std::string& key,const std::string& value="");
00058 void AddOptionAll(const Option_t& opt);
00059
00060 Option_t SplitOption(const std::string& line);
00061 int MakeModules(const SectionsList&);
00062 bool isComment( std::stringstream& line);
00063 std::string findSectionName(const std::string& line);
00064 std::ostream& PrintProblem();
00065
00066 private:
00067 SectionsList fAllOptions;
00068 ModuleList fModules;
00069 ModuleCounts fModulesCounts;
00070 static const char* fGlobalModule;
00071 int fLineNumber;
00072 bool fShouldPrint;
00073 bool fDebugAll;
00074 bool fDumpContents;
00075 bool fDumpInputFile;
00076 };
00077
00078 inline bool modules::reader::AddSection(const std::string& name,const std::string& type){
00079 if(fAllOptions.find(name)==fAllOptions.end()){
00080 fAllOptions[name] =new modules::options(type);
00081 return true;
00082 }
00083 return false;
00084 }
00085
00086 inline void modules::reader::AddOptionAll(const Option_t& opt){
00087 AddOptionAll(opt.key,opt.value);
00088 }
00089
00090 #endif // MODULESREADER__HH_