1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2011-2016, Rene Gollent, rene@gollent.com. 4 * Distributed under the terms of the MIT License. 5 */ 6 #ifndef SETTING_H 7 #define SETTING_H 8 9 10 #include <String.h> 11 12 #include <ObjectList.h> 13 #include <Referenceable.h> 14 #include <Variant.h> 15 16 17 enum setting_type { 18 SETTING_TYPE_BOOL, 19 SETTING_TYPE_FLOAT, 20 SETTING_TYPE_OPTIONS, 21 SETTING_TYPE_BOUNDED, 22 SETTING_TYPE_RANGE, 23 SETTING_TYPE_RECT, 24 SETTING_TYPE_STRING 25 }; 26 27 28 class Setting : public BReferenceable { 29 public: 30 virtual ~Setting(); 31 32 virtual setting_type Type() const = 0; 33 virtual const char* ID() const = 0; 34 virtual const char* Name() const = 0; 35 36 virtual BVariant DefaultValue() const = 0; 37 }; 38 39 40 class BoolSetting : public virtual Setting { 41 public: 42 virtual setting_type Type() const; 43 44 virtual BVariant DefaultValue() const; 45 46 virtual bool DefaultBoolValue() const = 0; 47 }; 48 49 50 class FloatSetting : public virtual Setting { 51 public: 52 virtual setting_type Type() const; 53 54 virtual BVariant DefaultValue() const; 55 56 virtual float DefaultFloatValue() const = 0; 57 }; 58 59 60 class SettingsOption : public BReferenceable { 61 public: 62 virtual ~SettingsOption(); 63 64 virtual const char* ID() const = 0; 65 virtual const char* Name() const = 0; 66 }; 67 68 69 class OptionsSetting : public virtual Setting { 70 public: 71 virtual setting_type Type() const; 72 73 virtual BVariant DefaultValue() const; 74 75 virtual int32 CountOptions() const = 0; 76 virtual SettingsOption* OptionAt(int32 index) const = 0; 77 virtual SettingsOption* OptionByID(const char* id) const = 0; 78 79 virtual SettingsOption* DefaultOption() const = 0; 80 }; 81 82 83 class BoundedSetting : public virtual Setting { 84 public: 85 virtual setting_type Type() const; 86 87 virtual BVariant LowerBound() const = 0; 88 virtual BVariant UpperBound() const = 0; 89 }; 90 91 92 class RangeSetting : public virtual BoundedSetting { 93 virtual setting_type Type() const; 94 95 virtual BVariant LowerValue() const = 0; 96 virtual BVariant UpperValue() const = 0; 97 }; 98 99 100 class RectSetting : public virtual Setting { 101 public: 102 virtual setting_type Type() const; 103 104 virtual BVariant DefaultValue() const; 105 106 virtual BRect DefaultRectValue() const = 0; 107 }; 108 109 110 class StringSetting : public virtual Setting { 111 public: 112 virtual setting_type Type() const; 113 114 virtual BVariant DefaultValue() const; 115 116 virtual const BString& DefaultStringValue() const = 0; 117 }; 118 119 120 class AbstractSetting : public virtual Setting { 121 public: 122 AbstractSetting(const BString& id, 123 const BString& name); 124 125 virtual const char* ID() const; 126 virtual const char* Name() const; 127 128 private: 129 BString fID; 130 BString fName; 131 }; 132 133 134 class BoolSettingImpl : public AbstractSetting, public BoolSetting { 135 public: 136 BoolSettingImpl(const BString& id, 137 const BString& name, bool defaultValue); 138 139 virtual bool DefaultBoolValue() const; 140 141 private: 142 bool fDefaultValue; 143 }; 144 145 146 class FloatSettingImpl : public AbstractSetting, public FloatSetting { 147 public: 148 FloatSettingImpl(const BString& id, 149 const BString& name, float defaultValue); 150 151 virtual float DefaultFloatValue() const; 152 153 private: 154 float fDefaultValue; 155 }; 156 157 158 class OptionsSettingImpl : public AbstractSetting, public OptionsSetting { 159 public: 160 OptionsSettingImpl(const BString& id, 161 const BString& name); 162 virtual ~OptionsSettingImpl(); 163 164 virtual SettingsOption* DefaultOption() const; 165 166 virtual int32 CountOptions() const; 167 virtual SettingsOption* OptionAt(int32 index) const; 168 virtual SettingsOption* OptionByID(const char* id) const; 169 170 bool AddOption(SettingsOption* option); 171 bool AddOption(const BString& id, 172 const BString& name); 173 174 void SetDefaultOption(SettingsOption* option); 175 176 private: 177 class Option; 178 179 typedef BObjectList<SettingsOption> OptionList; 180 181 private: 182 OptionList fOptions; 183 SettingsOption* fDefaultOption; 184 }; 185 186 187 class BoundedSettingImpl : public AbstractSetting, public BoundedSetting { 188 public: 189 BoundedSettingImpl(const BString& id, 190 const BString& name, 191 const BVariant& lowerBound, 192 const BVariant& upperBound, 193 const BVariant& defaultValue); 194 195 virtual BVariant DefaultValue() const; 196 197 virtual BVariant LowerBound() const; 198 virtual BVariant UpperBound() const; 199 200 private: 201 BVariant fLowerBound; 202 BVariant fUpperBound; 203 BVariant fDefaultValue; 204 }; 205 206 207 class RangeSettingImpl : public AbstractSetting, public RangeSetting { 208 public: 209 RangeSettingImpl(const BString& id, 210 const BString& name, 211 const BVariant& lowerBound, 212 const BVariant& upperBound, 213 const BVariant& lowerValue, 214 const BVariant& upperValue); 215 216 virtual BVariant DefaultValue() const; 217 218 virtual BVariant LowerBound() const; 219 virtual BVariant UpperBound() const; 220 virtual BVariant LowerValue() const; 221 virtual BVariant UpperValue() const; 222 223 private: 224 BVariant fLowerBound; 225 BVariant fUpperBound; 226 BVariant fLowerValue; 227 BVariant fUpperValue; 228 }; 229 230 231 class RectSettingImpl : public AbstractSetting, public RectSetting { 232 public: 233 RectSettingImpl(const BString& id, 234 const BString& name, 235 const BRect& defaultValue); 236 237 virtual BRect DefaultRectValue() const; 238 239 private: 240 BRect fDefaultValue; 241 }; 242 243 244 class StringSettingImpl : public AbstractSetting, public StringSetting { 245 public: 246 StringSettingImpl(const BString& id, 247 const BString& name, 248 const BString& defaultValue); 249 250 virtual const BString& DefaultStringValue() const; 251 252 private: 253 BString fDefaultValue; 254 }; 255 256 257 #endif // SETTING_H 258