BsSettings.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /** @addtogroup Settings
  9. * @{
  10. */
  11. /** Contains a serializable set of generic key-value pairs. */
  12. class BS_ED_EXPORT Settings : public IReflectable
  13. {
  14. public:
  15. Settings();
  16. /** Adds or updates a property key/value pair with a floating point value. */
  17. void setFloat(const String& name, float value);
  18. /** Adds or updates a property key/value pair with a signed integer value. */
  19. void setInt(const String& name, INT32 value);
  20. /** Adds or updates a property key/value pair with a boolean value. */
  21. void setBool(const String& name, bool value);
  22. /** Adds or updates a property key/value pair with a string value. */
  23. void setString(const String& name, const WString& value);
  24. /** Returns the floating point value of the specified key, or the default value if such key cannot be found. */
  25. float getFloat(const String& name, float defaultValue = 0.0f);
  26. /** Returns the integer point value of the specified key, or the default value if such key cannot be found. */
  27. INT32 getInt(const String& name, INT32 defaultValue = 0);
  28. /** Returns the boolean point value of the specified key, or the default value if such key cannot be found. */
  29. bool getBool(const String& name, bool defaultValue = false);
  30. /** Returns the string point value of the specified key, or the default value if such key cannot be found. */
  31. WString getString(const String& name, const WString& defaultValue = StringUtil::WBLANK);
  32. /** Returns true if the key with the specified name exists. */
  33. bool hasKey(const String& name);
  34. /** Deletes a key with the specified name. */
  35. void deleteKey(const String& name);
  36. /** Deletes all key/value pairs. */
  37. void deleteAllKeys();
  38. /** Returns a hash value that may be used for checking if any internal settings were modified. */
  39. UINT32 getHash() const { return mHash; }
  40. protected:
  41. /** Marks the object as dirty so that outside objects know when to update. */
  42. void markAsDirty() const { mHash++; }
  43. UnorderedMap<String, float> mFloatProperties;
  44. UnorderedMap<String, INT32> mIntProperties;
  45. UnorderedMap<String, bool> mBoolProperties;
  46. UnorderedMap<String, WString> mStringProperties;
  47. mutable UINT32 mHash;
  48. /************************************************************************/
  49. /* RTTI */
  50. /************************************************************************/
  51. public:
  52. friend class SettingsRTTI;
  53. static RTTITypeBase* getRTTIStatic();
  54. RTTITypeBase* getRTTI() const override;
  55. };
  56. /** @} */
  57. }