1/*****************************************************************************/
2// LiveSetting
3// Written by Michael Wilber
4//
5// LiveSetting.h
6//
7// This class stores the default value for an individual setting and provides
8// functions which read and write the setting to BMessages.
9//
10//
11// Copyright (C) Haiku
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30/*****************************************************************************/
31
32#ifndef LIVE_SETTING_H
33#define LIVE_SETTING_H
34
35#include <Locker.h>
36#include <Path.h>
37#include <Message.h>
38#include <String.h>
39#include <vector>
40#include "LiveSettingsObserver.h"
41
42class LiveSetting {
43public:
44	LiveSetting(uint32 id, const char *name, bool val);
45	LiveSetting(uint32 id, const char *name, int32 val);
46	LiveSetting(uint32 id, const char *name, const char *val);
47	~LiveSetting() { }
48
49	uint32 GetId() const { return fId; }
50	const char *GetName() const { return fName; }
51
52	bool AddReplaceValue(BMessage *msgTo, BMessage *msgFrom = NULL) const;
53
54	bool AddReplaceValue(BMessage *msgTo, bool val) const;
55	bool AddReplaceValue(BMessage *msgTo, int32 val) const;
56	bool AddReplaceValue(BMessage *msgTo, const BString &val) const;
57
58	bool GetValue(BMessage *msgFrom, bool &val) const;
59	bool GetValue(BMessage *msgFrom, int32 &val) const;
60	bool GetValue(BMessage *msgFrom, BString &val) const;
61
62private:
63	enum LiveSettingType {
64		LIVE_SETTING_BOOL = 0,
65		LIVE_SETTING_INT32,
66		LIVE_SETTING_STRING
67	};
68
69	void Init(uint32 id, const char *name, const LiveSettingType dataType);
70
71	uint32 fId;
72	const char *fName;
73	LiveSettingType fDataType;
74	union {
75		bool fBoolVal;
76		int32 fInt32Val;
77		const char *fCharpVal;
78	};
79};
80
81#endif // #ifndef LIVE_SETTING_H
82
83
84