Initial work on iterators, rework of variable handling by including actual string
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
43
src/Evaluator/Iterator/Iterator.hpp
Normal file
43
src/Evaluator/Iterator/Iterator.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
#ifndef PORYGONLANG_ITERATOR_HPP
|
||||
#define PORYGONLANG_ITERATOR_HPP
|
||||
|
||||
#include <memory>
|
||||
#include "../EvalValues/EvalValue.hpp"
|
||||
#include "../EvalValues/TableEvalValue.hpp"
|
||||
#include "../EvalValues/StringEvalValue.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Porygon::Evaluation{
|
||||
class Iterator {
|
||||
public:
|
||||
virtual shared_ptr<EvalValue> GetCurrent() = 0;
|
||||
virtual bool MoveNext() = 0;
|
||||
virtual void Reset() = 0;
|
||||
};
|
||||
|
||||
class TableKeyIterator : 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;
|
||||
public:
|
||||
TableKeyIterator(shared_ptr<TableEvalValue> table)
|
||||
: _iterator(table->GetTableIterator()), _end(table->GetTableIteratorEnd()){}
|
||||
|
||||
shared_ptr<EvalValue> GetCurrent() final{
|
||||
return make_shared<StringEvalValue>(_iterator->first.GetString());
|
||||
}
|
||||
|
||||
bool MoveNext() final{
|
||||
std::advance(_iterator, 1);
|
||||
return _iterator != _end;
|
||||
}
|
||||
|
||||
void Reset(){
|
||||
throw EvaluationException("Can't reset table key iterator");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //PORYGONLANG_ITERATOR_HPP
|
||||
Reference in New Issue
Block a user