ConfigSet.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos and contributors.
  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. ANKI_USE_RESULT Error setFromCommandLineArguments(
  38. U cmdLineArgsCount, char* cmdLineArgs[]);
  39. protected:
  40. void newOption(const CString& name, const CString& value);
  41. void newOption(const CString& name, F64 value);
  42. private:
  43. class Option : public NonCopyable
  44. {
  45. public:
  46. String m_name;
  47. String m_strVal;
  48. F64 m_fVal = 0.0;
  49. U8 m_type = 0; ///< 0: string, 1: float
  50. Option() = default;
  51. Option(Option&& b)
  52. : m_name(std::move(b.m_name))
  53. , m_strVal(std::move(b.m_strVal))
  54. , m_fVal(b.m_fVal)
  55. , m_type(b.m_type)
  56. {
  57. }
  58. ~Option() = default;
  59. Option& operator=(Option&& b) = delete;
  60. };
  61. HeapAllocator<U8> m_alloc;
  62. List<Option> m_options;
  63. Option* tryFind(const CString& name);
  64. const Option* tryFind(const CString& name) const;
  65. };
  66. /// @}
  67. } // end namespace anki