INIFile.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 6727 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-08-05 08:03:50 +0200 (Mi, 05. Aug 2009) $                   *
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     // ---------------------------------------- check if something is there
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     // ---------------------------------------- section manipulation
00139 
00142 
00144     /* \deprecated This function is not needed any more. New sections are
00145        implicitly created upon calls to add_entry().
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     // -------------------- delete
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     // -------------------- retrieval
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: // data
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

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .