From dc96053576f2895da0a8c98f7ba7f13226a8ca64 Mon Sep 17 00:00:00 2001 From: anschrammh Date: Sun, 24 Mar 2019 10:30:08 +0100 Subject: [PATCH] Enhanced the dictionary object (added get by index and getParameter methods) --- src/app/Dictionary.cpp | 14 +++++++++++++- src/app/Dictionary.h | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/Dictionary.cpp b/src/app/Dictionary.cpp index 9e14499..8af2cb8 100644 --- a/src/app/Dictionary.cpp +++ b/src/app/Dictionary.cpp @@ -59,13 +59,19 @@ Dictionary Dictionary::get(const char *parameter) Dictionary Dictionary::operator()(const char *parameter) { + return get(parameter); +} + +Dictionary Dictionary::get(const unsigned int index) +{ + unsigned int position(0); if(isListEmpty(_head->_next))return Dictionary(); Dictionary *cursor = _head->_next; while(!isListEmpty(cursor)) { - if(strcmp(cursor->_parameter,parameter) == 0) + if(position++ == index) return *cursor; cursor = cursor->_next; } @@ -73,6 +79,11 @@ Dictionary Dictionary::operator()(const char *parameter) return Dictionary(); } +Dictionary Dictionary::operator()(const unsigned int index) +{ + return get(index); +} + unsigned int Dictionary::count() { unsigned int counter(0); @@ -158,3 +169,4 @@ void Dictionary::dispose() } void Dictionary::clear() {this->dispose();} + diff --git a/src/app/Dictionary.h b/src/app/Dictionary.h index 28ac748..6767f38 100644 --- a/src/app/Dictionary.h +++ b/src/app/Dictionary.h @@ -31,6 +31,8 @@ public: boolean deleteParameter(const char *parameter); Dictionary get(const char *parameter); Dictionary operator()(const char *parameter); + Dictionary get(const unsigned int index); + Dictionary operator()(const unsigned int index); unsigned int count(); void clear(); void dispose(); @@ -47,6 +49,7 @@ public: return false; return strcmp(_value,"true") == 0 || strcmp(_value,"TRUE") == 0 ? true : false; } + const char *getParameter() const{return _parameter == NULL ? "" : _parameter;} protected: Dictionary(); Dictionary(const char *parameter, const char *value);