Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.3 KiB

  1. /*
  2. SETTINGS MODULE
  3. */
  4. #pragma once
  5. #include <cstdlib>
  6. // --------------------------------------------------------------------------
  7. namespace settings {
  8. namespace internal {
  9. template <typename T>
  10. using convert_t = T(*)(const String& value);
  11. template <typename T>
  12. T convert(const String& value);
  13. // --------------------------------------------------------------------------
  14. template <>
  15. float convert(const String& value) {
  16. return value.toFloat();
  17. }
  18. template <>
  19. double convert(const String& value) {
  20. return value.toFloat();
  21. }
  22. template <>
  23. int convert(const String& value) {
  24. return value.toInt();
  25. }
  26. template <>
  27. long convert(const String& value) {
  28. return value.toInt();
  29. }
  30. template <>
  31. bool convert(const String& value) {
  32. return convert<int>(value) == 1;
  33. }
  34. template <>
  35. unsigned long convert(const String& value) {
  36. return strtoul(value.c_str(), nullptr, 10);
  37. }
  38. template <>
  39. unsigned int convert(const String& value) {
  40. return convert<unsigned long>(value);
  41. }
  42. template <>
  43. unsigned short convert(const String& value) {
  44. return convert<unsigned long>(value);
  45. }
  46. template <>
  47. unsigned char convert(const String& value) {
  48. return convert<unsigned long>(value);
  49. }
  50. template <>
  51. String convert(const String& value) {
  52. return value;
  53. }
  54. } // namespace settings::internal
  55. } // namespace settings