Added JsonObjectIterator::operator->()

This commit is contained in:
Benoit Blanchon
2014-10-22 23:32:25 +02:00
parent 40ac60b941
commit 451c0ee70d
3 changed files with 32 additions and 22 deletions

View File

@ -12,41 +12,36 @@ namespace ArduinoJson
public:
explicit JsonObjectIterator(Internals::JsonNode* node)
: _node(node)
: _objectKeyValue(node)
{
}
const char* key() const
{
return operator*().key();
}
JsonValue value() const
{
return operator*().value();
}
void operator++()
{
_node = _node->next;
++_objectKeyValue;
}
JsonObjectKeyValue operator*() const
{
return JsonObjectKeyValue(_node);
return _objectKeyValue;
}
JsonObjectKeyValue* operator->()
{
return &_objectKeyValue;
}
bool operator==(const JsonObjectIterator& other) const
{
return _node == other._node;
return _objectKeyValue == other._objectKeyValue;
}
bool operator!=(const JsonObjectIterator& other) const
{
return _node != other._node;
return _objectKeyValue != other._objectKeyValue;
}
private:
Internals::JsonNode* _node;
JsonObjectKeyValue _objectKeyValue;
};
}

View File

@ -12,7 +12,7 @@ namespace ArduinoJson
{
}
const char* key()
const char* key() const
{
return _node->getAsObjectKey();
}
@ -22,6 +22,21 @@ namespace ArduinoJson
return JsonValue(_node->getAsObjectValue());
}
void operator++()
{
_node = _node->next;
}
bool operator==(const JsonObjectKeyValue& other) const
{
return _node == other._node;
}
bool operator!=(const JsonObjectKeyValue& other) const
{
return _node != other._node;
}
private:
Internals::JsonNode* _node;
};

View File

@ -16,12 +16,12 @@ TEST(JsonObject_Iterator_Test, SimpleTest)
JsonObjectIterator end = object.end();
EXPECT_NE(end, it);
EXPECT_STREQ("ab", it.key());
EXPECT_EQ(12, static_cast<int>(it.value()));
EXPECT_STREQ("ab", it->key());
EXPECT_EQ(12, static_cast<int>(it->value()));
++it;
EXPECT_NE(end, it);
EXPECT_STREQ("cd", it.key());
EXPECT_EQ(34, static_cast<int>(it.value()));
EXPECT_STREQ("cd", it->key());
EXPECT_EQ(34, static_cast<int>(it->value()));
++it;
EXPECT_EQ(object.end(), it);
}