2 * Copyright 2013-2016, Rene Gollent, rene@gollent.com.
3 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
13 // #pragma mark - Setting
21 // #pragma mark - BoolSetting
25 BoolSetting::Type() const
27 return SETTING_TYPE_BOOL
;
32 BoolSetting::DefaultValue() const
34 return DefaultBoolValue();
38 // #pragma mark - FloatSetting
42 FloatSetting::Type() const
44 return SETTING_TYPE_FLOAT
;
49 FloatSetting::DefaultValue() const
51 return DefaultFloatValue();
55 // #pragma mark - SettingsOption
58 SettingsOption::~SettingsOption()
63 // #pragma mark - OptionsSetting
67 OptionsSetting::Type() const
69 return SETTING_TYPE_OPTIONS
;
74 OptionsSetting::DefaultValue() const
76 SettingsOption
* option
= DefaultOption();
78 ? BVariant(option
->ID(), B_VARIANT_DONT_COPY_DATA
) : BVariant();
82 // #pragma mark - BoundedSetting
86 BoundedSetting::Type() const
88 return SETTING_TYPE_BOUNDED
;
92 // #pragma mark - RangeSetting
96 RangeSetting::Type() const
98 return SETTING_TYPE_RANGE
;
102 // #pragma mark - RectSetting
105 RectSetting::Type() const
107 return SETTING_TYPE_RECT
;
112 RectSetting::DefaultValue() const
114 return DefaultRectValue();
118 // #pragma mark - StringSetting
122 StringSetting::Type() const
124 return SETTING_TYPE_STRING
;
129 StringSetting::DefaultValue() const
131 return DefaultStringValue().String();
135 // #pragma mark - AbstractSetting
138 AbstractSetting::AbstractSetting(const BString
& id
, const BString
& name
)
147 AbstractSetting::ID() const
154 AbstractSetting::Name() const
160 // #pragma mark - BoolSettingImpl
163 BoolSettingImpl::BoolSettingImpl(const BString
& id
, const BString
& name
,
166 AbstractSetting(id
, name
),
167 fDefaultValue(defaultValue
)
173 BoolSettingImpl::DefaultBoolValue() const
175 return fDefaultValue
;
179 // #pragma mark - FloatSettingImpl
182 FloatSettingImpl::FloatSettingImpl(const BString
& id
, const BString
& name
,
185 AbstractSetting(id
, name
),
186 fDefaultValue(defaultValue
)
192 FloatSettingImpl::DefaultFloatValue() const
194 return fDefaultValue
;
198 // #pragma mark - OptionsSettingImpl
201 class OptionsSettingImpl::Option
: public SettingsOption
{
203 Option(const BString
& id
, const BString
& name
)
207 virtual const char* ID() const
212 virtual const char* Name() const
223 OptionsSettingImpl::OptionsSettingImpl(const BString
& id
, const BString
& name
)
225 AbstractSetting(id
, name
),
231 OptionsSettingImpl::~OptionsSettingImpl()
233 SetDefaultOption(NULL
);
235 for (int32 i
= 0; SettingsOption
* option
= fOptions
.ItemAt(i
); i
++)
236 option
->ReleaseReference();
241 OptionsSettingImpl::DefaultOption() const
243 return fDefaultOption
!= NULL
? fDefaultOption
: fOptions
.ItemAt(0);
248 OptionsSettingImpl::CountOptions() const
250 return fOptions
.CountItems();
255 OptionsSettingImpl::OptionAt(int32 index
) const
257 return fOptions
.ItemAt(index
);
262 OptionsSettingImpl::OptionByID(const char* id
) const
264 for (int32 i
= 0; SettingsOption
* option
= fOptions
.ItemAt(i
); i
++) {
265 if (strcmp(option
->ID(), id
) == 0)
274 OptionsSettingImpl::AddOption(SettingsOption
* option
)
276 if (!fOptions
.AddItem(option
))
279 option
->AcquireReference();
285 OptionsSettingImpl::AddOption(const BString
& id
, const BString
& name
)
287 Option
* option
= new(std::nothrow
) Option(id
, name
);
290 BReference
<Option
> optionReference(option
, true);
292 return AddOption(option
);
297 OptionsSettingImpl::SetDefaultOption(SettingsOption
* option
)
299 if (option
== fDefaultOption
)
302 if (fDefaultOption
!= NULL
)
303 fDefaultOption
->ReleaseReference();
305 fDefaultOption
= option
;
307 if (fDefaultOption
!= NULL
)
308 fDefaultOption
->AcquireReference();
312 // #pragma mark - RangeSettingImpl
315 BoundedSettingImpl::BoundedSettingImpl(const BString
& id
, const BString
& name
,
316 const BVariant
& lowerBound
, const BVariant
& upperBound
,
317 const BVariant
& defaultValue
)
319 AbstractSetting(id
, name
),
320 fLowerBound(lowerBound
),
321 fUpperBound(upperBound
),
322 fDefaultValue(defaultValue
)
328 BoundedSettingImpl::DefaultValue() const
330 return fDefaultValue
;
335 BoundedSettingImpl::LowerBound() const
342 BoundedSettingImpl::UpperBound() const
348 // #pragma mark - RangeSettingImpl
351 RangeSettingImpl::RangeSettingImpl(const BString
& id
, const BString
& name
,
352 const BVariant
& lowerBound
, const BVariant
& upperBound
,
353 const BVariant
& lowerValue
, const BVariant
& upperValue
)
355 AbstractSetting(id
, name
),
356 fLowerBound(lowerBound
),
357 fUpperBound(upperBound
),
358 fLowerValue(lowerValue
),
359 fUpperValue(upperValue
)
365 RangeSettingImpl::DefaultValue() const
367 // this one doesn't really make sense for RangeSetting since it
368 // describes a pair of values, which BVariant can't readily
375 RangeSettingImpl::LowerBound() const
382 RangeSettingImpl::UpperBound() const
389 RangeSettingImpl::LowerValue() const
396 RangeSettingImpl::UpperValue() const
402 // #pragma mark - RectSettingImpl
405 RectSettingImpl::RectSettingImpl(const BString
& id
, const BString
& name
,
406 const BRect
& defaultValue
)
408 AbstractSetting(id
, name
),
409 fDefaultValue(defaultValue
)
415 RectSettingImpl::DefaultRectValue() const
417 return fDefaultValue
;
421 // #pragma mark - StringSettingImpl
424 StringSettingImpl::StringSettingImpl(const BString
& id
, const BString
& name
,
425 const BString
& defaultValue
)
427 AbstractSetting(id
, name
),
428 fDefaultValue(defaultValue
)
434 StringSettingImpl::DefaultStringValue() const
436 return fDefaultValue
;