ConfigSet.h 1.1 KB

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