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:
52
lib/config/GwConfigItem.h
Normal file
52
lib/config/GwConfigItem.h
Normal 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
|
||||
Reference in New Issue
Block a user