1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-15 23:13:07 +01:00

intermediate: externalize config definitions

This commit is contained in:
andreas
2021-10-28 20:43:05 +02:00
parent b5aa62ff49
commit b4fe48744b
7 changed files with 212 additions and 92 deletions

52
lib/config/GwConfigItem.h Normal file
View File

@@ -0,0 +1,52 @@
#ifndef _GWCONFIGITEM_H
#define _GWCONFIGITEM_H
#include "WString.h"
class GwConfigInterface{
public:
virtual String asString() const=0;
virtual const char * asCString() const =0;
virtual bool asBoolean() const = 0;
virtual int asInt() const = 0;
};
class GwConfigItem: public GwConfigInterface{
private:
String name;
String initialValue;
String value;
public:
GwConfigItem(const String &name, const String initialValue){
this->name=name;
this->initialValue=initialValue;
this->value=initialValue;
}
virtual String asString() const{
return value;
}
virtual const char * asCString() const{
return value.c_str();
};
virtual void fromString(const String v){
value=v;
};
virtual bool asBoolean() const{
return strcasecmp(value.c_str(),"true") == 0;
}
virtual int asInt() const{
return (int)value.toInt();
}
String getName() const{
return name;
}
virtual void reset(){
value=initialValue;
}
bool changed() const{
return value != initialValue;
}
String getDefault() const {
return initialValue;
}
};
#endif