-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTable.h
51 lines (40 loc) · 1.9 KB
/
Table.h
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
#pragma once
#include "Forward.h"
#include "Object.h"
#include "Directory.h"
/*
Tables are a very special variety of Objects, for these reasons:
1. Tables are, in part, arrays. You can do numerical indexing into them.
2. Tables are iteratable. You can iterate over their properties and array.
These things form the basis of the array-orientation of this language,
while also providing for a lovely harmonization with the object-orientation also present within this language.
For instance, every method below can (or at least, ought to be possibly) overloaded in a child type of /table,
to perhaps provide a default value to return, or other features.
This concept in general is a mixture of general OOP and Lua's concept of having a "metatable."
*/
class Table final : public Object
{
//The worker function for at_ref, at_set, and at_set_raw.
//Allocates space within the table for the key-value pair corresponding to the 1st and 2nd args, respectively.
//Returns a reference to the place it allocated. Must succeed.
Value& talloc(Value, const Value&);
public:
//Deallocates the index provided, if it exists somewhere.
void tfree(const Value&);
std::vector<Value> t_array;
Hashtable<Value, Value> t_hash;
Table(const ImmutableString& objty, Hashtable<ImmutableString, Value>* puh, Hashtable<ImmutableString, Function*>* fuh)
:Object(objty,puh,fuh,nullptr)
{
}
virtual ~Table() = default;
//Returns the value stored at this index, or NULL if it cannot be found.
Value at(Interpreter&, Value);
//Gets a handle to the value pointed to by this index. Quietly creates a reference to a null Value if it cannot be found.
Value& at_ref(Interpreter&, Value);
//Sets the value pointed to by index to the value referenced by the second.
void at_set(Interpreter&, Value, Value&);
bool at_set_raw(Value, const Value&);
size_t length() { return t_array.size(); }
bool virtual is_table() const override { return true; }
};