tcp: Add APICall trace entry and move TRACEs into locked parts.
[haiku.git] / src / add-ons / screen_savers / slideshowsaver / LiveSetting.cpp
blobdf0a63128f838b682a6d4825625326524f950ef6
1 /*****************************************************************************/
2 // LiveSetting
3 // Written by Michael Wilber
4 //
5 // LiveSetting.cpp
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 //
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"
34 void
35 LiveSetting::Init(uint32 id, const char *name, const LiveSettingType dataType)
37 fId = id;
38 fName = name;
39 fDataType = dataType;
42 LiveSetting::LiveSetting(uint32 id, const char *name, bool val)
44 Init(id, name, LIVE_SETTING_BOOL);
45 fBoolVal = val;
48 LiveSetting::LiveSetting(uint32 id, const char *name, int32 val)
50 Init(id, name, LIVE_SETTING_INT32);
51 fInt32Val = val;
54 LiveSetting::LiveSetting(uint32 id, const char *name, const char *val)
56 Init(id, name, LIVE_SETTING_STRING);
57 fCharpVal = val;
60 bool
61 LiveSetting::AddReplaceValue(BMessage *msgTo, BMessage *msgFrom /*= NULL*/) const
63 bool bResult = false;
65 switch (fDataType) {
66 case LIVE_SETTING_BOOL:
68 bool bVal;
69 if (GetValue(msgFrom, bVal) == true)
70 return AddReplaceValue(msgTo, bVal);
72 case LIVE_SETTING_INT32:
74 int32 iVal;
75 if (GetValue(msgFrom, iVal) == true)
76 return AddReplaceValue(msgTo, iVal);
78 case LIVE_SETTING_STRING:
80 BString str;
81 if (GetValue(msgFrom, str) == true)
82 return AddReplaceValue(msgTo, str);
84 default:
85 break;
88 return bResult;
91 bool
92 LiveSetting::AddReplaceValue(BMessage *msgTo, bool val) const
94 if (msgTo == NULL)
95 return false;
97 bool bResult = false;
98 bool dummy;
99 if (msgTo->FindBool(fName, &dummy) == B_OK) {
100 if (msgTo->ReplaceBool(fName, val) == B_OK)
101 bResult = true;
102 } else {
103 if (msgTo->AddBool(fName, val) == B_OK)
104 bResult = true;
107 return bResult;
110 bool
111 LiveSetting::AddReplaceValue(BMessage *msgTo, int32 val) const
113 if (msgTo == NULL)
114 return false;
116 bool bResult = false;
117 int32 dummy;
118 if (msgTo->FindInt32(fName, &dummy) == B_OK) {
119 if (msgTo->ReplaceInt32(fName, val) == B_OK)
120 bResult = true;
121 } else {
122 if (msgTo->AddInt32(fName, val) == B_OK)
123 bResult = true;
126 return bResult;
129 bool
130 LiveSetting::AddReplaceValue(BMessage *msgTo, const BString &val) const
132 if (msgTo == NULL)
133 return false;
135 bool bResult = false;
136 BString dummy;
137 if (msgTo->FindString(fName, &dummy) == B_OK) {
138 if (msgTo->ReplaceString(fName, val) == B_OK)
139 bResult = true;
140 } else {
141 if (msgTo->AddString(fName, val) == B_OK)
142 bResult = true;
145 return bResult;
148 bool
149 LiveSetting::GetValue(BMessage *msgFrom, bool &val) const
151 if (fDataType != LIVE_SETTING_BOOL)
152 return false;
154 bool bResult = false;
155 if (msgFrom == NULL) {
156 val = fBoolVal;
157 bResult = true;
159 } else if (msgFrom->FindBool(fName, &val) == B_OK)
160 bResult = true;
162 return bResult;
165 bool
166 LiveSetting::GetValue(BMessage *msgFrom, int32 &val) const
168 if (fDataType != LIVE_SETTING_INT32)
169 return false;
171 bool bResult = false;
172 if (msgFrom == NULL) {
173 val = fInt32Val;
174 bResult = true;
176 } else if (msgFrom->FindInt32(fName, &val) == B_OK)
177 bResult = true;
179 return bResult;
182 bool
183 LiveSetting::GetValue(BMessage *msgFrom, BString &val) const
185 if (fDataType != LIVE_SETTING_STRING)
186 return false;
188 bool bResult = false;
189 if (msgFrom == NULL) {
190 val = fCharpVal;
191 bResult = true;
193 } else if (msgFrom->FindString(fName, &val) == B_OK)
194 bResult = true;
196 return bResult;