Enhanced the dictionary object (added get by index and getParameter methods)

This commit is contained in:
anschrammh 2019-03-24 10:30:08 +01:00
parent cbf88aff25
commit dc96053576
2 changed files with 16 additions and 1 deletions

View File

@ -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();}

View File

@ -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);