ConfigSet.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef ANKI_MISC_CONFIG_SET_H
  2. #define ANKI_MISC_CONFIG_SET_H
  3. #include "anki/util/StdTypes.h"
  4. #include <unordered_map>
  5. namespace anki {
  6. /// A storage of configuration variables
  7. class ConfigSet
  8. {
  9. public:
  10. /// Find an option and return it's value
  11. F64 get(const char* name) const
  12. {
  13. std::unordered_map<std::string, F64>::const_iterator it =
  14. map.find(name);
  15. if(it != map.end())
  16. {
  17. return it->second;
  18. }
  19. else
  20. {
  21. throw ANKI_EXCEPTION("Option not found");
  22. }
  23. }
  24. /// Find an option and return it's value
  25. F64& get(const char* name)
  26. {
  27. std::unordered_map<std::string, F64>::iterator it = map.find(name);
  28. if(it != map.end())
  29. {
  30. return it->second;
  31. }
  32. else
  33. {
  34. throw ANKI_EXCEPTION("Option not found");
  35. }
  36. }
  37. // Set an option
  38. void set(const char* name, F64 value)
  39. {
  40. std::unordered_map<std::string, F64>::iterator it = map.find(name);
  41. if(it != map.end())
  42. {
  43. it->second = value;
  44. }
  45. else
  46. {
  47. throw ANKI_EXCEPTION("Option not found");
  48. }
  49. }
  50. protected:
  51. /// Add a new option
  52. void newOption(const char* name, F64 value)
  53. {
  54. map[name] = value;
  55. }
  56. private:
  57. std::unordered_map<std::string, F64> map;
  58. };
  59. } // end namespace anki
  60. #endif