FloatSetting.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "FloatSetting.h"
  23. namespace crown
  24. {
  25. static FloatSetting* g_float_settings_head = NULL;
  26. //-----------------------------------------------------------------------------
  27. FloatSetting::FloatSetting(const char* name, const char* synopsis, float value, float min, float max) :
  28. m_name(name),
  29. m_synopsis(synopsis),
  30. m_value(0),
  31. m_min(min),
  32. m_max(max),
  33. m_next(NULL)
  34. {
  35. *this = value;
  36. if (g_float_settings_head == NULL)
  37. {
  38. g_float_settings_head = this;
  39. m_next = NULL;
  40. }
  41. else
  42. {
  43. m_next = g_float_settings_head;
  44. g_float_settings_head = this;
  45. }
  46. }
  47. //-----------------------------------------------------------------------------
  48. const char* FloatSetting::name() const
  49. {
  50. return m_name;
  51. }
  52. //-----------------------------------------------------------------------------
  53. const char* FloatSetting::synopsis() const
  54. {
  55. return m_synopsis;
  56. }
  57. //-----------------------------------------------------------------------------
  58. float FloatSetting::value() const
  59. {
  60. return m_value;
  61. }
  62. //-----------------------------------------------------------------------------
  63. float FloatSetting::min() const
  64. {
  65. return m_min;
  66. }
  67. //-----------------------------------------------------------------------------
  68. float FloatSetting::max() const
  69. {
  70. return m_max;
  71. }
  72. //-----------------------------------------------------------------------------
  73. FloatSetting::operator float()
  74. {
  75. return m_value;
  76. }
  77. //-----------------------------------------------------------------------------
  78. FloatSetting& FloatSetting::operator=(const float value)
  79. {
  80. if (value > m_max)
  81. {
  82. m_value = m_max;
  83. }
  84. else if (value < m_min)
  85. {
  86. m_value = m_min;
  87. }
  88. else
  89. {
  90. m_value = value;
  91. }
  92. return *this;
  93. }
  94. } // namespace crown