Developer Documentation
INIFile.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 
46 
47 #ifndef TOOLS_INIFILE_HH
48 #define TOOLS_INIFILE_HH
49 
51 #include <QString>
52 #include <QFile>
53 #include <map>
54 #include <vector>
55 
56 
58 
100 {
101 public :
102 
104  INIFile();
105 
107  ~INIFile();
108 
110  bool connect( const QString& name,
111  const bool create );
112 
114  void disconnect();
115 
117  bool is_connected() const { return mf_isConnected; }
118 
120  const QString& name() const { return m_filename; }
121 
122 
123  // ---------------------------------------- check if something is there
124 
127 
129  bool section_exists(const QString & _section) const;
130 
132  bool entry_exists(const QString & _section, const QString & _key) const;
133 
135  bool entry_in_section(const QString & _section,
136  const QString & _key) const
137  { return entry_exists( _section, _key ); }
138 
139  // ---------------------------------------- section manipulation
140 
143 
145  /* \deprecated This function is not needed any more. New sections are
146  implicitly created upon calls to add_entry().
147  */
148  void add_section(const QString & _sectionname);
149 
151  void add_entry( const QString & _section,
152  const QString & _key,
153  const QString & _value );
154 
156  void add_entry( const QString & _section,
157  const QString & _key,
158  const char * _value )
159  { add_entry( _section, _key, QString(_value) ); }
160 
162  void add_entry( const QString & _section,
163  const QString & _key,
164  const double & _value);
165 
167  void add_entry( const QString & _section,
168  const QString & _key,
169  const float & _value);
170 
172  void add_entry( const QString & _section,
173  const QString & _key ,
174  const int & _value);
175 
177  void add_entry( const QString & _section,
178  const QString & _key ,
179  const unsigned int & _value);
180 
182  void add_entry( const QString & _section,
183  const QString & _key ,
184  const bool & _value);
185 
187  void add_entry( const QString & _section,
188  const QString & _key ,
189  const std::vector<float> & _value);
190 
192  void add_entry( const QString & _section,
193  const QString & _key ,
194  const std::vector<double> & _value);
195 
197  void add_entry( const QString & _section,
198  const QString & _key ,
199  const std::vector<bool> & _value);
200 
202  template < typename VectorT >
203  void add_entryVec ( const QString & _section,
204  const QString & _key,
205  const VectorT & _value);
206 
208  template < typename VectorT >
209  void add_entryVec ( const QString & _section,
210  const QString & _key,
211  const std::vector< VectorT > & _value);
212 
214  void add_entry( const QString & _section,
215  const QString & _key ,
216  const std::vector<int> & _value);
217 
219  void add_entry( const QString & _section,
220  const QString & _key ,
221  const std::vector<QString> & _value);
222 
224  void add_entry( const QString & _section,
225  const QString & _key ,
226  const QStringList & _value);
227 
228 
230 
231 
232  // -------------------- delete
233 
236 
238  void delete_entry( const QString & _section, const QString & _key);
239 
241  void delete_section( const QString & _sectionname );
242 
244 
245 
246 
247  // -------------------- retrieval
248 
251 
253  bool get_entry( QString & _val,
254  const QString & _section,
255  const QString & _key ) const;
256 
258  bool get_entry( double & _val,
259  const QString & _section,
260  const QString & _key ) const;
261 
263  bool get_entry( float & _val,
264  const QString & _section,
265  const QString & _key ) const;
266 
268  bool get_entry( int & _val,
269  const QString & _section,
270  const QString & _key ) const;
271 
273  bool get_entry( unsigned int & _val,
274  const QString & _section,
275  const QString & _key ) const;
276 
278  bool get_entry( bool & _val,
279  const QString & _section,
280  const QString & _key) const;
281 
283  bool get_entry( std::vector<float> & _val,
284  const QString & _section,
285  const QString & _key) const;
286 
288  bool get_entry( std::vector<double> & _val,
289  const QString & _section,
290  const QString & _key) const;
291 
293  bool get_entry( std::vector<bool> & _val,
294  const QString & _section,
295  const QString & _key) const;
296 
298  bool get_entry( std::vector<int> & _val,
299  const QString & _section,
300  const QString & _key) const;
301 
303  bool get_entry( std::vector<QString> & _val,
304  const QString & _section,
305  const QString & _key ) const;
306 
308  bool get_entry( QStringList & _val,
309  const QString & _section,
310  const QString & _key ) const;
311 
313  template < typename VectorT >
314  bool get_entryVecd ( VectorT & _val ,
315  const QString & _section,
316  const QString & _key ) const;
317 
319  template < typename VectorT >
320  bool get_entryVecf ( VectorT & _val ,
321  const QString & _section,
322  const QString & _key ) const;
323 
325  template < typename VectorT >
326  bool get_entryVeci ( VectorT & _val ,
327  const QString & _section,
328  const QString & _key ) const;
329 
331  template < typename VectorT >
332  bool get_entryVecd (std::vector< VectorT > & _val ,
333  const QString & _section,
334  const QString & _key ) const;
335 
337  template < typename VectorT >
338  bool get_entryVecf (std::vector< VectorT > & _val ,
339  const QString & _section,
340  const QString & _key ) const;
341 
343  template < typename VectorT >
344  bool get_entryVeci (std::vector< VectorT > & _val ,
345  const QString & _section,
346  const QString & _key ) const;
347 
348 
349 private: // data
350 
351 
353  typedef std::map< QString, QString > EntryMap;
354 
355 
357  typedef std::map< QString, EntryMap > SectionMap;
358 
359 
362 
364  bool parseFile( QFile & _inputStream );
365 
367  bool writeFile( void );
368 
370  QString m_filename;
371 
374 
375 
377  SectionMap m_iniData;
378 };
379 
380 
381 #if defined(INCLUDE_TEMPLATES) && !defined(INIFILE_C)
382 #define INIFILE_TEMPLATES
383 #include "INIFileT_impl.hh"
384 #endif
385 
386 #endif
void add_entry(const QString &_section, const QString &_key, const char *_value)
Addition / modification of a string entry, given as char array.
Definition: INIFile.hh:156
bool mf_isConnected
Flag: this object is connected to an INI file.
Definition: INIFile.hh:373
bool is_connected() const
Check if object is connected to file.
Definition: INIFile.hh:117
std::map< QString, EntryMap > SectionMap
Type for map of contained sections.
Definition: INIFile.hh:357
const QString & name() const
Access to name of connected file.
Definition: INIFile.hh:120
std::map< QString, QString > EntryMap
Type for map of contained entries.
Definition: INIFile.hh:353
bool entry_in_section(const QString &_section, const QString &_key) const
Same as entry_exists() (for backward compatibility)
Definition: INIFile.hh:135
QString m_filename
Name of current INI file.
Definition: INIFile.hh:370
SectionMap m_iniData
Stored data of an INI file.
Definition: INIFile.hh:377
#define DLLEXPORT
Class for the handling of simple configuration files.
Definition: INIFile.hh:99