Mercurial > hg > svcore
comparison base/ConfigFile.h @ 149:3e4c384f518e
* Reorganising code base. This revision will not compile.
author | Chris Cannam |
---|---|
date | Mon, 31 Jul 2006 12:03:45 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
148:1a42221a1522 | 149:3e4c384f518e |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _CONFIG_FILE_H_ | |
17 #define _CONFIG_FILE_H_ | |
18 | |
19 #include <QString> | |
20 #include <QMutex> | |
21 | |
22 #include <map> | |
23 | |
24 class ConfigFile | |
25 { | |
26 public: | |
27 ConfigFile(QString filename); | |
28 virtual ~ConfigFile(); | |
29 | |
30 /** | |
31 * Get a value, with a default if it hasn't been set. | |
32 */ | |
33 QString get(QString key, QString deft = ""); | |
34 | |
35 bool getBool(QString key, bool deft); | |
36 | |
37 int getInt(QString key, int deft); | |
38 | |
39 float getFloat(QString key, float deft); | |
40 | |
41 QStringList getStringList(QString key); | |
42 | |
43 /** | |
44 * Set a value. Values must not contain carriage return or other | |
45 * non-printable characters. Keys must contain [a-zA-Z0-9_-] only. | |
46 */ | |
47 void set(QString key, QString value); | |
48 | |
49 void set(QString key, bool value); | |
50 | |
51 void set(QString key, int value); | |
52 | |
53 void set(QString key, float value); | |
54 | |
55 void set(QString key, const QStringList &values); // must not contain '|' | |
56 | |
57 /** | |
58 * Write the data to file. May throw FileOperationFailed. | |
59 * | |
60 * This is called automatically on destruction if any data has | |
61 * changed since it was last called. At that time, any exception | |
62 * will be ignored. If you want to ensure that exceptions are | |
63 * handled, call it yourself before destruction. | |
64 */ | |
65 void commit(); | |
66 | |
67 /** | |
68 * Return to the stored values. You can also call this before | |
69 * destruction if you want to ensure that any values modified so | |
70 * far are not written out to file on destruction. | |
71 */ | |
72 void reset(); | |
73 | |
74 protected: | |
75 bool load(); | |
76 | |
77 QString m_filename; | |
78 | |
79 typedef std::map<QString, QString> DataMap; | |
80 DataMap m_data; | |
81 | |
82 bool m_loaded; | |
83 bool m_modified; | |
84 | |
85 QMutex m_mutex; | |
86 }; | |
87 | |
88 #endif | |
89 |