BsSettings.h 3.1 KB

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