ConfigSet.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (C) 2009-2015, 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. /// @addtogroup misc
  10. /// @{
  11. /// A storage of configuration variables.
  12. class ConfigSet
  13. {
  14. public:
  15. ConfigSet();
  16. /// Copy.
  17. ConfigSet(const ConfigSet& b)
  18. {
  19. operator=(b);
  20. }
  21. ~ConfigSet();
  22. /// Copy.
  23. ConfigSet& operator=(const ConfigSet& b);
  24. /// @name Set an option
  25. /// @{
  26. void set(const CString& name, const CString& value);
  27. void set(const CString& name, F64 value);
  28. /// @}
  29. /// @name Find an option and return it's value.
  30. /// @{
  31. F64 getNumber(const CString& name) const;
  32. CString getString(const CString& name) const;
  33. /// @}
  34. protected:
  35. void newOption(const CString& name, const CString& value);
  36. void newOption(const CString& name, F64 value);
  37. private:
  38. class Option: public NonCopyable
  39. {
  40. public:
  41. String m_name;
  42. String m_strVal;
  43. F64 m_fVal = 0.0;
  44. U8 m_type = 0; ///< 0: string, 1: float
  45. Option() = default;
  46. Option(Option&& b)
  47. : m_name(std::move(b.m_name))
  48. , m_strVal(std::move(b.m_strVal))
  49. , m_fVal(b.m_fVal)
  50. , m_type(b.m_type)
  51. {}
  52. ~Option() = default;
  53. Option& operator=(Option&& b) = delete;
  54. };
  55. HeapAllocator<U8> m_alloc;
  56. List<Option> m_options;
  57. Option* tryFind(const CString& name);
  58. const Option* tryFind(const CString& name) const;
  59. };
  60. /// @}
  61. } // end namespace anki