00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CConfigFileBase_H
00029 #define CConfigFileBase_H
00030
00031 #include <mrpt/utils/utils_defs.h>
00032
00033
00034
00035
00036 namespace mrpt
00037 {
00038 namespace utils
00039 {
00043 class MRPTDLLIMPEXP CConfigFileBase
00044 {
00045 protected:
00048 virtual void writeString(const std::string §ion,const std::string &name, const std::string &str) = 0;
00049
00053 virtual std::string readString(
00054 const std::string §ion,
00055 const std::string &name,
00056 const std::string &defaultStr,
00057 bool failIfNotFound = false) const = 0;
00058
00059 public:
00062 virtual ~CConfigFileBase()
00063 {
00064 }
00065
00068 virtual void getAllSections( vector_string §ions ) const = 0 ;
00069
00071 bool sectionExists( const std::string §ion_name) const;
00072
00075 void write(const std::string §ion, const std::string &name, double value);
00076
00079 void write(const std::string §ion, const std::string &name, float value);
00080
00083 void write(const std::string §ion, const std::string &name, int value);
00084
00087 void write(const std::string §ion, const std::string &name, const std::string &value);
00088
00091 void write(const std::string §ion, const std::string &name, const std::vector<int> &value);
00092
00095 void write(const std::string §ion, const std::string &name, const std::vector<unsigned int> &value);
00096
00099 void write(const std::string §ion, const std::string &name, const std::vector<float> &value);
00100
00103 void write(const std::string §ion, const std::string &name, const std::vector<double> &value);
00104
00107 void write(const std::string §ion, const std::string &name, const std::vector<bool> &value);
00108
00112 double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound = false) const;
00113
00117 float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound = false) const;
00118
00122 bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound = false) const;
00123
00127 int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound = false) const;
00128
00132 uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound ) const;
00133
00137 std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound = false) const;
00138
00142 std::string read_string_first_word(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound = false) const;
00143
00147 void read_vector(
00148 const std::string §ion,
00149 const std::string &name,
00150 const std::vector<uint32_t> &defaultValue,
00151 std::vector<uint32_t> &outValues,
00152 bool failIfNotFound = false) const;
00153
00157 void read_vector(
00158 const std::string §ion,
00159 const std::string &name,
00160 const std::vector<int32_t> &defaultValue,
00161 std::vector<int32_t> &outValues,
00162 bool failIfNotFound = false) const;
00163
00167 void read_vector(
00168 const std::string §ion,
00169 const std::string &name,
00170 const std::vector<uint64_t> &defaultValue,
00171 std::vector<uint64_t> &outValues,
00172 bool failIfNotFound = false) const;
00173
00177 void read_vector(
00178 const std::string §ion,
00179 const std::string &name,
00180 const std::vector<int64_t> &defaultValue,
00181 std::vector<int64_t> &outValues,
00182 bool failIfNotFound = false) const;
00183
00184
00188 void read_vector(
00189 const std::string §ion,
00190 const std::string &name,
00191 const std::vector<float> &defaultValue,
00192 std::vector<float> &outValues,
00193 bool failIfNotFound = false) const;
00194
00198 void read_vector(
00199 const std::string §ion,
00200 const std::string &name,
00201 const std::vector<double> &defaultValue,
00202 std::vector<double> &outValues,
00203 bool failIfNotFound = false ) const;
00204
00208 void read_vector(
00209 const std::string §ion,
00210 const std::string &name,
00211 const std::vector<bool> &defaultValue,
00212 std::vector<bool> &outValues,
00213 bool failIfNotFound = false ) const;
00214
00215 };
00216
00220 #define MRPT_LOAD_CONFIG_VAR(variableName,variableType,configFileObject,sectionNameStr) \
00221 { variableName = configFileObject.read_##variableType(sectionNameStr,#variableName,variableName); }
00222
00225 #define MRPT_LOAD_CONFIG_VAR_DEGREES(variableName,configFileObject,sectionNameStr) \
00226 { variableName = DEG2RAD( configFileObject.read_float(sectionNameStr,#variableName, RAD2DEG(variableName)) ); }
00227
00228 #define MRPT_LOAD_CONFIG_VAR_CAST(variableName,variableType,variableTypeCast,configFileObject,sectionNameStr) \
00229 { variableName = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,variableName)); }
00230
00231
00232 #define MRPT_LOAD_HERE_CONFIG_VAR(variableName,variableType,targetVariable,configFileObject,sectionNameStr) \
00233 targetVariable = configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,false);
00234
00235 #define MRPT_LOAD_HERE_CONFIG_VAR_NO_DEFAULT(variableName,variableType,targetVariable,configFileObject,sectionNameStr) \
00236 { try { \
00237 targetVariable = configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,true); \
00238 } catch (std::exception &) \
00239 { \
00240 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00241 } }\
00242
00243
00244 #define MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(variableName,variableType,configFileObject,sectionNameStr) \
00245 { try { \
00246 variableName = configFileObject.read_##variableType(sectionNameStr,#variableName,variableName,true); \
00247 } catch (std::exception &) \
00248 { \
00249 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00250 } }\
00251
00252 #define MRPT_LOAD_CONFIG_VAR_CAST_NO_DEFAULT(variableName,variableType,variableTypeCast,configFileObject,sectionNameStr) \
00253 { try { \
00254 variableName = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,variableName,true)); \
00255 } catch (std::exception &) \
00256 { \
00257 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00258 } }\
00259
00260
00261 #define MRPT_LOAD_HERE_CONFIG_VAR_CAST(variableName,variableType,variableTypeCast,targetVariable,configFileObject,sectionNameStr) \
00262 targetVariable = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable));
00263
00264 #define MRPT_LOAD_HERE_CONFIG_VAR_CAST_NO_DEFAULT(variableName,variableType,variableTypeCast,targetVariable,configFileObject,sectionNameStr) \
00265 { try { \
00266 targetVariable = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,true)); \
00267 } catch (std::exception &) \
00268 { \
00269 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00270 } }\
00271
00272
00273 }
00274 }
00275 #endif