Added new class to handle the parameters and values retrieved from the config files
This commit is contained in:
parent
7ae2541999
commit
45fc1e468b
42
src/app/CFGParameterValue.cpp
Normal file
42
src/app/CFGParameterValue.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "CFGParameterValue.h"
|
||||||
|
|
||||||
|
CFGParameterValue::CFGParameterValue():DictionaryInterface(),_parameter(NULL), _value(NULL), _quotedParameter(false), _quotedValue(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CFGParameterValue::CFGParameterValue(const char *parameter, const char *value, bool quotedParameter, bool quotedValue):_quotedParameter(quotedParameter), _quotedValue(quotedValue)
|
||||||
|
{
|
||||||
|
_parameter = (char *) malloc((strlen(parameter) * sizeof(char)) + 1); //+1 for the string terminating character
|
||||||
|
_value = (char *) malloc((strlen(value) * sizeof(char)) + 1); //+1 for the string terminating character
|
||||||
|
|
||||||
|
strcpy(_parameter, parameter);
|
||||||
|
strcpy(_value, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
CFGParameterValue::CFGParameterValue(const char *parameter, const char *value):CFGParameterValue()
|
||||||
|
{
|
||||||
|
_parameter = (char *) malloc((strlen(parameter) * sizeof(char)) + 1); //+1 for the string terminating character
|
||||||
|
_value = (char *) malloc((strlen(value) * sizeof(char)) + 1); //+1 for the string terminating character
|
||||||
|
|
||||||
|
strcpy(_parameter, parameter);
|
||||||
|
strcpy(_value, value);
|
||||||
|
}
|
||||||
|
CFGParameterValue::CFGParameterValue(const CFGParameterValue &Object)
|
||||||
|
{
|
||||||
|
_parameter = (char *) malloc((strlen(Object._parameter) * sizeof(char)) + 1); //+1 for the string terminating character
|
||||||
|
_value = (char *) malloc((strlen(Object._value) * sizeof(char)) + 1); //+1 for the string terminating character
|
||||||
|
|
||||||
|
strcpy(_parameter, Object._parameter);
|
||||||
|
strcpy(_value, Object._value);
|
||||||
|
|
||||||
|
_quotedParameter = Object._quotedParameter;
|
||||||
|
_quotedValue = Object._quotedValue;
|
||||||
|
}
|
||||||
|
CFGParameterValue::~CFGParameterValue()
|
||||||
|
{
|
||||||
|
free(_parameter);
|
||||||
|
_parameter = NULL;
|
||||||
|
free(_value);
|
||||||
|
_value = NULL;
|
||||||
|
}
|
45
src/app/CFGParameterValue.h
Normal file
45
src/app/CFGParameterValue.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#ifndef CFGPARAMETERVALUE_H
|
||||||
|
#define CFGPARAMETERVALUE_H
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "DictionaryInterface.h"
|
||||||
|
|
||||||
|
class CFGParameterValue : public DictionaryInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CFGParameterValue();
|
||||||
|
CFGParameterValue(const char *parameter, const char *value, bool quotedParameter, bool quotedValue);
|
||||||
|
CFGParameterValue(const char *parameter, const char *value);
|
||||||
|
CFGParameterValue(const CFGParameterValue &Object);
|
||||||
|
~CFGParameterValue();
|
||||||
|
const char *stringValue() const{return _value == NULL ? "":_value;}
|
||||||
|
long longValue() const {return _value == NULL ? 0 : strtol(_value, NULL, 10);}
|
||||||
|
int intValue() const {return (int) (_value == NULL ? 0 : strtol(_value, NULL, 10));}
|
||||||
|
unsigned long uintValue() const {return _value == NULL ? 0 : strtoul(_value, NULL, 10);}
|
||||||
|
double doubleValue() const {return _value == NULL ? 0 : strtod(_value, NULL);}
|
||||||
|
float floatValue() const {return _value == NULL ? 0 : strtof(_value, NULL);}
|
||||||
|
boolean booleanValue() const
|
||||||
|
{
|
||||||
|
if(_value == NULL)
|
||||||
|
return false;
|
||||||
|
return strcmp(_value,"true") == 0 || strcmp(_value,"TRUE") == 0 ? true : false;
|
||||||
|
}
|
||||||
|
const char *getParameter() const{return _parameter == NULL ? "" : _parameter;}
|
||||||
|
virtual const char *toString()
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
private:
|
||||||
|
char *_parameter;
|
||||||
|
char *_value;
|
||||||
|
|
||||||
|
bool _quotedParameter;
|
||||||
|
bool _quotedValue;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //CFGPARAMETERVALUE_H
|
Loading…
Reference in New Issue
Block a user