]> icculus.org git repositories - dana/openbox.git/blob - src/configuration.hh
dont have any languages yet
[dana/openbox.git] / src / configuration.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __Configuration_hh
3 #define   __Configuration_hh
4
5 #include <X11/Xlib.h>
6 #include <X11/Xresource.h>
7 #include <string>
8
9 /*
10  * The Configuration class is a generic wrapper for configuration settings.
11  *
12  * This class is used for the global rc/config file, and for styles.
13  *
14  * This implementation of the Configuration class wraps an X resource database
15  * file.
16  */
17 class Configuration {
18 public:
19   explicit Configuration(const std::string &file, bool autosave = True);
20   Configuration(bool autosave = True);
21   virtual ~Configuration();
22
23   inline const std::string &file() const {
24     return static_cast<const std::string &>(_file);
25   }
26   void setFile(const std::string &file);
27
28   // defaults to true!
29   inline bool autoSave() const {
30     return _autosave;
31   }
32   void setAutoSave(bool);
33
34   inline bool isModified() const {
35     return _modified;
36   }
37
38   void save();
39   bool load();
40   bool merge(const std::string &file, bool overwrite = False);
41   void create();
42
43   void setValue(const std::string &rname, bool value);
44   inline void setValue(const std::string &rname, int value) {
45     setValue(rname, (long) value);
46   }
47   inline void setValue(const std::string &rname, unsigned int value) {
48     setValue(rname, (unsigned long) value);
49   }
50   void setValue(const std::string &rname, long value);
51   void setValue(const std::string &rname, unsigned long value);
52   void setValue(const std::string &rname, const std::string &value);
53   void setValue(const std::string &rname, const char *value);
54
55   bool getValue(const std::string &rname, bool &value) const;
56   inline bool getValue(const std::string &rname, int &value) const {
57     return getValue(rname, (long) value);
58   }
59   inline bool getValue(const std::string &rname, unsigned int &value) const {
60     return getValue(rname, (unsigned long) value);
61   }
62   bool getValue(const std::string &rname, long &value) const;
63   bool getValue(const std::string &rname, unsigned long &value) const;
64   bool getValue(const std::string &rname, std::string &value) const;
65
66 private:
67   std::string createClassName(const std::string &rname) const;
68   char toUpper(char) const;
69   
70   static bool _initialized;
71   std::string _file;
72   bool _modified;
73   bool _autosave;
74   XrmDatabase _database;
75 };
76
77 #endif // __Configuration_hh