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 bool sectionExists( const std::string §ion_name) const;
00074
00075
00076
00077 void write(const std::string §ion, const std::string &name, double value);
00078
00079
00080
00081 void write(const std::string §ion, const std::string &name, float value);
00082
00083
00084
00085 void write(const std::string §ion, const std::string &name, int value);
00086
00087
00088
00089 void write(const std::string §ion, const std::string &name, const std::string &value);
00090
00091
00092
00093 void write(const std::string §ion, const std::string &name, const std::vector<int> &value);
00094
00095
00096
00097 void write(const std::string §ion, const std::string &name, const std::vector<unsigned int> &value);
00098
00099
00100
00101 void write(const std::string §ion, const std::string &name, const std::vector<float> &value);
00102
00103
00104
00105 void write(const std::string §ion, const std::string &name, const std::vector<double> &value);
00106
00107
00108
00109 void write(const std::string §ion, const std::string &name, const std::vector<bool> &value);
00110
00111
00112
00113
00114 double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound = false) const;
00115
00116
00117
00118
00119 float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound = false) const;
00120
00121
00122
00123
00124 bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound = false) const;
00125
00126
00127
00128
00129 int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound = false) const;
00130
00131
00132
00133
00134 uint64_t read_uint64_t(const std::string §ion, const std::string &name, uint64_t defaultValue, bool failIfNotFound ) const;
00135
00136
00137
00138
00139 std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound = false) const;
00140
00141
00142
00143
00144 std::string read_string_first_word(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound = false) const;
00145
00146
00147
00148
00149 void read_vector(
00150 const std::string §ion,
00151 const std::string &name,
00152 const std::vector<uint32_t> &defaultValue,
00153 std::vector<uint32_t> &outValues,
00154 bool failIfNotFound = false) const;
00155
00156
00157
00158
00159 void read_vector(
00160 const std::string §ion,
00161 const std::string &name,
00162 const std::vector<int32_t> &defaultValue,
00163 std::vector<int32_t> &outValues,
00164 bool failIfNotFound = false) const;
00165
00166
00167
00168
00169 void read_vector(
00170 const std::string §ion,
00171 const std::string &name,
00172 const std::vector<uint64_t> &defaultValue,
00173 std::vector<uint64_t> &outValues,
00174 bool failIfNotFound = false) const;
00175
00176
00177
00178
00179 void read_vector(
00180 const std::string §ion,
00181 const std::string &name,
00182 const std::vector<int64_t> &defaultValue,
00183 std::vector<int64_t> &outValues,
00184 bool failIfNotFound = false) const;
00185
00186
00187
00188
00189
00190 void read_vector(
00191 const std::string §ion,
00192 const std::string &name,
00193 const std::vector<float> &defaultValue,
00194 std::vector<float> &outValues,
00195 bool failIfNotFound = false) const;
00196
00197
00198
00199
00200 void read_vector(
00201 const std::string §ion,
00202 const std::string &name,
00203 const std::vector<double> &defaultValue,
00204 std::vector<double> &outValues,
00205 bool failIfNotFound = false ) const;
00206
00207
00208
00209
00210 void read_vector(
00211 const std::string §ion,
00212 const std::string &name,
00213 const std::vector<bool> &defaultValue,
00214 std::vector<bool> &outValues,
00215 bool failIfNotFound = false ) const;
00216
00217
00218
00219
00220
00221 template <class T>
00222 void read_matrix(
00223 const std::string §ion,
00224 const std::string &name,
00225 mrpt::math::CMatrixTemplate<T> &outMatrix,
00226 const mrpt::math::CMatrixTemplate<T> &defaultMatrix = mrpt::math::CMatrixTemplate<T>(0,0),
00227 bool failIfNotFound = false ) const;
00228
00229
00230 };
00231
00232
00233
00234
00235 #define MRPT_LOAD_CONFIG_VAR(variableName,variableType,configFileObject,sectionNameStr) \
00236 { variableName = configFileObject.read_##variableType(sectionNameStr,#variableName,variableName); }
00237
00238
00239
00240 #define MRPT_LOAD_CONFIG_VAR_DEGREES(variableName,configFileObject,sectionNameStr) \
00241 { variableName = DEG2RAD( configFileObject.read_float(sectionNameStr,#variableName, RAD2DEG(variableName)) ); }
00242
00243 #define MRPT_LOAD_CONFIG_VAR_CAST(variableName,variableType,variableTypeCast,configFileObject,sectionNameStr) \
00244 { variableName = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,variableName)); }
00245
00246
00247 #define MRPT_LOAD_HERE_CONFIG_VAR(variableName,variableType,targetVariable,configFileObject,sectionNameStr) \
00248 targetVariable = configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,false);
00249
00250 #define MRPT_LOAD_HERE_CONFIG_VAR_NO_DEFAULT(variableName,variableType,targetVariable,configFileObject,sectionNameStr) \
00251 { try { \
00252 targetVariable = configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,true); \
00253 } catch (std::exception &) \
00254 { \
00255 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00256 } }\
00257
00258
00259 #define MRPT_LOAD_CONFIG_VAR_NO_DEFAULT(variableName,variableType,configFileObject,sectionNameStr) \
00260 { try { \
00261 variableName = configFileObject.read_##variableType(sectionNameStr,#variableName,variableName,true); \
00262 } catch (std::exception &) \
00263 { \
00264 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00265 } }\
00266
00267 #define MRPT_LOAD_CONFIG_VAR_CAST_NO_DEFAULT(variableName,variableType,variableTypeCast,configFileObject,sectionNameStr) \
00268 { try { \
00269 variableName = static_cast<variableTypeCast>(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
00276 #define MRPT_LOAD_HERE_CONFIG_VAR_CAST(variableName,variableType,variableTypeCast,targetVariable,configFileObject,sectionNameStr) \
00277 targetVariable = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable));
00278
00279 #define MRPT_LOAD_HERE_CONFIG_VAR_CAST_NO_DEFAULT(variableName,variableType,variableTypeCast,targetVariable,configFileObject,sectionNameStr) \
00280 { try { \
00281 targetVariable = static_cast<variableTypeCast>(configFileObject.read_##variableType(sectionNameStr,#variableName,targetVariable,true)); \
00282 } catch (std::exception &) \
00283 { \
00284 THROW_EXCEPTION( format( "Value for '%s' not found in config file", static_cast<const char*>(#variableName ) )); \
00285 } }\
00286
00287
00288 }
00289 }
00290 #endif