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

Params.h

Go to the documentation of this file.
00001 00002 #ifndef PARAMS_H 00003 #define PARAMS_H 00004 00005 #include "Exceptions.h" 00006 #include "xercesDomUtil.h" 00007 00008 BOREALIS_NAMESPACE_BEGIN; 00009 00011 class Params { 00012 public: 00013 enum Req { 00014 NOT_REQUIRED, 00015 REQUIRED, 00016 NON_EMPTY 00017 }; 00018 00019 Params() {} 00020 explicit Params(const DOMElement *elt) throw (AuroraBadEntityException) { addFromXml(elt); } 00021 void addFromXml(const DOMElement *elt) throw (AuroraBadEntityException); 00022 00024 bool empty() const { return _params.empty(); } 00025 00029 string param(string name, Req req = NOT_REQUIRED) const 00030 throw (AuroraBadEntityException); 00031 00034 string param(string name, string def) const; 00035 00043 template <typename T> 00044 bool typedParam(string name, T& value, Req req = NOT_REQUIRED) const 00045 throw (AuroraBadEntityException) 00046 { 00047 map<string, string>::const_iterator i = _params.find(name); 00048 00049 if (i == _params.end()) { 00050 if (req != NOT_REQUIRED) { 00051 Throw(AuroraBadEntityException, 00052 "Missing required attribute \"" + name + "\""); 00053 } 00054 return false; 00055 } 00056 00057 // It's provided; coerce it 00058 istringstream iss(i->second); 00059 if (iss >> value) 00060 return true; 00061 00062 Throw(AuroraBadEntityException, 00063 "Invalid format for parameter named \"" + name + "\": \"" + 00064 to_escaped_string(i->second) + "\""); 00065 } 00066 00068 string as_string() const { return "Params" + to_string(_params); } 00069 00070 private: 00071 map<string, string> _params; 00072 }; 00073 00074 BOREALIS_NAMESPACE_END; 00075 00076 #endif

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