summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/EvaluatorResult.java
blob: 2c3c74c8d387bee6a0e4f29e3de63f02772c3734 (plain)
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
package bjc.dicelang;

import bjc.dicelang.dice.Die;
import bjc.dicelang.dice.DieExpression;
import bjc.dicelang.dice.DieList;
import bjc.utils.data.ITree;
import bjc.utils.data.Tree;

public class EvaluatorResult {
	public static enum Type {
		FAILURE, INT, FLOAT, DICE, STRING
	}

	public final EvaluatorResult.Type type;

	// These may or may not have values based
	// off of the result type
	public long intVal;
	public double floatVal;
	public DieExpression diceVal;
	public String stringVal;

	// Original node data
	public ITree<Node> origVal;

	public EvaluatorResult(EvaluatorResult.Type typ) {
		type = typ;
	}

	public EvaluatorResult(EvaluatorResult.Type typ, ITree<Node> orig) {
		this(typ);

		origVal = orig;
	}

	public EvaluatorResult(EvaluatorResult.Type typ, Node orig) {
		this(typ, new Tree<>(orig));
	}

	public EvaluatorResult(EvaluatorResult.Type typ, EvaluatorResult orig) {
		this(typ, new Node(Node.Type.RESULT, orig));
	}

	public EvaluatorResult(EvaluatorResult.Type typ, long iVal) {
		this(typ);

		intVal = iVal;
	}

	public EvaluatorResult(EvaluatorResult.Type typ, double dVal) {
		this(typ);

		floatVal = dVal;
	}

	public EvaluatorResult(EvaluatorResult.Type typ, DieExpression dVal) {
		this(typ);

		diceVal = dVal;
	}

	public EvaluatorResult(EvaluatorResult.Type typ, Die dVal) {
		this(typ);

		diceVal = new DieExpression(dVal);
	}

	public EvaluatorResult(EvaluatorResult.Type typ, DieList dVal) {
		this(typ);

		diceVal = new DieExpression(dVal);
	}

	public EvaluatorResult(EvaluatorResult.Type typ, String strang) {
		this(typ);

		stringVal = strang;
	}

	public String toString() {
		switch (type) {
		case INT:
			return type.toString() + "(" + intVal + ")";
		case FLOAT:
			return type.toString() + "(" + floatVal + ")";
		case DICE:
			return type.toString() + "(" + diceVal + ")";
		case STRING:
			return type.toString() + "(" + stringVal + ")";
		case FAILURE:
			return type.toString();
		default:
			return "Unknown result type " + type.toString();
		}
	}
}