From 4924e2e9ae8572ce0de351cff33f3422b13513ea Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 5 Nov 2009 17:32:16 +0000 Subject: [PATCH] Classes to describe settings in a generic way. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33903 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../debugger/settings/generic/Setting.cpp | 265 ++++++++++++++++++ src/apps/debugger/settings/generic/Setting.h | 152 ++++++++++ .../debugger/settings/generic/Settings.cpp | 115 ++++++++ src/apps/debugger/settings/generic/Settings.h | 71 +++++ .../settings/generic/SettingsDescription.cpp | 58 ++++ .../settings/generic/SettingsDescription.h | 35 +++ 6 files changed, 696 insertions(+) create mode 100644 src/apps/debugger/settings/generic/Setting.cpp create mode 100644 src/apps/debugger/settings/generic/Setting.h create mode 100644 src/apps/debugger/settings/generic/Settings.cpp create mode 100644 src/apps/debugger/settings/generic/Settings.h create mode 100644 src/apps/debugger/settings/generic/SettingsDescription.cpp create mode 100644 src/apps/debugger/settings/generic/SettingsDescription.h diff --git a/src/apps/debugger/settings/generic/Setting.cpp b/src/apps/debugger/settings/generic/Setting.cpp new file mode 100644 index 0000000000..9f4b126fad --- /dev/null +++ b/src/apps/debugger/settings/generic/Setting.cpp @@ -0,0 +1,265 @@ +/* + * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "Setting.h" + +#include + + +// #pragma mark - Setting + + +Setting::~Setting() +{ +} + + +// #pragma mark - BoolSetting + + +setting_type +BoolSetting::Type() const +{ + return SETTING_TYPE_BOOL; +} + + +BVariant +BoolSetting::DefaultValue() const +{ + return DefaultBoolValue(); +} + + +// #pragma mark - SettingsOption + + +SettingsOption::~SettingsOption() +{ +} + + +// #pragma mark - OptionsSetting + + +setting_type +OptionsSetting::Type() const +{ + return SETTING_TYPE_OPTIONS; +} + + +BVariant +OptionsSetting::DefaultValue() const +{ + SettingsOption* option = DefaultOption(); + return option != NULL + ? BVariant(option->ID(), B_VARIANT_DONT_COPY_DATA) : BVariant(); +} + + +// #pragma mark - RangeSetting + + +setting_type +RangeSetting::Type() const +{ + return SETTING_TYPE_RANGE; +} + + +// #pragma mark - AbstractSetting + + +AbstractSetting::AbstractSetting(const BString& id, const BString& name) + : + fID(id), + fName(name) +{ +} + + +const char* +AbstractSetting::ID() const +{ + return fID; +} + + +const char* +AbstractSetting::Name() const +{ + return fName; +} + + +// #pragma mark - BoolSettingImpl + + +BoolSettingImpl::BoolSettingImpl(const BString& id, const BString& name, + bool defaultValue) + : + AbstractSetting(id, name), + fDefaultValue(defaultValue) +{ +} + + +bool +BoolSettingImpl::DefaultBoolValue() const +{ + return fDefaultValue; +} + + +// #pragma mark - OptionsSettingImpl + + +class OptionsSettingImpl::Option : public SettingsOption { +public: + Option(const BString& id, const BString& name) + { + } + + virtual const char* ID() const + { + return fID; + } + + virtual const char* Name() const + { + return fName; + } + +private: + BString fID; + BString fName; +}; + + +OptionsSettingImpl::OptionsSettingImpl(const BString& id, const BString& name) + : + AbstractSetting(id, name), + fDefaultOption(NULL) +{ +} + + +OptionsSettingImpl::~OptionsSettingImpl() +{ + SetDefaultOption(NULL); + + for (int32 i = 0; SettingsOption* option = fOptions.ItemAt(i); i++) + option->ReleaseReference(); +} + + +SettingsOption* +OptionsSettingImpl::DefaultOption() const +{ + return fDefaultOption != NULL ? fDefaultOption : fOptions.ItemAt(0); +} + + +int32 +OptionsSettingImpl::CountOptions() const +{ + return fOptions.CountItems(); +} + + +SettingsOption* +OptionsSettingImpl::OptionAt(int32 index) const +{ + return fOptions.ItemAt(index); +} + + +SettingsOption* +OptionsSettingImpl::OptionByID(const char* id) const +{ + for (int32 i = 0; SettingsOption* option = fOptions.ItemAt(i); i++) { + if (strcmp(option->ID(), id) == 0) + return option; + } + + return NULL; +} + + +bool +OptionsSettingImpl::AddOption(SettingsOption* option) +{ + if (!fOptions.AddItem(option)) + return false; + + option->AddReference(); + return true; +} + + +bool +OptionsSettingImpl::AddOption(const BString& id, const BString& name) +{ + Option* option = new(std::nothrow) Option(id, name); + if (option == NULL) + return false; + Reference