1 /*****************************************************************************/
3 // Written by Michael Wilber
7 // This class stores the default value for an individual setting and provides
8 // functions which read and write the setting to BMessages.
11 // Copyright (C) Haiku
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:
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
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 /*****************************************************************************/
32 #include "LiveSetting.h"
35 LiveSetting::Init(uint32 id
, const char *name
, const LiveSettingType dataType
)
42 LiveSetting::LiveSetting(uint32 id
, const char *name
, bool val
)
44 Init(id
, name
, LIVE_SETTING_BOOL
);
48 LiveSetting::LiveSetting(uint32 id
, const char *name
, int32 val
)
50 Init(id
, name
, LIVE_SETTING_INT32
);
54 LiveSetting::LiveSetting(uint32 id
, const char *name
, const char *val
)
56 Init(id
, name
, LIVE_SETTING_STRING
);
61 LiveSetting::AddReplaceValue(BMessage
*msgTo
, BMessage
*msgFrom
/*= NULL*/) const
66 case LIVE_SETTING_BOOL
:
69 if (GetValue(msgFrom
, bVal
) == true)
70 return AddReplaceValue(msgTo
, bVal
);
72 case LIVE_SETTING_INT32
:
75 if (GetValue(msgFrom
, iVal
) == true)
76 return AddReplaceValue(msgTo
, iVal
);
78 case LIVE_SETTING_STRING
:
81 if (GetValue(msgFrom
, str
) == true)
82 return AddReplaceValue(msgTo
, str
);
92 LiveSetting::AddReplaceValue(BMessage
*msgTo
, bool val
) const
99 if (msgTo
->FindBool(fName
, &dummy
) == B_OK
) {
100 if (msgTo
->ReplaceBool(fName
, val
) == B_OK
)
103 if (msgTo
->AddBool(fName
, val
) == B_OK
)
111 LiveSetting::AddReplaceValue(BMessage
*msgTo
, int32 val
) const
116 bool bResult
= false;
118 if (msgTo
->FindInt32(fName
, &dummy
) == B_OK
) {
119 if (msgTo
->ReplaceInt32(fName
, val
) == B_OK
)
122 if (msgTo
->AddInt32(fName
, val
) == B_OK
)
130 LiveSetting::AddReplaceValue(BMessage
*msgTo
, const BString
&val
) const
135 bool bResult
= false;
137 if (msgTo
->FindString(fName
, &dummy
) == B_OK
) {
138 if (msgTo
->ReplaceString(fName
, val
) == B_OK
)
141 if (msgTo
->AddString(fName
, val
) == B_OK
)
149 LiveSetting::GetValue(BMessage
*msgFrom
, bool &val
) const
151 if (fDataType
!= LIVE_SETTING_BOOL
)
154 bool bResult
= false;
155 if (msgFrom
== NULL
) {
159 } else if (msgFrom
->FindBool(fName
, &val
) == B_OK
)
166 LiveSetting::GetValue(BMessage
*msgFrom
, int32
&val
) const
168 if (fDataType
!= LIVE_SETTING_INT32
)
171 bool bResult
= false;
172 if (msgFrom
== NULL
) {
176 } else if (msgFrom
->FindInt32(fName
, &val
) == B_OK
)
183 LiveSetting::GetValue(BMessage
*msgFrom
, BString
&val
) const
185 if (fDataType
!= LIVE_SETTING_STRING
)
188 bool bResult
= false;
189 if (msgFrom
== NULL
) {
193 } else if (msgFrom
->FindString(fName
, &val
) == B_OK
)