From 45fc1e468b9aeb26548d686e4c4a969328cc7a27 Mon Sep 17 00:00:00 2001 From: anschrammh Date: Thu, 28 Mar 2019 00:00:52 +0100 Subject: [PATCH] Added new class to handle the parameters and values retrieved from the config files --- src/app/CFGParameterValue.cpp | 42 ++++++++++++++++++++++++++++++++ src/app/CFGParameterValue.h | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/app/CFGParameterValue.cpp create mode 100644 src/app/CFGParameterValue.h diff --git a/src/app/CFGParameterValue.cpp b/src/app/CFGParameterValue.cpp new file mode 100644 index 0000000..0a44d58 --- /dev/null +++ b/src/app/CFGParameterValue.cpp @@ -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; +} diff --git a/src/app/CFGParameterValue.h b/src/app/CFGParameterValue.h new file mode 100644 index 0000000..9ed15b1 --- /dev/null +++ b/src/app/CFGParameterValue.h @@ -0,0 +1,45 @@ +#ifndef CFGPARAMETERVALUE_H +#define CFGPARAMETERVALUE_H + +#include +#include +#include +#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