Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

ConfFile.h

Go to the documentation of this file.
00001 00002 #ifndef CONF_FILE_H 00003 #define CONF_FILE_H 00004 00005 #include "xercesDomUtil.h" 00006 00007 BOREALIS_NAMESPACE_BEGIN; 00008 00009 class ConfFile { 00010 public: 00011 ConfFile(); 00012 00013 ConfFile(string file) 00014 throw (AuroraException); 00015 00016 const DOMElement *getModuleTag(string module_name, 00017 XmlAttrReq req = ATTR_NOT_REQUIRED) const 00018 throw (AuroraBadEntityException); 00019 00020 string getParameter(string module_name, string name, 00021 XmlAttrReq req = ATTR_NOT_REQUIRED) const 00022 throw (AuroraBadEntityException); 00023 00024 string getParameter(string module_name, string name, string def) const 00025 throw (AuroraBadEntityException); 00026 00027 template <typename T> 00028 bool getTypedParameter(string module_name, string name, T& value, 00029 XmlAttrReq req = ATTR_NOT_REQUIRED) const 00030 throw (AuroraBadEntityException); 00031 00032 private: 00033 typedef map<string, const DOMElement *> ModuleParams; 00034 00035 struct ModuleInfo { 00036 const DOMElement * _elt; 00037 ModuleParams _params; 00038 }; 00039 00040 typedef map<string, ptr<ModuleInfo> > ModuleMap; 00041 00042 ptr<DOMDocument> _doc; 00043 ModuleMap _modules; 00044 00045 const ModuleInfo *ConfFile::getModuleInfo(string module_name, 00046 XmlAttrReq req = ATTR_NOT_REQUIRED) const 00047 throw (AuroraBadEntityException); 00048 }; 00049 00050 template <typename T> 00051 bool ConfFile::getTypedParameter(string module_name, string name, T& value, 00052 XmlAttrReq req) const 00053 throw (AuroraBadEntityException) 00054 { 00055 const ModuleInfo *info = getModuleInfo(module_name, req); 00056 if (!info) { 00057 if (req != ATTR_NOT_REQUIRED) 00058 Throw(AuroraBadEntityException, 00059 "Missing module configuration for " + module_name); 00060 return false; 00061 } 00062 00063 ModuleParams::const_iterator i = info->_params.find(name); 00064 if (i == info->_params.end()) { 00065 if (req != ATTR_NOT_REQUIRED) 00066 Throw(AuroraBadEntityException, 00067 "Missing \"" + name + "\" parameter in module " + module_name); 00068 00069 return false; 00070 } 00071 00072 return xmlTypedAttribute(i->second, "value", value, ATTR_REQUIRED); 00073 } 00074 00075 BOREALIS_NAMESPACE_END; 00076 00077 #endif

Generated on Fri Nov 12 15:15:20 2004 for Borealis by doxygen 1.3.8