Implemented generic for loops
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-26 16:19:34 +02:00
parent cfd558b718
commit d86e9ba8ae
18 changed files with 325 additions and 44 deletions

View File

@@ -0,0 +1,39 @@
#ifndef PORYGONLANG_SIMPLEKEYITERATOR_HPP
#define PORYGONLANG_SIMPLEKEYITERATOR_HPP
#include "Iterator.hpp"
#include "../EvalValues/TableEvalValue.hpp"
#include "../EvalValues/StringEvalValue.hpp"
namespace Porygon::Evaluation{
class TableKeyIterator : public Iterator{
_Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> _iterator;
_Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> _end;
bool _hasStarted = false;
public:
explicit TableKeyIterator(const TableEvalValue* table)
: _iterator(table->GetTableIterator()), _end(table->GetTableIteratorEnd()){}
shared_ptr<EvalValue> GetCurrent() final{
return make_shared<StringEvalValue>(*_iterator->first.GetString());
}
bool MoveNext() final{
if (_hasStarted){
std::advance(_iterator, 1);
} else{
_hasStarted = true;
}
return _iterator != _end;
}
void Reset(){
throw EvaluationException("Can't reset table key iterator");
}
};
}
#endif //PORYGONLANG_SIMPLEKEYITERATOR_HPP