blob: b9afcf6ceb0d1ec7ecee8112c9f697c6d2961986 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/******************************************************************************
* swconfig.h - definition of Class SWConfig used for saving and retrieval
* of configuration information
*
* $Id: swconfig.h,v 1.20 2002/10/01 22:04:58 dglassey Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
*/
#ifndef SWCONFIG_H
#define SWCONFIG_H
#include <stdio.h>
#include <string>
#include <map>
#include <defs.h>
#include <multimapwdef.h>
SWORD_NAMESPACE_START
typedef multimapwithdefault < std::string, std::string, std::less < std::string > >ConfigEntMap;
typedef std::map < std::string, ConfigEntMap, std::less < std::string > >SectionMap;
/** The class to read and save settings using a file on disk.
*
*/
class SWDLLEXPORT SWConfig {
private:
char getline(FILE * fp, std::string & line);
public:
/** The filename used by this SWConfig object
*
*/
std::string filename;
/** Map of available sections
* The map of available sections.
*/
SectionMap Sections;
/** Constructor of SWConfig
* @param ifilename The file, which should be used for this config.
*/
SWConfig(const char *ifilename);
virtual ~SWConfig();
/** Load from disk
* Load the contzent from disk.
*/
virtual void Load();
/** Save to disk
* Save the content of this config object to disk.
*/
virtual void Save();
/** Merges the values of addFrom
* @param The config which values should be merged to this config object. Already existing values will be overwritten.
*/
virtual void augment(SWConfig &addFrom);
virtual SWConfig & operator +=(SWConfig &addFrom) { augment(addFrom); return *this; }
/** Get a section
* This is an easy way to get and store config values.
* The following will work:\n
*
* @code
* SWConfig config("/home/user/.setttings");
* config["Colors"]["Background"] = "red";
* @endcode
*/
virtual ConfigEntMap & operator [](const char *section);
};
SWORD_NAMESPACE_END
#endif
|