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

PropsFile.h

Go to the documentation of this file.
00001 #ifndef PROPSFILE_H 00002 #define PROPSFILE_H 00003 00004 #include <map> 00005 #include <string> 00006 #include <exception> 00007 #include <algorithm> 00008 #include <set> 00009 00010 #include "Exceptions.h" 00011 00012 BOREALIS_NAMESPACE_BEGIN; 00013 00051 class PropsFile 00052 { 00053 public: 00054 // Loads a particular properties file, and models it with an instance of this 00055 // class. 00056 PropsFile(string filepath) 00057 throw (AuroraException); 00058 00059 // Loads a particular properties file, and models it with an instance of this 00060 // class. 00061 // Then, all of the command-line arguments (supplied via argc/argv) that begin 00062 // with 'prefix' will be used to override existing entries in the PropsFile 00063 // or to add new entries in the PropsFile. 00064 // 00065 // Example: prefix = "-D", argc/v = "myprog -Dfoo:int=42 blah -Dcow:string=milk" 00066 // 00067 // In this case, regardless of what was given in the XML file, we know for 00068 // sure that this PropsFile will have at least the following two entries: 00069 // (int) foo = 42 00070 // (string) cow = milk 00071 // 00072 // An exception is thrown if any command line argument starting with the given 00073 // prefix is malformed, or if more than one cmd-line argument defines the 00074 // same property name. 00075 // 00076 // 'prefix' must not be the empty string, and argv[0] is ignored. 00077 PropsFile(string filepath, string prefix, int argc, const char* argv[]) 00078 throw (AuroraException); 00079 00080 virtual ~PropsFile(); 00081 00082 00083 //----------------------------------------------------------------------------- 00084 00085 // Returns the full property names and types of all string-properies whose 00086 // names begin with the substring 'prefix'. 00087 // 00088 // The key string in the map is the property's full name. 00089 // 00090 // The dependent value is one of the following values: 00091 // "bool", "int", "uint", "long", "ulong", "ulonglong", "double", "string" 00092 map<string, string> findPropsByPrefix(string prefix) const 00093 throw (AuroraException); 00094 00095 //----------------------------------------------------------------------------- 00096 00097 /* 00098 This methods throw an exception if the specified property isn't defined with 00099 the type indicated by the method. 00100 00101 If that's not acceptable, use the two-parameter versions, which return a default 00102 value when the property isn't defined. 00103 */ 00104 00105 bool getBool(string propName) const 00106 throw (AuroraException); 00107 00108 bool isBoolPropDefined(string propName) const 00109 throw (AuroraException); 00110 00111 bool getBoolWithDefault(string propName, bool defaultValue) const; 00112 00113 //----------------------------------------------------------------------------- 00114 00115 int getInt(string propName) const 00116 throw (AuroraException); 00117 00118 bool isIntPropDefined(string propName) const 00119 throw (AuroraException); 00120 00121 int getIntWithDefault(string propName, int defaultValue) const; 00122 00123 //----------------------------------------------------------------------------- 00124 00125 unsigned int getUInt(string propName) const 00126 throw (AuroraException); 00127 00128 bool isUIntPropDefined(string propName) const 00129 throw (AuroraException); 00130 00131 unsigned int getUIntWithDefault(string propName, unsigned int defaultValue) const; 00132 00133 //----------------------------------------------------------------------------- 00134 00135 long getLong(string propName) const 00136 throw (AuroraException); 00137 00138 bool isLongPropDefined(string propName) const 00139 throw (AuroraException); 00140 00141 long getLongWithDefault(string propName, long defaultValue) const; 00142 00143 //----------------------------------------------------------------------------- 00144 00145 unsigned long getULong(string propName) const 00146 throw (AuroraException); 00147 00148 bool isULongPropDefined(string propName) const 00149 throw (AuroraException); 00150 00151 unsigned long getULongWithDefault(string propName, unsigned long defaultValue) const; 00152 00153 //----------------------------------------------------------------------------- 00154 00155 unsigned long long getULongLong(string propName) const 00156 throw (AuroraException); 00157 00158 bool isULongLongPropDefined(string propName) const 00159 throw (AuroraException); 00160 00161 unsigned long long getULongLongWithDefault(string propName, unsigned long long defaultValue) const; 00162 00163 //----------------------------------------------------------------------------- 00164 00165 double getDouble(string propName) const 00166 throw (AuroraException); 00167 00168 bool isDoubleDefined(string propName) const 00169 throw (AuroraException); 00170 00171 double getDoubleWithDefault(string propName, double defaultValue) const; 00172 00173 //----------------------------------------------------------------------------- 00174 00175 string getString(string propName) const 00176 throw (AuroraException); 00177 00178 bool isStringPropDefined(string propName) const 00179 throw (AuroraException); 00180 00181 string getStringWithDefault(string propName, string defaultValue) const; 00182 00183 //----------------------------------------------------------------------------- 00184 00185 private: 00186 // The various stored values. Key = prop name, dependent value = prop value. 00187 map<string, bool> _boolMap; 00188 map<string, int> _intMap; 00189 map<string, unsigned int> _uintMap; 00190 map<string, long> _longMap; 00191 map<string, unsigned long> _ulongMap; 00192 map<string, unsigned long long> _ulongLongMap; 00193 map<string, double> _doubleMap; 00194 map<string, string> _stringMap; 00195 00196 struct AliasTarget 00197 { 00198 string _propName; 00199 string _propType; 00200 00201 AliasTarget(string propName, string propType) 00202 : _propName(propName), 00203 _propType(propType) 00204 { 00205 } 00206 }; 00207 00208 // Maps aliases to the propetery name/type that alias is tied to. 00209 map<string, AliasTarget> _aliasMap; 00210 00211 void loadFile(string filepath) 00212 throw (AuroraException); 00213 }; 00214 00215 BOREALIS_NAMESPACE_END; 00216 00217 #endif

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