Implemented generic for loops
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
39
src/Evaluator/Iterator/SimpleKeyIterator.hpp
Normal file
39
src/Evaluator/Iterator/SimpleKeyIterator.hpp
Normal 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
|
||||
Reference in New Issue
Block a user