-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguageCollection.cpp
More file actions
executable file
·77 lines (57 loc) · 2.3 KB
/
LanguageCollection.cpp
File metadata and controls
executable file
·77 lines (57 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "LanguageCollection.hpp"
#include "RuntimeException.hpp"
void LanguageCollection::deleteObject() {
delete collectionIt;
}
Function* LanguageCollection::getFunction(Variable* var) {
if(var->getType() == Types::LANGUAGEELEMENT) {
return new Function(*this, var);
} else {
throw RuntimeException("Language Element Expected");
}
}
Variable* LanguageCollection::evaluateFunction(std::string& functionName, Variable* parameters) {
if(functionName.compare("addItem") == 0) {
if(parameters == nullptr || parameters->getType() == Types::COMMALIST) {
throw RuntimeException("Expected only one parameter");
}
variableCollection.add(new Variable(parameters));
if(collectionType == Types::OTHER) {
collectionType = parameters->getType();
collectionIt = variableCollection.getIterator();
} else if(collectionType != parameters->getType()) {
throw RuntimeException("Type mismatch in collection");
} else {
}
return new Variable(nullptr, Types::OTHER, -1);
} else if(functionName.compare("getNext") == 0) {
if(parameters != nullptr) {
throw RuntimeException("Expected no parameters");
}
if(collectionIt == nullptr) collectionIt = variableCollection.getIterator();
Variable* rtn = new Variable(collectionIt->getValue());
collectionIt->next();
return rtn;
} else if(functionName.compare("resetNext") == 0) {
if(parameters != nullptr) {
throw RuntimeException("Expected no parameters");
}
delete collectionIt;
collectionIt = variableCollection.getIterator();
return new Variable(nullptr, Types::OTHER, -1);
} else if(functionName.compare("hasNext") == 0) {
if(parameters != nullptr) {
throw RuntimeException("Expected no parameters");
}
if(collectionIt != nullptr) {
return new Variable((void*)(new bool(collectionIt->hasMore())), Types::BOOLEAN, -1);
} else throw RuntimeException("Initialize collection first before accessing");
} else if(functionName.compare("isEmpty") == 0) {
if(parameters != nullptr) {
throw RuntimeException("Expected no parameters");
}
return new Variable((void*)(new bool(variableCollection.isEmpty())), Types::BOOLEAN, -1);
} else {
throw RuntimeException(functionName + " is not a member function of collection");
}
}