1 |
/* |
/* |
2 |
$Id$ |
$Id$ |
3 |
|
|
4 |
Copyright (C) 2004 Kai Sterker <kaisterker@linuxgames.com> |
Copyright (C) 2004 Kai Sterker <kaisterker@linuxgames.com> |
5 |
Part of the Adonthell Project http://adonthell.linuxgames.com |
Part of the Adonthell Project http://adonthell.linuxgames.com |
6 |
|
|
7 |
Adonthell is free software; you can redistribute it and/or modify |
Adonthell is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
9 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
10 |
(at your option) any later version. |
(at your option) any later version. |
11 |
|
|
12 |
Adonthell is distributed in the hope that it will be useful, |
Adonthell is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
18 |
along with Adonthell; if not, write to the Free Software |
along with Adonthell; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
21 |
|
|
22 |
/** |
/** |
23 |
* @file base/configio.h |
* @file base/configio.h |
24 |
* @author Kai Sterker <kaisterker@linuxgames.com> |
* @author Kai Sterker <kaisterker@linuxgames.com> |
25 |
* |
* |
26 |
* @brief Loads and saves configuration file. |
* @brief Loads and saves configuration file. |
27 |
*/ |
*/ |
28 |
|
|
29 |
#ifndef BASE_CONFIG_IO_H |
#ifndef BASE_CONFIG_IO_H |
30 |
#define BASE_CONFIG_IO_H |
#define BASE_CONFIG_IO_H |
31 |
|
|
32 |
// low-level stuff swig/python needs not know about |
// low-level stuff swig/python needs not know about |
33 |
#ifndef SWIG |
#ifndef SWIG |
34 |
|
|
35 |
#include "base/configuration.h" |
#include "base/configuration.h" |
36 |
|
|
37 |
namespace base { |
namespace base { |
38 |
/** |
/** |
39 |
* Encapsulates reading and writing the XML configuration file. |
* Encapsulates reading and writing the XML configuration file. |
40 |
* Reading is done via a custom SAX parser. For writing, the xml |
* Reading is done via a custom SAX parser. For writing, the xml |
41 |
* xml document is created in memory first and then saved to file. |
* xml document is created in memory first and then saved to file. |
42 |
*/ |
*/ |
43 |
class config_io |
class config_io |
44 |
{ |
{ |
45 |
public: |
public: |
46 |
/** |
/** |
47 |
* Parser states. |
* Parser states. |
48 |
*/ |
*/ |
49 |
enum { UNDEF, START, SECTION, OPTION }; |
enum { UNDEF, START, SECTION, OPTION }; |
50 |
|
|
51 |
/** |
/** |
52 |
* Read a configuration from file. |
* Read a configuration from file. |
53 |
* @param filename name of configuration file without path and suffix. |
* @param filename name of configuration file without path and suffix. |
54 |
* @param config configuration to load given file into. |
* @param config configuration to load given file into. |
55 |
* @return \c true on success, \c false otherwise |
* @return \c true on success, \c false otherwise |
56 |
*/ |
*/ |
57 |
static bool read (const std::string & filename, base::configuration *config); |
static bool read (const std::string & filename, base::configuration *config); |
58 |
|
|
59 |
/** |
/** |
60 |
* Write configuration to file. |
* Write configuration to file. |
61 |
* @param filename name of configuration file without path and suffix. |
* @param filename name of configuration file without path and suffix. |
62 |
* @param config configuration to write to given file. |
* @param config configuration to write to given file. |
63 |
* @return \c true on success, \c false otherwise |
* @return \c true on success, \c false otherwise |
64 |
*/ |
*/ |
65 |
static bool write (const std::string & filename, const base::configuration *config); |
static bool write (const std::string & filename, const base::configuration *config); |
66 |
}; |
}; |
67 |
} |
} |
68 |
|
|
69 |
#endif // SWIG |
#endif // SWIG |
70 |
#endif // BASE_CONFIG_IO_H |
#endif // BASE_CONFIG_IO_H |