xref: /haiku/headers/private/debugger/settings/generic/Settings.h (revision faf79e7f783976326856422ff006b4c6ae9c3031)
1 /*
2  * Copyright 2013, Rene Gollent, rene@gollent.com.
3  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef SETTINGS_H
7 #define SETTINGS_H
8 
9 
10 #include <Locker.h>
11 #include <Message.h>
12 
13 #include <ObjectList.h>
14 #include <Referenceable.h>
15 #include <Variant.h>
16 
17 #include "Setting.h"
18 
19 
20 class SettingsDescription;
21 
22 
23 class Settings : public BReferenceable {
24 public:
25 	class Listener;
26 
27 public:
28 								Settings(SettingsDescription* description);
29 	virtual						~Settings();
30 
31 			status_t			Init();
32 
33 			bool				Lock()		{ return fLock.Lock(); }
34 			void				Unlock()	{ fLock.Unlock(); }
35 
36 			SettingsDescription* Description() const	{ return fDescription; }
37 			const BMessage&		Message() const			{ return fValues; }
38 
39 			BVariant			Value(Setting* setting) const;
40 			BVariant			Value(const char* settingID) const;
41 			bool				SetValue(Setting* setting,
42 									const BVariant& value);
43 
44 			bool				RestoreValues(const BMessage& message);
45 
46 			bool				BoolValue(BoolSetting* setting) const
47 									{ return Value(setting).ToBool(); }
48 			SettingsOption*		OptionValue(OptionsSetting* setting) const;
49 			BVariant			RangeValue(RangeSetting* setting) const
50 									{ return Value(setting); }
51 
52 			bool				AddListener(Listener* listener);
53 			void				RemoveListener(Listener* listener);
54 
55 private:
56 			typedef BObjectList<Listener> ListenerList;
57 
58 private:
59 	mutable	BLocker				fLock;
60 			SettingsDescription* fDescription;
61 			BMessage			fValues;
62 			ListenerList		fListeners;
63 };
64 
65 
66 class Settings::Listener {
67 public:
68 	virtual						~Listener();
69 
70 	virtual	void				SettingValueChanged(Setting* setting) = 0;
71 };
72 
73 
74 #endif	// SETTINGS_H
75