float_setting.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "float_setting.h"
  6. #include "string_utils.h"
  7. #include "math_utils.h"
  8. namespace crown
  9. {
  10. static FloatSetting* g_float_settings_head = NULL;
  11. FloatSetting::FloatSetting(const char* name, const char* synopsis, float value, float min, float max)
  12. : _name(name)
  13. , _synopsis(synopsis)
  14. , _value(0)
  15. , _min(min)
  16. , _max(max)
  17. , _next(NULL)
  18. {
  19. *this = value;
  20. if (g_float_settings_head != NULL)
  21. {
  22. _next = g_float_settings_head;
  23. }
  24. g_float_settings_head = this;
  25. }
  26. const char* FloatSetting::name() const
  27. {
  28. return _name;
  29. }
  30. const char* FloatSetting::synopsis() const
  31. {
  32. return _synopsis;
  33. }
  34. float FloatSetting::value() const
  35. {
  36. return _value;
  37. }
  38. float FloatSetting::min() const
  39. {
  40. return _min;
  41. }
  42. float FloatSetting::max() const
  43. {
  44. return _max;
  45. }
  46. FloatSetting::operator float()
  47. {
  48. return _value;
  49. }
  50. FloatSetting& FloatSetting::operator=(const float value)
  51. {
  52. _value = clamp(_min, _max, value);
  53. return *this;
  54. }
  55. FloatSetting* FloatSetting::find_setting(const char* name)
  56. {
  57. FloatSetting* head = g_float_settings_head;
  58. while (head != NULL)
  59. {
  60. if (strcmp(name, head->name()) == 0)
  61. {
  62. return head;
  63. }
  64. head = head->_next;
  65. }
  66. return NULL;
  67. }
  68. } // namespace crown