ConfigSet.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. protected:
  36. void newOption(const CString& name, const CString& value);
  37. void newOption(const CString& name, F64 value);
  38. private:
  39. class Option : public NonCopyable
  40. {
  41. public:
  42. String m_name;
  43. String m_strVal;
  44. F64 m_fVal = 0.0;
  45. U8 m_type = 0; ///< 0: string, 1: float
  46. Option() = default;
  47. Option(Option&& b)
  48. : m_name(std::move(b.m_name))
  49. , m_strVal(std::move(b.m_strVal))
  50. , m_fVal(b.m_fVal)
  51. , m_type(b.m_type)
  52. {
  53. }
  54. ~Option() = default;
  55. Option& operator=(Option&& b) = delete;
  56. };
  57. HeapAllocator<U8> m_alloc;
  58. List<Option> m_options;
  59. Option* tryFind(const CString& name);
  60. const Option* tryFind(const CString& name) const;
  61. };
  62. /// @}
  63. } // end namespace anki