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:
@@ -2,11 +2,17 @@
|
||||
#ifndef PORYGONLANG_EVALVALUE_HPP
|
||||
#define PORYGONLANG_EVALVALUE_HPP
|
||||
|
||||
#include "../../ScriptType.hpp"
|
||||
#include "../EvaluationException.hpp"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include "../../ScriptType.hpp"
|
||||
#include "../EvaluationException.hpp"
|
||||
namespace Porygon::Evaluation{
|
||||
class EvalValue;
|
||||
class Iterator;
|
||||
}
|
||||
#include "../Iterator/Iterator.hpp"
|
||||
|
||||
|
||||
namespace Porygon::Evaluation {
|
||||
class EvalValue {
|
||||
@@ -54,6 +60,10 @@ namespace Porygon::Evaluation {
|
||||
virtual void SetIndexValue(EvalValue *key, const shared_ptr<EvalValue> &value) const {
|
||||
throw EvaluationException("Can't index this EvalValue");
|
||||
}
|
||||
|
||||
virtual Iterator * GetKeyIterator() const{
|
||||
throw EvaluationException("Can't iterate over this EvalValue");
|
||||
}
|
||||
};
|
||||
|
||||
class BooleanEvalValue : public EvalValue {
|
||||
|
||||
6
src/Evaluator/EvalValues/TableEvalValue.cpp
Normal file
6
src/Evaluator/EvalValues/TableEvalValue.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "TableEvalValue.hpp"
|
||||
#include "../Iterator/SimpleKeyIterator.hpp"
|
||||
|
||||
Porygon::Evaluation::Iterator * Porygon::Evaluation::TableEvalValue::GetKeyIterator() const {
|
||||
return new TableKeyIterator(this);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
#ifndef PORYGONLANG_TABLEEVALVALUE_HPP
|
||||
#define PORYGONLANG_TABLEEVALVALUE_HPP
|
||||
#include <utility>
|
||||
@@ -8,18 +9,20 @@ using namespace std;
|
||||
|
||||
namespace Porygon::Evaluation {
|
||||
class TableEvalValue : public EvalValue {
|
||||
shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> _table;
|
||||
size_t _hash;
|
||||
const shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> _table;
|
||||
const size_t _hash;
|
||||
|
||||
explicit TableEvalValue(shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> table, size_t hash) {
|
||||
_table = std::move(table);
|
||||
_hash = hash;
|
||||
explicit TableEvalValue(shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> table, size_t hash)
|
||||
: _table(std::move(table)),
|
||||
_hash(hash)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
explicit TableEvalValue(shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> table) {
|
||||
_table = std::move(table);
|
||||
_hash = rand();
|
||||
explicit TableEvalValue(shared_ptr<map<Utilities::HashedString, shared_ptr<EvalValue>>> table) :
|
||||
_table(std::move(table)),
|
||||
_hash(rand())
|
||||
{
|
||||
}
|
||||
|
||||
const TypeClass GetTypeClass() const final {
|
||||
@@ -57,6 +60,8 @@ namespace Porygon::Evaluation {
|
||||
this->_table->at(Utilities::HashedString::CreateLookup(hash)) = value;
|
||||
}
|
||||
|
||||
Iterator * GetKeyIterator() const final;
|
||||
|
||||
const _Rb_tree_const_iterator<pair<const Utilities::HashedString, shared_ptr<EvalValue>>> GetTableIterator() const{
|
||||
return _table->cbegin();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user