The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swconfig.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * swconfig.h - class SWConfig: used for saving and
4  * retrieval of configuration information
5  *
6  * $Id: swconfig.h 3786 2020-08-30 11:35:14Z scribe $
7  *
8  * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #ifndef SWCONFIG_H
25 #define SWCONFIG_H
26 
27 #include <map>
28 
29 #include <defs.h>
30 #include <multimapwdef.h>
31 #include <swbuf.h>
32 
34 
36 typedef std::map < SWBuf, ConfigEntMap, std::less < SWBuf > >SectionMap;
37 
42 public:
50  SWConfig(const char *fileName);
51  SWConfig();
52  virtual ~SWConfig();
53 
56  virtual SectionMap &getSections();
57  const SectionMap &getSections() const { return const_cast<SWConfig *>(this)->getSections(); }
58 
61  virtual void load();
62 
65  virtual void save() const;
66 
70  virtual void augment(const SWConfig &addFrom);
71 
76  ConfigEntMap &getSection(const char *section) { return getSections()[section]; }
77 
78 
91  ConfigEntMap &operator [](const char *section) { return getSection(section); }
92 
95  SWConfig &operator +=(const SWConfig &addFrom) { augment(addFrom); return *this; }
96 
102  SWBuf getValue(const char *section, const char *key) {
103  return (*this)[section][key];
104  }
105 
111  void setValue(const char *section, const char *key, const char *value) {
112  (*this)[section][key] = value;
113  }
114 
117  SWBuf getFileName() const;
118 
119 
120  // ****** Deprecated methods for removal in 2.0
121 
126 
131 
135  SWDEPRECATED void Load() { load(); }
136 
140  SWDEPRECATED void Save() { save(); }
141 
142 };
144 #endif
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
SWBuf getValue(const char *section, const char *key)
Definition: swconfig.h:102
#define SWDLLEXPORT
Definition: defs.h:171
void setValue(const char *section, const char *key, const char *value)
Definition: swconfig.h:111
SWDEPRECATED void Save()
Definition: swconfig.h:140
SWDEPRECATED void Load()
Definition: swconfig.h:135
#define SWDEPRECATED
Definition: defs.h:174
SWDEPRECATED SectionMap Sections
Definition: swconfig.h:125
ConfigEntMap & getSection(const char *section)
Definition: swconfig.h:76
std::map< SWBuf, ConfigEntMap, std::less< SWBuf > > SectionMap
Definition: swconfig.h:36
SWDEPRECATED SWBuf filename
Definition: swconfig.h:130
SWORD_NAMESPACE_START typedef multimapwithdefault< SWBuf, SWBuf, std::less< SWBuf > > ConfigEntMap
Definition: swconfig.h:35
const SectionMap & getSections() const
Definition: swconfig.h:57
#define SWORD_NAMESPACE_END
Definition: defs.h:40