Added offset capabilities for integers

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:09 +01:00
parent 88ea3f8b20
commit 30c1e703b1
2 changed files with 33 additions and 7 deletions
@@ -83,7 +83,7 @@ namespace YAML {
// return node;
// }
static bool decode(const YAML::Node& node, GeneralSettings& rhs) {
static bool decode(const Node& node, GeneralSettings& rhs) {
node["version"] >> rhs.version;
node["versionBla"] >> rhs.version;
@@ -93,8 +93,10 @@ namespace YAML {
node["contrast"] >> rhs.contrast;
node["vBatWarn"] >> rhs.vBatWarn;
node["txVoltageCalibration"] >> rhs.txVoltageCalibration;
node["vBatMin"] >> rhs.vBatMin;
node["vBatMax"] >> rhs.vBatMax;
node["vBatMin"] >> ioffset_int(rhs.vBatMin, 90);
node["vBatMax"] >> ioffset_int(rhs.vBatMax, 120);
node["backlightMode"] >> backlightModeLut >> rhs.backlightMode;
node["trainer"] >> rhs.trainer;
node["view"] >> rhs.view;
+28 -4
View File
@@ -25,7 +25,24 @@
typedef std::pair<int, std::string> YamlLookupTableElmt;
typedef std::vector<YamlLookupTableElmt> YamlLookupTable;
YAML::Node operator>>(const YAML::Node& node, const YamlLookupTable& lut)
class ioffset_int {
public:
ioffset_int(int& val, int offset)
: value(val), offset(offset)
{}
void assign(int newValue) const {
value = newValue - offset;
}
private:
int& value;
int offset;
};
YAML::Node operator >> (const YAML::Node& node, const YamlLookupTable& lut)
{
if (node) {
std::string str = node.as<std::string>();
@@ -44,8 +61,15 @@ YAML::Node operator>>(const YAML::Node& node, const YamlLookupTable& lut)
return node;
}
void operator >> (const YAML::Node& node, const ioffset_int& value)
{
if (node && node.IsScalar()) {
value.assign(node.as<int>());
}
}
template <typename T>
void operator>>(const YAML::Node& node, T& value)
void operator >> (const YAML::Node& node, T& value)
{
if (node && !node.IsNull()) {
value = node.as<T>();
@@ -53,7 +77,7 @@ void operator>>(const YAML::Node& node, T& value)
}
template <>
void operator>>(const YAML::Node& node, bool& value)
void operator >> (const YAML::Node& node, bool& value)
{
if (node && node.IsScalar()) {
value = node.as<int>();
@@ -61,7 +85,7 @@ void operator>>(const YAML::Node& node, bool& value)
}
template <size_t N>
void operator>>(const YAML::Node& node, char (&value)[N])
void operator >> (const YAML::Node& node, char (&value)[N])
{
if (node && node.IsScalar()) {
auto str = node.as<std::string>();