BsSettings.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsIReflectable.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Contains a serializable set of generic key-value pairs.
  8. */
  9. class BS_ED_EXPORT Settings : public IReflectable
  10. {
  11. public:
  12. Settings();
  13. /**
  14. * @brief Adds or updates a property key/value pair with a floating point value.
  15. */
  16. void setFloat(const String& name, float value);
  17. /**
  18. * @brief Adds or updates a property key/value pair with a signed integer value.
  19. */
  20. void setInt(const String& name, INT32 value);
  21. /**
  22. * @brief Adds or updates a property key/value pair with a boolean value.
  23. */
  24. void setBool(const String& name, bool value);
  25. /**
  26. * @brief Adds or updates a property key/value pair with a string value.
  27. */
  28. void setString(const String& name, const WString& value);
  29. /**
  30. * @brief Returns the floating point value of the specified key, or the default value
  31. * if such key cannot be found.
  32. */
  33. float getFloat(const String& name, float defaultValue = 0.0f);
  34. /**
  35. * @brief Returns the integer point value of the specified key, or the default value
  36. * if such key cannot be found.
  37. */
  38. INT32 getInt(const String& name, INT32 defaultValue = 0);
  39. /**
  40. * @brief Returns the boolean point value of the specified key, or the default value
  41. * if such key cannot be found.
  42. */
  43. bool getBool(const String& name, bool defaultValue = false);
  44. /**
  45. * @brief Returns the string point value of the specified key, or the default value
  46. * if such key cannot be found.
  47. */
  48. WString getString(const String& name, const WString& defaultValue = StringUtil::WBLANK);
  49. /**
  50. * @brief Returns true if the key with the specified name exists.
  51. */
  52. bool hasKey(const String& name);
  53. /**
  54. * @brief Deletes a key with the specified name.
  55. */
  56. void deleteKey(const String& name);
  57. /**
  58. * @brief Deletes all key/value pairs.
  59. */
  60. void deleteAllKeys();
  61. /**
  62. * @brief Returns a hash value that may be used for checking if any internal settings were
  63. * modified.
  64. */
  65. UINT32 getHash() const { return mHash; }
  66. protected:
  67. /**
  68. * @brief Marks the object as dirty so that outside objects know when to update.
  69. */
  70. void markAsDirty() const { mHash++; }
  71. Map<String, float> mFloatProperties;
  72. Map<String, INT32> mIntProperties;
  73. Map<String, bool> mBoolProperties;
  74. Map<String, WString> mStringProperties;
  75. mutable UINT32 mHash;
  76. /************************************************************************/
  77. /* RTTI */
  78. /************************************************************************/
  79. public:
  80. friend class SettingsRTTI;
  81. static RTTITypeBase* getRTTIStatic();
  82. virtual RTTITypeBase* getRTTI() const override;
  83. };
  84. }