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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef TOOLS_INIFILE_HH
00047 #define TOOLS_INIFILE_HH
00048
00049 #include <OpenFlipper/common/GlobalDefines.hh>
00050 #include <QString>
00051 #include <QFile>
00052 #include <map>
00053 #include <vector>
00054
00055
00057
00098 class DLLEXPORT INIFile
00099 {
00100 public :
00101
00103 INIFile();
00104
00106 ~INIFile();
00107
00109 bool connect( const QString& name,
00110 const bool create );
00111
00113 void disconnect();
00114
00116 bool is_connected() const { return mf_isConnected; }
00117
00119 const QString& name() const { return m_filename; }
00120
00121
00122
00123
00126
00128 bool section_exists(const QString & _section) const;
00129
00131 bool entry_exists(const QString & _section, const QString & _key) const;
00132
00134 bool entry_in_section(const QString & _section,
00135 const QString & _key) const
00136 { return entry_exists( _section, _key ); }
00137
00138
00139
00142
00144
00145
00146
00147 void add_section(const QString & _sectionname);
00148
00150 void add_entry( const QString & _section,
00151 const QString & _key,
00152 const QString & _value );
00153
00155 void add_entry( const QString & _section,
00156 const QString & _key,
00157 const char * _value )
00158 { add_entry( _section, _key, QString(_value) ); }
00159
00161 void add_entry( const QString & _section,
00162 const QString & _key,
00163 const double & _value);
00164
00166 void add_entry( const QString & _section,
00167 const QString & _key,
00168 const float & _value);
00169
00171 void add_entry( const QString & _section,
00172 const QString & _key ,
00173 const int & _value);
00174
00176 void add_entry( const QString & _section,
00177 const QString & _key ,
00178 const unsigned int & _value);
00179
00181 void add_entry( const QString & _section,
00182 const QString & _key ,
00183 const bool & _value);
00184
00186 void add_entry( const QString & _section,
00187 const QString & _key ,
00188 const std::vector<float> & _value);
00189
00191 void add_entry( const QString & _section,
00192 const QString & _key ,
00193 const std::vector<double> & _value);
00194
00196 template < typename VectorT >
00197 void add_entryVec ( const QString & _section,
00198 const QString & _key,
00199 const VectorT & _value);
00200
00202 template < typename VectorT >
00203 void add_entryVec ( const QString & _section,
00204 const QString & _key,
00205 const std::vector< VectorT > & _value);
00206
00208 void add_entry( const QString & _section,
00209 const QString & _key ,
00210 const std::vector<int> & _value);
00211
00213 void add_entry( const QString & _section,
00214 const QString & _key ,
00215 const std::vector<QString> & _value);
00216
00218 void add_entry( const QString & _section,
00219 const QString & _key ,
00220 const QStringList & _value);
00221
00222
00224
00225
00226
00227
00230
00232 void delete_entry( const QString & _section, const QString & _key);
00233
00235 void delete_section( const QString & _sectionname );
00236
00238
00239
00240
00241
00242
00245
00247 bool get_entry( QString & _val,
00248 const QString & _section,
00249 const QString & _key ) const;
00250
00252 bool get_entry( double & _val,
00253 const QString & _section,
00254 const QString & _key ) const;
00255
00257 bool get_entry( float & _val,
00258 const QString & _section,
00259 const QString & _key ) const;
00260
00262 bool get_entry( int & _val,
00263 const QString & _section,
00264 const QString & _key ) const;
00265
00267 bool get_entry( unsigned int & _val,
00268 const QString & _section,
00269 const QString & _key ) const;
00270
00272 bool get_entry( bool & _val,
00273 const QString & _section,
00274 const QString & _key) const;
00275
00277 bool get_entry( std::vector<float> & _val,
00278 const QString & _section,
00279 const QString & _key) const;
00280
00282 bool get_entry( std::vector<double> & _val,
00283 const QString & _section,
00284 const QString & _key) const;
00285
00287 bool get_entry( std::vector<int> & _val,
00288 const QString & _section,
00289 const QString & _key) const;
00290
00292 bool get_entry( std::vector<QString> & _val,
00293 const QString & _section,
00294 const QString & _key ) const;
00295
00297 bool get_entry( QStringList & _val,
00298 const QString & _section,
00299 const QString & _key ) const;
00300
00302 template < typename VectorT >
00303 bool get_entryVecd ( VectorT & _val ,
00304 const QString & _section,
00305 const QString & _key ) const;
00306
00308 template < typename VectorT >
00309 bool get_entryVecf ( VectorT & _val ,
00310 const QString & _section,
00311 const QString & _key ) const;
00312
00314 template < typename VectorT >
00315 bool get_entryVeci ( VectorT & _val ,
00316 const QString & _section,
00317 const QString & _key ) const;
00318
00320 template < typename VectorT >
00321 bool get_entryVecd (std::vector< VectorT > & _val ,
00322 const QString & _section,
00323 const QString & _key ) const;
00324
00326 template < typename VectorT >
00327 bool get_entryVecf (std::vector< VectorT > & _val ,
00328 const QString & _section,
00329 const QString & _key ) const;
00330
00332 template < typename VectorT >
00333 bool get_entryVeci (std::vector< VectorT > & _val ,
00334 const QString & _section,
00335 const QString & _key ) const;
00336
00337
00338 private:
00339
00340
00342 typedef std::map< QString, QString > EntryMap;
00343
00344
00346 typedef std::map< QString, EntryMap > SectionMap;
00347
00348
00351
00353 bool parseFile( QFile & _inputStream );
00354
00356 bool writeFile( void );
00357
00359 QString m_filename;
00360
00362 bool mf_isConnected;
00363
00364
00366 SectionMap m_iniData;
00367 };
00368
00369
00370 #if defined(INCLUDE_TEMPLATES) && !defined(INIFILE_C)
00371 #define INIFILE_TEMPLATES
00372 #include "INIFileT.cc"
00373 #endif
00374
00375 #endif