1 #ifndef SETTINGS_H 2 #define SETTINGS_H 3 4 #include "SettingsHandler.h" 5 6 void SetUpSettings(char* filename); 7 void QuitSettings(); 8 9 class StringValueSetting : public SettingsArgvDispatcher { 10 // simple string setting 11 public: 12 StringValueSetting(const char* name, 13 const char* defaultValue, 14 const char* valueExpectedErrorString, 15 const char* wrongValueErrorString = ""); 16 17 virtual ~StringValueSetting(); 18 19 void ValueChanged(const char* newValue); 20 const char* Value() const; 21 virtual const char* Handle(const char *const *argv); 22 23 protected: 24 virtual void SaveSettingValue(Settings*); 25 virtual bool NeedsSaving() const; 26 27 const char* fDefaultValue; 28 const char* fValueExpectedErrorString; 29 const char* fWrongValueErrorString; 30 char* fValue; 31 }; 32 33 34 // string setting, values that do not match string enumeration 35 // are rejected 36 class EnumeratedStringValueSetting : public StringValueSetting { 37 public: 38 // A pointer to a function returning a string for an index, or NULL 39 // if the index is out of bounds. 40 typedef const char* (*StringEnumerator)(int32); 41 42 EnumeratedStringValueSetting(const char* name, 43 const char* defaultValue, 44 StringEnumerator enumerator, 45 const char* valueExpectedErrorString, 46 const char* wrongValueErrorString); 47 48 void ValueChanged(const char* newValue); 49 virtual const char* Handle(const char *const *argv); 50 51 private: 52 bool _ValidateString(const char* string); 53 StringEnumerator fEnumerator; 54 }; 55 56 57 // simple int32 setting 58 class ScalarValueSetting : public SettingsArgvDispatcher { 59 public: 60 ScalarValueSetting(const char* name, 61 int32 defaultValue, 62 const char* valueExpectedErrorString, 63 const char* wrongValueErrorString, 64 int32 min = LONG_MIN, int32 max = LONG_MAX); 65 virtual ~ScalarValueSetting(); 66 67 void ValueChanged(int32 newValue); 68 int32 Value() const; 69 void GetValueAsString(char*) const; 70 virtual const char* Handle(const char *const *argv); 71 72 protected: 73 virtual void SaveSettingValue(Settings*); 74 virtual bool NeedsSaving() const; 75 76 int32 fDefaultValue; 77 int32 fValue; 78 int32 fMax; 79 int32 fMin; 80 const char* fValueExpectedErrorString; 81 const char* fWrongValueErrorString; 82 }; 83 84 85 class BooleanValueSetting : public ScalarValueSetting { 86 public: 87 BooleanValueSetting(const char* name, 88 bool defaultValue); 89 virtual ~BooleanValueSetting(); 90 91 bool Value() const; 92 virtual const char* Handle(const char *const *argv); 93 94 protected: 95 virtual void SaveSettingValue(Settings *); 96 }; 97 98 #endif // SETTINGS_H 99