Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 #ifndef TOOLS_INIFILE_HH
54 #define TOOLS_INIFILE_HH
55 
57 #include <QString>
58 #include <QFile>
59 #include <map>
60 #include <vector>
61 
62 
64 
106 {
107 public :
108 
110  INIFile();
111 
113  ~INIFile();
114 
116  bool connect( const QString& name,
117  const bool create );
118 
120  void disconnect();
121 
123  bool is_connected() const { return mf_isConnected; }
124 
126  const QString& name() const { return m_filename; }
127 
128 
129  // ---------------------------------------- check if something is there
130 
133 
135  bool section_exists(const QString & _section) const;
136 
138  bool entry_exists(const QString & _section, const QString & _key) const;
139 
141  bool entry_in_section(const QString & _section,
142  const QString & _key) const
143  { return entry_exists( _section, _key ); }
144 
145  // ---------------------------------------- section manipulation
146 
149 
151  /* \deprecated This function is not needed any more. New sections are
152  implicitly created upon calls to add_entry().
153  */
154  void add_section(const QString & _sectionname);
155 
157  void add_entry( const QString & _section,
158  const QString & _key,
159  const QString & _value );
160 
162  void add_entry( const QString & _section,
163  const QString & _key,
164  const char * _value )
165  { add_entry( _section, _key, QString(_value) ); }
166 
168  void add_entry( const QString & _section,
169  const QString & _key,
170  const double & _value);
171 
173  void add_entry( const QString & _section,
174  const QString & _key,
175  const float & _value);
176 
178  void add_entry( const QString & _section,
179  const QString & _key ,
180  const int & _value);
181 
183  void add_entry( const QString & _section,
184  const QString & _key ,
185  const unsigned int & _value);
186 
188  void add_entry( const QString & _section,
189  const QString & _key ,
190  const bool & _value);
191 
193  void add_entry( const QString & _section,
194  const QString & _key ,
195  const std::vector<float> & _value);
196 
198  void add_entry( const QString & _section,
199  const QString & _key ,
200  const std::vector<double> & _value);
201 
203  void add_entry( const QString & _section,
204  const QString & _key ,
205  const std::vector<bool> & _value);
206 
208  template < typename VectorT >
209  void add_entryVec ( const QString & _section,
210  const QString & _key,
211  const VectorT & _value);
212 
214  template < typename VectorT >
215  void add_entryVec ( const QString & _section,
216  const QString & _key,
217  const std::vector< VectorT > & _value);
218 
220  void add_entry( const QString & _section,
221  const QString & _key ,
222  const std::vector<int> & _value);
223 
225  void add_entry( const QString & _section,
226  const QString & _key ,
227  const std::vector<QString> & _value);
228 
230  void add_entry( const QString & _section,
231  const QString & _key ,
232  const QStringList & _value);
233 
234 
236 
237 
238  // -------------------- delete
239 
242 
244  void delete_entry( const QString & _section, const QString & _key);
245 
247  void delete_section( const QString & _sectionname );
248 
250 
251 
252 
253  // -------------------- retrieval
254 
257 
259  bool get_entry( QString & _val,
260  const QString & _section,
261  const QString & _key ) const;
262 
264  bool get_entry( double & _val,
265  const QString & _section,
266  const QString & _key ) const;
267 
269  bool get_entry( float & _val,
270  const QString & _section,
271  const QString & _key ) const;
272 
274  bool get_entry( int & _val,
275  const QString & _section,
276  const QString & _key ) const;
277 
279  bool get_entry( unsigned int & _val,
280  const QString & _section,
281  const QString & _key ) const;
282 
284  bool get_entry( bool & _val,
285  const QString & _section,
286  const QString & _key) const;
287 
289  bool get_entry( std::vector<float> & _val,
290  const QString & _section,
291  const QString & _key) const;
292 
294  bool get_entry( std::vector<double> & _val,
295  const QString & _section,
296  const QString & _key) const;
297 
299  bool get_entry( std::vector<bool> & _val,
300  const QString & _section,
301  const QString & _key) const;
302 
304  bool get_entry( std::vector<int> & _val,
305  const QString & _section,
306  const QString & _key) const;
307 
309  bool get_entry( std::vector<QString> & _val,
310  const QString & _section,
311  const QString & _key ) const;
312 
314  bool get_entry( QStringList & _val,
315  const QString & _section,
316  const QString & _key ) const;
317 
319  template < typename VectorT >
320  bool get_entryVecd ( VectorT & _val ,
321  const QString & _section,
322  const QString & _key ) const;
323 
325  template < typename VectorT >
326  bool get_entryVecf ( VectorT & _val ,
327  const QString & _section,
328  const QString & _key ) const;
329 
331  template < typename VectorT >
332  bool get_entryVeci ( VectorT & _val ,
333  const QString & _section,
334  const QString & _key ) const;
335 
337  template < typename VectorT >
338  bool get_entryVecd (std::vector< VectorT > & _val ,
339  const QString & _section,
340  const QString & _key ) const;
341 
343  template < typename VectorT >
344  bool get_entryVecf (std::vector< VectorT > & _val ,
345  const QString & _section,
346  const QString & _key ) const;
347 
349  template < typename VectorT >
350  bool get_entryVeci (std::vector< VectorT > & _val ,
351  const QString & _section,
352  const QString & _key ) const;
353 
354 
355 private: // data
356 
357 
359  typedef std::map< QString, QString > EntryMap;
360 
361 
363  typedef std::map< QString, EntryMap > SectionMap;
364 
365 
368 
370  bool parseFile( QFile & _inputStream );
371 
373  bool writeFile( void );
374 
376  QString m_filename;
377 
380 
381 
383  SectionMap m_iniData;
384 };
385 
386 
387 #if defined(INCLUDE_TEMPLATES) && !defined(INIFILE_C)
388 #define INIFILE_TEMPLATES
389 #include "INIFileT.cc"
390 #endif
391 
392 #endif
std::map< QString, QString > EntryMap
Type for map of contained entries.
Definition: INIFile.hh:359
bool is_connected() const
Check if object is connected to file.
Definition: INIFile.hh:123
Class for the handling of simple configuration files.
Definition: INIFile.hh:105
QString m_filename
Name of current INI file.
Definition: INIFile.hh:376
#define DLLEXPORT
bool mf_isConnected
Flag: this object is connected to an INI file.
Definition: INIFile.hh:379
std::map< QString, EntryMap > SectionMap
Type for map of contained sections.
Definition: INIFile.hh:363
bool entry_in_section(const QString &_section, const QString &_key) const
Same as entry_exists() (for backward compatibility)
Definition: INIFile.hh:141
const QString & name() const
Access to name of connected file.
Definition: INIFile.hh:126
SectionMap m_iniData
Stored data of an INI file.
Definition: INIFile.hh:383
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:162