00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ModulesConf_h
00012 #define ModulesConf_h
00013
00014 #include <string>
00015 #include <list>
00016 #include <map>
00017
00018 using std::string;
00019 using std::list;
00020 using std::map;
00021
00022 #define MAX_LINE_LENGTH 256
00023 #define WHITESPACE " \t\n"
00024
00025 #define MAGIC_ENTRY "Ctrl and Alt keys stuck -- press Del to continue."
00026
00036 class ModuleEntry {
00037
00038 public:
00039
00040 enum Mode { INIT, SET, REINIT };
00041 typedef map <const string, string> EntryArg;
00042 typedef string EntryCom;
00043
00047 ModuleEntry() : comment(), argument(), dirtyflag(false) {}
00048
00052 ~ModuleEntry();
00053
00058 EntryCom getComment() const;
00063 EntryArg getArgument() const { return argument; }
00070 bool setComment(const EntryCom &com, Mode m) { comment = com; return true; }
00077 bool setArgument(const string arg, Mode m);
00085 bool setOption(const string option, const string value, Mode m);
00092 bool setOptions(const EntryArg &arg, Mode m);
00093
00102 bool Set(Mode m);
00103
00104 private:
00105 EntryCom comment;
00106 EntryArg argument;
00107 bool dirtyflag;
00108
00109 };
00110
00120 class ModulesConf {
00121
00122 public:
00123 typedef list<string> ModulesConfIndex;
00124 typedef map<const string, ModuleEntry> ModuleEntryMap;
00125 typedef map<const string, ModuleEntryMap> ModulesConfMap;
00126
00131 ModulesConf(const string &fname);
00135 ~ModulesConf();
00136
00141 ModulesConfMap getDirectives();
00147 ModuleEntryMap getModules(const string directive);
00153 ModuleEntry::EntryArg getOptions(const string module);
00159 string getOptionsAsString (const string module);
00166 string getOption(const string module, const string option);
00173 string getArgument(const string directive, const string module);
00180 string getComment(const string directive, const string module);
00181
00189 bool setOption(const string module, const string option, const string value, ModuleEntry::Mode m);
00197 bool setOptions(const string module, const ModuleEntry::EntryArg arg, ModuleEntry::Mode m);
00206 bool setArgument(const string directive, const string module, const string arg, ModuleEntry::Mode m);
00215 bool setComment(const string directive, const string module, const string arg, ModuleEntry::Mode m);
00216
00224 bool removeEntry(const string directive, const string module);
00225
00231 bool writeFile(const string fname = "");
00232
00233 private:
00234 string file_name;
00235 ModulesConfMap modules_conf_map;
00236 ModulesConfIndex modules_conf_index;
00237
00238 bool modified;
00239
00240 struct ModuleLine {
00241 string directive;
00242 string module;
00243 string argument;
00244 ModuleEntry::EntryArg options;
00245 string comment;
00246 };
00247
00251 typedef time_t TimeStamp;
00257 TimeStamp getTimeStamp(const string &fname);
00258
00259 TimeStamp time_stamp;
00260
00266 bool isDirective(const string directive) const;
00273 bool isModule(const string directive, const string module);
00280 bool isOption(const string module, const string option);
00281
00286 bool updateIfModified();
00291 bool updateTimeStamp();
00298 bool updateIndex(const string directive, const string module);
00305 bool parseLine(const string &line, ModuleLine &l) const;
00313 bool parseFile(const string &file_name, ModuleEntry::Mode m, const bool with_comment = true);
00314
00315 };
00316
00317
00318 #endif