CmPreferences.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include "CmEditorPrerequisites.h"
  3. namespace CamelotEditor
  4. {
  5. class Preferences
  6. {
  7. public:
  8. void setValue(const String& key, const String& value, CamelotFramework::UINT32 arrayIdx = 0);
  9. void addValue(const String& key, const String& value);
  10. const String& getValue(const String& key, const String& defaultValue = StringUtil::BLANK, CamelotFramework::UINT32 arrayIdx = 0);
  11. void setValue(const String& key, const int value, CamelotFramework::UINT32 arrayIdx = 0);
  12. void addValue(const String& key, const int value);
  13. int getValue(const String& key, int defaultValue = 0, CamelotFramework::UINT32 arrayIdx = 0);
  14. void setValue(const String& key, float value, CamelotFramework::UINT32 arrayIdx = 0);
  15. void addValue(const String& key, float value);
  16. float getValue(const String& key, float defaultValue = 0.0f, CamelotFramework::UINT32 arrayIdx = 0);
  17. CamelotFramework::UINT32 getNumValues(const String& key);
  18. void save(const String& path, bool overwrite = true) const;
  19. void load(const String& path);
  20. private:
  21. struct PrefStringEntries
  22. {
  23. Vector<String>::type entries;
  24. };
  25. struct PrefIntEntries
  26. {
  27. Vector<int>::type entries;
  28. };
  29. struct PrefFloatEntries
  30. {
  31. Vector<float>::type entries;
  32. };
  33. enum ValueMapType
  34. {
  35. VMT_String,
  36. VMT_Int,
  37. VMT_Float
  38. };
  39. struct KeyMapIndex
  40. {
  41. ValueMapType mapType;
  42. CamelotFramework::UINT32 entryIdx;
  43. };
  44. struct EntryToSave
  45. {
  46. String name;
  47. String value;
  48. };
  49. Map<String, KeyMapIndex>::type mKeys;
  50. Vector<PrefStringEntries>::type mStringEntries;
  51. Vector<PrefIntEntries>::type mIntEntries;
  52. Vector<PrefFloatEntries>::type mFloatEntries;
  53. bool isKeyValid(const String& key) const;
  54. };
  55. }