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

/*
SETTINGS MODULE
*/
#pragma once
#include <cstdlib>
// --------------------------------------------------------------------------
namespace settings {
namespace internal {
template <typename T>
using convert_t = T(*)(const String& value);
template <typename T>
T convert(const String& value);
// --------------------------------------------------------------------------
template <>
float convert(const String& value) {
return value.toFloat();
}
template <>
double convert(const String& value) {
return value.toFloat();
}
template <>
int convert(const String& value) {
return value.toInt();
}
template <>
long convert(const String& value) {
return value.toInt();
}
template <>
bool convert(const String& value) {
return convert<int>(value) == 1;
}
template <>
unsigned long convert(const String& value) {
return strtoul(value.c_str(), nullptr, 10);
}
template <>
unsigned int convert(const String& value) {
return convert<unsigned long>(value);
}
template <>
unsigned short convert(const String& value) {
return convert<unsigned long>(value);
}
template <>
unsigned char convert(const String& value) {
return convert<unsigned long>(value);
}
template <>
String convert(const String& value) {
return value;
}
} // namespace settings::internal
} // namespace settings