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 #include <mrpt/math/CMatrixTemplate.h>
00034
00035
00036
00037
00038 namespace mrpt
00039 {
00040 namespace utils
00041 {
00042
00043
00044
00045 class MRPTDLLIMPEXP CConfigFileBase
00046 {
00047 protected:
00048
00049
00050 virtual void writeString(const std::string §ion,const std::string &name, const std::string &str) = 0;
00051
00052
00053
00054
00055 virtual std::string readString(
00056 const std::string §ion,
00057 const std::string &name,
00058 const std::string &defaultStr,
00059 bool failIfNotFound = false) const = 0;
00060
00061 public:
00062
00063
00064 virtual ~CConfigFileBase()
00065 {
00066 }
00067
00068
00069
00070 virtual void getAllSections( vector_string §ions ) const = 0 ;
00071
00072
00073
00074 virtual void getAllKeys( const std::string section, vector_string &keys ) const = 0;
00075
00076
00077 bool sectionExists( const std::string §ion_name) const;
00078
00079
00080
00081 void write(const std::string §ion, const std::string &name, double value);
00082
00083
00084
00085 void write(const std::string §ion, const std::string &name, float value);
00086
00087
00088
00089 void write(const std::string §ion, const std::string &name, int value);
00090
00091
00092
00093 void write(const std::string §ion, const std::string &name, unsigned int value);
00094
00095
00096
00097 void write(const std::string §ion, const std::string &name, const std::string &value);
00098
00099
00100
00101 void write(const std::string §ion, const std::string &name, const std::vector<int> &value);
00102
00103
00104
00105 void write(const std::string §ion, const std::string &name, const std::vector<unsigned int> &value);
00106
00107
00108
00109 void write(const std::string §ion, const std::string &name, const std::vector<float> &value);
00110
00111
00112
00113 void write(const std::string §ion, const std::string &name, const std::vector<double> &value);
00114
00115
00116
00117 void write(const std::string §ion, const std::string &name, const std::vector<bool> &value);
00118
00119
00120
00121
00122 double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound = false) const;
00123
00124
00125
00126
00127 float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound = false) const;
00128
00129
00130
00131
00132 bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound = false) const;
00133
00134
00135
00136
00137 int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound = false) const;
00138
00139
00140
00141
00142 uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound = false ) const;
00143
00144
00145
00146
00147 std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound = false) const;
00148
00149
00150
00151
00152 std::string read_string_first_word(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound = false) const;
00153
00154
00155
00156
00157 void read_vector(
00158 const std::string §ion,
00159 const std::string &name,
00160 const std::vector<uint32_t> &defaultValue,
00161 std::vector<uint32_t> &outValues,
00162 bool failIfNotFound = false) const;
00163
00164
00165
00166
00167 void read_vector(
00168 const std::string §ion,
00169 const std::string &name,
00170 const std::vector<int32_t> &defaultValue,
00171 std::vector<int32_t> &outValues,
00172 bool failIfNotFound = false) const;
00173
00174
00175
00176
00177 void read_vector(
00178 const std::string §ion,
00179 const std::string &name,
00180 const std::vector<uint64_t> &defaultValue,
00181 std::vector<uint64_t> &outValues,
00182 bool failIfNotFound = false) const;
00183
00184
00185
00186
00187 void read_vector(
00188 const std::string §ion,
00189 const std::string &name,
00190 const std::vector<int64_t> &defaultValue,
00191 std::vector<int64_t> &outValues,
00192 bool failIfNotFound = false) const;
00193
00194
00195
00196
00197
00198 void read_vector(
00199 const std::string §ion,
00200 const std::string &name,
00201 const std::vector<float> &defaultValue,
00202 std::vector<float> &outValues,
00203 bool failIfNotFound = false) const;
00204
00205
00206
00207
00208 void read_vector(
00209 const std::string §ion,
00210 const std::string &name,
00211 const std::vector<double> &defaultValue,
00212 std::vector<double> &outValues,
00213 bool failIfNotFound = false ) const;
00214
00215
00216
00217
00218 void read_vector(
00219 const std::string §ion,
00220 const std::string &name,
00221 const std::vector<bool> &defaultValue,
00222 std::vector<bool> &outValues,
00223 bool failIfNotFound = false ) const;
00224
00225
00226
00227
00228
00229 template <class T>
00230 void read_matrix(
00231 const std::string §ion,
00232 const std::string &name,
00233 mrpt::math::CMatrixTemplate<T> &outMatrix,
00234 const mrpt::math::CMatrixTemplate<T> &defaultMatrix = mrpt::math::CMatrixTemplate<T>(0,0),
00235 bool failIfNotFound = false ) const;
00236
00237
00238 };
00239
00240
00241
00242
00243 #define MRPT_LOAD_CONFIG_VAR(variableName,variableType,configFileObject,sectionNameStr) \
00244 { variableName = configFileObject.read_##variableType(sectionNameStr,#variableName,variableName); }
00245
00246
00247
00248 #define MRPT_LOAD_CONFIG_VAR_DEGREES(variableName,configFileObject,sectionNameStr) \
00249 { variableName = DEG2RAD( configFileObject.read_float(sectionNameStr,#variableName, RAD2DEG(variableName)) ); }
00250
00251 #define MRPT_LOAD_CONFIG_VAR_CAST(variableName,variableType,variableTypeCast,configFileObject,sectionNameStr) \
00252 { variableName = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,variableName)); }
00253
00254
00255 #define MRPT_LOAD_HERE_CONFIG_VAR(variableName,variableType,targetVariable,configFileObject,sectionNameStr) \
00256 targetVariable = configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,false);
00257
00258 #define MRPT_LOAD_HERE_CONFIG_VAR_NO_DEFAULT(variableName,variableType,targetVariable,configFileObject,sectionNameStr) \
00259 { try { \
00260 targetVariable = configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,true); \
00261 } catch (std::exception &) \
00262 { \
00263 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00264 } }\
00265
00266
00267 #define MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(variableName,variableType,configFileObject,sectionNameStr) \
00268 { try { \
00269 variableName = configFileObject.read_##variableType(sectionNameStr,#variableName,variableName,true); \
00270 } catch (std::exception &) \
00271 { \
00272 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00273 } }\
00274
00275 #define MRPT_LOAD_CONFIG_VAR_CAST_NO_DEFAULT(variableName,variableType,variableTypeCast,configFileObject,sectionNameStr) \
00276 { try { \
00277 variableName = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,variableName,true)); \
00278 } catch (std::exception &) \
00279 { \
00280 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00281 } }\
00282
00283
00284 #define MRPT_LOAD_HERE_CONFIG_VAR_CAST(variableName,variableType,variableTypeCast,targetVariable,configFileObject,sectionNameStr) \
00285 targetVariable = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable));
00286
00287 #define MRPT_LOAD_HERE_CONFIG_VAR_CAST_NO_DEFAULT(variableName,variableType,variableTypeCast,targetVariable,configFileObject,sectionNameStr) \
00288 { try { \
00289 targetVariable = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,true)); \
00290 } catch (std::exception &) \
00291 { \
00292 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00293 } }\
00294
00295
00296 #define MRPT_SAVE_CONFIG_VAR(variableName,configFileObject,sectionNameStr) \
00297 { configFileObject.write(sectionNameStr,#variableName,variableName); }
00298
00299 #define MRPT_SAVE_CONFIG_VAR_DEGREES(variableName,configFileObject,sectionNameStr) \
00300 { configFileObject.write(sectionNameStr,#variableName, RAD2DEG(variableName)); }
00301
00302
00303 }
00304 }
00305 #endif