settings.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SETTINGS_H_
  23. #define _SETTINGS_H_
  24. #include "console/simBase.h"
  25. #include "core/util/tVector.h"
  26. class SimXMLDocument;
  27. ///
  28. class Settings : public SimObject
  29. {
  30. private:
  31. StringTableEntry mFile;
  32. Vector<String> mGroupStack;
  33. S32 mSearchPos;
  34. Vector<String> mSearchResults;
  35. public:
  36. Settings();
  37. virtual ~Settings();
  38. // Required in all ConsoleObject subclasses.
  39. typedef SimObject Parent;
  40. DECLARE_CONOBJECT(Settings);
  41. static void initPersistFields();
  42. /// These will set and get the values, with an option default value passed in to the get
  43. void setDefaultValue(const UTF8 *settingName, const UTF8 *settingValue, const UTF8 *settingType="");
  44. void setValue(const UTF8 *settingName, const UTF8 *settingValue = "");
  45. const UTF8 *value(const UTF8 *settingName, const UTF8 *defaultValue = "");
  46. void remove(const UTF8 *settingName, bool includeDefaults = false);
  47. void clearAllFields();
  48. bool write();
  49. bool read();
  50. void readLayer(SimXMLDocument *document, String groupStack = String(""));
  51. void beginGroup(const UTF8 *groupName, bool fromStart = false);
  52. void endGroup();
  53. void clearGroups();
  54. void buildGroupString(String &name, const UTF8 *settingName);
  55. const UTF8 *getCurrentGroups();
  56. //S32 buildSearchList(const char* pattern, bool deepSearch = false, bool defaultsSearch = false);
  57. const char* findFirstValue(const char* pattern, bool deepSearch = false, bool includeDefaults = false);
  58. const char* findNextValue();
  59. };
  60. class SettingSaveNode
  61. {
  62. public:
  63. Vector<SettingSaveNode*> mGroupNodes;
  64. Vector<SettingSaveNode*> mSettingNodes;
  65. String mName;
  66. String mValue;
  67. bool mIsGroup;
  68. SettingSaveNode()
  69. {
  70. mIsGroup = false;
  71. }
  72. SettingSaveNode(const String &name, bool isGroup = false)
  73. {
  74. mName = name;
  75. mIsGroup = isGroup;
  76. }
  77. SettingSaveNode(const String &name, const String &value)
  78. {
  79. mName = name;
  80. mValue = value;
  81. mIsGroup = false;
  82. }
  83. ~SettingSaveNode()
  84. {
  85. clear();
  86. }
  87. void addValue(const UTF8 *name, const UTF8 *value);
  88. S32 getGroupCount(const String &name);
  89. String getGroup(const String &name, S32 num);
  90. String getSettingName(const String &name);
  91. void buildDocument(SimXMLDocument *document, bool skipWrite = false);
  92. void clear();
  93. static S32 _NodeCompare(SettingSaveNode* const* a, SettingSaveNode* const* b);
  94. };
  95. #endif