ConfigSet.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/util/List.h>
  7. #include <anki/util/String.h>
  8. namespace anki
  9. {
  10. /// @addtogroup misc
  11. /// @{
  12. /// A storage of configuration variables.
  13. class ConfigSet
  14. {
  15. public:
  16. ConfigSet();
  17. /// Copy.
  18. ConfigSet(const ConfigSet& b)
  19. {
  20. operator=(b);
  21. }
  22. ~ConfigSet();
  23. /// Copy.
  24. ConfigSet& operator=(const ConfigSet& b);
  25. /// @name Set an option
  26. /// @{
  27. void set(const CString& name, const CString& value);
  28. void set(const CString& name, F64 value);
  29. /// @}
  30. /// @name Find an option and return it's value.
  31. /// @{
  32. F64 getNumber(const CString& name) const;
  33. CString getString(const CString& name) const;
  34. /// @}
  35. ANKI_USE_RESULT Error loadFromFile(CString filename);
  36. ANKI_USE_RESULT Error saveToFile(CString filename) const;
  37. protected:
  38. void newOption(const CString& name, const CString& value);
  39. void newOption(const CString& name, F64 value);
  40. private:
  41. class Option : public NonCopyable
  42. {
  43. public:
  44. String m_name;
  45. String m_strVal;
  46. F64 m_fVal = 0.0;
  47. U8 m_type = 0; ///< 0: string, 1: float
  48. Option() = default;
  49. Option(Option&& b)
  50. : m_name(std::move(b.m_name))
  51. , m_strVal(std::move(b.m_strVal))
  52. , m_fVal(b.m_fVal)
  53. , m_type(b.m_type)
  54. {
  55. }
  56. ~Option() = default;
  57. Option& operator=(Option&& b) = delete;
  58. };
  59. HeapAllocator<U8> m_alloc;
  60. List<Option> m_options;
  61. Option* tryFind(const CString& name);
  62. const Option* tryFind(const CString& name) const;
  63. };
  64. /// @}
  65. } // end namespace anki