1 /*
2  *  KCemu -- The emulator for the KC85 homecomputer series and much more.
3  *  Copyright (C) 1997-2010 Torsten Paul
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __kc_prefs_profile_h
21 #define __kc_prefs_profile_h
22 
23 #include <map>
24 #include <list>
25 #include <string>
26 
27 using namespace std;
28 
29 typedef enum {
30     PROFILE_LEVEL_ROOT = 0,
31     PROFILE_LEVEL_DEFAULT = 1,
32     PROFILE_LEVEL_SYSTEM = 2,
33     PROFILE_LEVEL_SYSTEM_USER = 3,
34     PROFILE_LEVEL_USER = 4,
35 } profile_level_t;
36 
37 class ProfileValue {
38 private:
39     typedef enum {
40         PROFILE_VALUE_TYPE_NULL = 0,
41         PROFILE_VALUE_TYPE_INT = 1,
42         PROFILE_VALUE_TYPE_STRING = 2,
43     } profile_value_type_t;
44 
45     profile_level_t _level;
46     profile_value_type_t _type;
47     int _int_value;
48     string _string_value;
49 
50 public:
51     ProfileValue(ProfileValue *value);
52     ProfileValue(profile_level_t level);
53     ProfileValue(profile_level_t level, int value);
54     ProfileValue(profile_level_t level, string value);
55     virtual ~ProfileValue(void);
56 
57     virtual profile_level_t get_level(void) const;
58 
59     bool equals(ProfileValue *value) const;
60 
61     virtual int get_int_value(void) const;
62     virtual const char * get_string_value(void) const;
63     virtual char * get_encoded_value(void) const;
64 };
65 
66 class Profile {
67 private:
68     typedef map<string, ProfileValue *> pref_map_t;
69 
70     bool _changed;
71     bool _deleted;
72     profile_level_t _level;
73     string _name;
74     string _config_name;
75     string _path;
76     Profile * _parent;
77     pref_map_t _pref_map;
78     pref_map_t _pref_map_old;
79 
80 protected:
81     void set_value_with_backup(string key, ProfileValue *value, ProfileValue *old_value);
82 
83 public:
84     Profile(profile_level_t level, string path, string config_name, string name);
85     virtual ~Profile(void);
86 
87     const char * get_name(void) const;
88     void set_name(string name);
89 
90     const char * get_config_name(void) const;
91 
92     profile_level_t get_level(void) const;
93     const char *get_path(void) const;
94 
95     bool is_changed(void) const;
96     void set_changed(bool changed);
97 
98     bool is_deleted(void) const;
99     void set_deleted(bool deleted);
100 
101     Profile *get_parent(void) const;
102     void set_parent(Profile *parent);
103 
104     const char * get_comment(void) const;
105 
106     ProfileValue * get_value(string key) const;
107     char * get_encoded_value(string key) const;
108     void set_value(string key, ProfileValue *value);
109 
110     void reject_changes(void);
111 
112     int get_int_value(string key, int default_value) const;
113     void set_int_value(string key, int value);
114 
115     const char * get_string_value(string key, const char *default_value) const;
116     void set_string_value(string key, string value);
117 
118     void set_null_value(string key);
119     void remove_value(string key);
120     bool contains_key(string key) const;
121     list<string> * get_keys(void);
122 };
123 
124 #endif /* __kc_prefs_profile_h */
125