Setting.h revision fce4895d
1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2011-2013, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef SETTING_H
7#define SETTING_H
8
9
10#include <String.h>
11
12#include <ObjectList.h>
13#include <Referenceable.h>
14#include <Variant.h>
15
16
17enum setting_type {
18	SETTING_TYPE_BOOL,
19	SETTING_TYPE_FLOAT,
20	SETTING_TYPE_OPTIONS,
21	SETTING_TYPE_BOUNDED,
22	SETTING_TYPE_RANGE,
23	SETTING_TYPE_RECT
24};
25
26
27class Setting : public BReferenceable {
28public:
29	virtual						~Setting();
30
31	virtual	setting_type		Type() const = 0;
32	virtual	const char*			ID() const = 0;
33	virtual	const char*			Name() const = 0;
34
35	virtual	BVariant			DefaultValue() const = 0;
36};
37
38
39class BoolSetting : public virtual Setting {
40public:
41	virtual	setting_type		Type() const;
42
43	virtual	BVariant			DefaultValue() const;
44
45	virtual	bool				DefaultBoolValue() const = 0;
46};
47
48
49class FloatSetting : public virtual Setting {
50public:
51	virtual	setting_type		Type() const;
52
53	virtual	BVariant			DefaultValue() const;
54
55	virtual	float				DefaultFloatValue() const = 0;
56};
57
58
59class SettingsOption : public BReferenceable {
60public:
61	virtual						~SettingsOption();
62
63	virtual	const char*			ID() const = 0;
64	virtual	const char*			Name() const = 0;
65};
66
67
68class OptionsSetting : public virtual Setting {
69public:
70	virtual	setting_type		Type() const;
71
72	virtual	BVariant			DefaultValue() const;
73
74	virtual	int32				CountOptions() const = 0;
75	virtual	SettingsOption*		OptionAt(int32 index) const = 0;
76	virtual	SettingsOption*		OptionByID(const char* id) const = 0;
77
78	virtual	SettingsOption*		DefaultOption() const = 0;
79};
80
81
82class BoundedSetting : public virtual Setting {
83public:
84	virtual	setting_type		Type() const;
85
86	virtual	BVariant			LowerBound() const = 0;
87	virtual	BVariant			UpperBound() const = 0;
88};
89
90
91class RangeSetting : public virtual BoundedSetting {
92	virtual	setting_type		Type() const;
93
94	virtual	BVariant			LowerValue() const = 0;
95	virtual	BVariant			UpperValue() const = 0;
96};
97
98
99class RectSetting : public virtual Setting {
100public:
101	virtual	setting_type		Type() const;
102
103	virtual	BVariant			DefaultValue() const;
104
105	virtual	BRect				DefaultRectValue() const = 0;
106};
107
108
109class AbstractSetting : public virtual Setting {
110public:
111								AbstractSetting(const BString& id,
112									const BString& name);
113
114	virtual	const char*			ID() const;
115	virtual	const char*			Name() const;
116
117private:
118			BString				fID;
119			BString				fName;
120};
121
122
123class BoolSettingImpl : public AbstractSetting, public BoolSetting {
124public:
125								BoolSettingImpl(const BString& id,
126									const BString& name, bool defaultValue);
127
128	virtual	bool				DefaultBoolValue() const;
129
130private:
131			bool				fDefaultValue;
132};
133
134
135class FloatSettingImpl : public AbstractSetting, public FloatSetting {
136public:
137								FloatSettingImpl(const BString& id,
138									const BString& name, float defaultValue);
139
140	virtual	float				DefaultFloatValue() const;
141
142private:
143			float				fDefaultValue;
144};
145
146
147class OptionsSettingImpl : public AbstractSetting, public OptionsSetting {
148public:
149								OptionsSettingImpl(const BString& id,
150									const BString& name);
151	virtual						~OptionsSettingImpl();
152
153	virtual	SettingsOption*		DefaultOption() const;
154
155	virtual	int32				CountOptions() const;
156	virtual	SettingsOption*		OptionAt(int32 index) const;
157	virtual	SettingsOption*		OptionByID(const char* id) const;
158
159			bool				AddOption(SettingsOption* option);
160			bool				AddOption(const BString& id,
161									const BString& name);
162
163			void				SetDefaultOption(SettingsOption* option);
164
165private:
166			class Option;
167
168			typedef BObjectList<SettingsOption> OptionList;
169
170private:
171			OptionList			fOptions;
172			SettingsOption*		fDefaultOption;
173};
174
175
176class BoundedSettingImpl : public AbstractSetting, public BoundedSetting {
177public:
178								BoundedSettingImpl(const BString& id,
179									const BString& name,
180									const BVariant& lowerBound,
181									const BVariant& upperBound,
182									const BVariant& defaultValue);
183
184	virtual	BVariant			DefaultValue() const;
185
186	virtual	BVariant			LowerBound() const;
187	virtual	BVariant			UpperBound() const;
188
189private:
190			BVariant			fLowerBound;
191			BVariant			fUpperBound;
192			BVariant			fDefaultValue;
193};
194
195
196class RangeSettingImpl : public AbstractSetting, public RangeSetting {
197public:
198								RangeSettingImpl(const BString& id,
199									const BString& name,
200									const BVariant& lowerBound,
201									const BVariant& upperBound,
202									const BVariant& lowerValue,
203									const BVariant& upperValue);
204
205	virtual	BVariant			DefaultValue() const;
206
207	virtual BVariant			LowerBound() const;
208	virtual	BVariant			UpperBound() const;
209	virtual BVariant			LowerValue() const;
210	virtual BVariant			UpperValue() const;
211
212private:
213			BVariant			fLowerBound;
214			BVariant			fUpperBound;
215			BVariant			fLowerValue;
216			BVariant			fUpperValue;
217};
218
219
220class RectSettingImpl : public AbstractSetting, public RectSetting {
221public:
222								RectSettingImpl(const BString& id,
223									const BString& name,
224									const BRect& defaultValue);
225
226	virtual	BRect				DefaultRectValue() const;
227
228private:
229			BRect				fDefaultValue;
230};
231
232
233#endif	// SETTING_H
234