83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
#ifndef _GWCONFIGITEM_H
|
|
#define _GWCONFIGITEM_H
|
|
#include "WString.h"
|
|
#include <vector>
|
|
|
|
class GwConfigHandler;
|
|
class GwConfigInterface{
|
|
private:
|
|
String name;
|
|
const char * initialValue;
|
|
String value;
|
|
bool secret=false;
|
|
String changedValue;
|
|
bool hasChangedValue=false;
|
|
void updateValue(String value,bool cmpDefault=false){
|
|
hasChangedValue=false;
|
|
if (cmpDefault){
|
|
if (value != initialValue) {
|
|
changedValue=value;
|
|
hasChangedValue=true;
|
|
}
|
|
}
|
|
else{
|
|
if (value != this->value) {
|
|
changedValue=value;
|
|
hasChangedValue=true;
|
|
}
|
|
}
|
|
}
|
|
public:
|
|
GwConfigInterface(const String &name, const char * initialValue, bool secret=false){
|
|
this->name=name;
|
|
this->initialValue=initialValue;
|
|
this->value=initialValue;
|
|
this->secret=secret;
|
|
}
|
|
virtual String asString() const{
|
|
return value;
|
|
}
|
|
virtual const char * asCString() const{
|
|
return value.c_str();
|
|
};
|
|
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 bool isSecret() const{
|
|
return secret;
|
|
}
|
|
bool changed() const{
|
|
return value != initialValue;
|
|
}
|
|
String getDefault() const {
|
|
return initialValue;
|
|
}
|
|
friend class GwConfigHandler;
|
|
};
|
|
|
|
class GwNmeaFilter{
|
|
private:
|
|
String config;
|
|
bool isReady=false;
|
|
bool ais=true;
|
|
bool blacklist=true;
|
|
std::vector<String> filter;
|
|
void handleToken(String token, int index);
|
|
void parseFilter();
|
|
public:
|
|
GwNmeaFilter(String config){
|
|
this->config=config;
|
|
isReady=false;
|
|
}
|
|
bool canPass(const char *buffer);
|
|
String toString();
|
|
};
|
|
|
|
|
|
#endif |