-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathValue.h
More file actions
119 lines (102 loc) · 3.93 KB
/
Copy pathValue.h
File metadata and controls
119 lines (102 loc) · 3.93 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef VALUE_H
#define VALUE_H
#include <string>
class Object;
typedef void (*LibraryFunction)(Object&);
class Value {
public:
enum Type {
UndefType = 0,
NumberType,
BooleanType,
StringType,
ObjectType,
ProgramFunctionType,
LibraryFunctionType,
NativePtrType,
NilType
};
Value(Type _type); //otherwise undef
Value(double _numVal);
Value(bool _boolVal);
Value(const char* _strVal);
Value(LibraryFunction libFuncAst, const char *name);
Value(Object* _objectVal);
Value(Object* _funcAst, Object* _funcClosure, const char *name);
Value(void* _ptr, const char* _typeId);
Value(const Value&);
Value(Value&&);
~Value();
operator bool() const;
bool isUndef() const;
bool isNumber() const;
bool isBoolean() const;
bool isString() const;
bool isObject() const;
bool isProgramFunction() const;
bool isLibraryFunction() const;
bool isNativePtr() const;
bool isNil() const;
Type getType() const;
double toNumber() const;
bool toBoolean() const;
char* toString() const;
const Object* toObject() const;
const Object* toProgramFunctionAST() const;
const Object* toProgramFunctionClosure() const;
const char* toProgramFunctionName() const;
Object* toObjectNoConst() const;
Object* toProgramFunctionASTNoConst() const;
Object* toProgramFunctionClosureNoConst() const;
const LibraryFunction toLibraryFunction() const;
void* toNativePtr() const;
const char* toNativeTypeId() const;
void fromNil(void);
void fromNativePtr (void* _ptr, char* _typeId);
void fromProgramFunction (Object* _funcAst, Object* _funcClosure, const char *name);
void fromObject (Object* _objectVal);
void fromLibraryFunction (LibraryFunction ast, char *name);
void fromString (const char *_strVal);
void fromBool (bool _boolVal);
void fromDouble (double _numVal);
Value* clone() const;
void clear();
void swap(Value&);
const Value operator=(const Value&);
Value& operator=(Value&&);
Value operator+(const Value& other) const;
Value operator-(const Value& other) const;
Value operator*(const Value& other) const;
Value operator/(const Value& other) const;
Value operator%(const Value& other) const;
Value operator>(const Value& other) const;
Value operator>=(const Value& other) const;
Value operator<(const Value& other) const;
Value operator<=(const Value& other) const;
Value operator==(const Value& other) const;
Value operator!=(const Value& other) const;
std::string makeString() const;
std::string typeOfToString();
private:
Type type;
union {
double numVal;
bool boolVal;
char* strVal;
struct {
LibraryFunction ast;
char *libFuncName;
} libFuncVal;
Object* objectVal;
struct {
Object* ast;
Object* closure;
char *funcName;
} progFuncVal;
struct {
void* ptr;
const char* typeId;
} nativePtrVal;
} data;
};
#endif