bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1
by Gustav Hartvigsson
* Initial code - far from done |
1 |
using Gee; |
2 |
||
3 |
using VQDR.Expression; |
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
4 |
using Vee; |
1
by Gustav Hartvigsson
* Initial code - far from done |
5 |
|
6 |
namespace VQDR.Expression { |
|
7 |
public abstract class FunctionToken : Token { |
|
8 |
protected FunctionToken () { |
|
9 |
base (0); |
|
10 |
} |
|
11 |
|
|
26
by Gustav Hartvigsson
* Fixed the "allowed function token type" map... |
12 |
private struct Entry { |
13 |
public string key; |
|
14 |
public Type? val; |
|
15 |
} |
|
16 |
|
|
17 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
18 |
// We only store the type, as that is what is important. |
19 |
private static Gee.HashMap<string, Type?> _allowed_functions; |
|
20 |
|
|
57
by Gustav Hartvigsson
Made sure that no text rows exeed 80 columns. |
21 |
// +1 so that I can still use int64.MIN_VALUE. |
22 |
protected const int64 UNDEFINED = int64.MIN + 1; |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
23 |
/** Right arrow */ |
24 |
protected const string CH_RARR = "\u2192"; |
|
25 |
/** Left arrow */ |
|
26 |
protected const string CH_LARR = "\u2190"; |
|
27 |
/** Round up open bracket */ |
|
28 |
protected const string CH_RUP_OP = "\u2308"; |
|
29 |
/** Round up closed bracket */ |
|
30 |
protected const string CH_RUP_CL = "\u2309"; |
|
31 |
/** Round down open bracket */ |
|
32 |
protected const string CH_RDN_OP = "\u230a"; |
|
33 |
/** Round down closed bracket */ |
|
34 |
protected const string CH_RDN_CL = "\u230b"; |
|
35 |
/** Absolute open bracket */ |
|
36 |
protected const string CH_ABS_OP = "|"; |
|
37 |
/** Absolute closed bracket */ |
|
38 |
protected const string CH_ABS_CL = "|"; |
|
39 |
/** Greater than */ |
|
40 |
protected const string CH_GT = ">"; |
|
41 |
/** Lower than */ |
|
42 |
protected const string CH_LT = "<"; |
|
43 |
/** Equal */ |
|
44 |
protected const string CH_EQUAL = "="; |
|
45 |
||
46 |
/** Begin of a complex result */ |
|
47 |
protected const string SYM_BEGIN = "["; |
|
48 |
/** End of a complex result */ |
|
49 |
protected const string SYM_END = "]"; |
|
50 |
/** Begin of a complex result, alternative */ |
|
51 |
protected const string SYM_BEGIN_ALT = "{"; |
|
52 |
/** End of a complex result, alternative */ |
|
53 |
protected const string SYM_END_ALT = "}"; |
|
54 |
/** Separator for different roll result */ |
|
55 |
protected const string SYM_SEP = ","; |
|
56 |
/** Separator for different value of same roll */ |
|
57 |
protected const string SYM_SEP_SAME = ":"; |
|
58 |
/** Separator for overall (fumble, critical, botch, glitch) */ |
|
59 |
protected const string SYM_SEP_ = "\u2261"; //"=" (with 3 lines) |
|
60 |
/** Denotes a success */ |
|
61 |
protected const string SYM_SUCCESS = "!"; |
|
62 |
/** Denotes a failure */ |
|
63 |
protected const string SYM_FAILURE = "*"; |
|
64 |
/** Denotes an extra result */ |
|
65 |
protected const string SYM_EXTRA = "!"; |
|
66 |
/** Denotes a selected result */ |
|
67 |
protected const string SYM_SELECTED = "!"; |
|
68 |
/** Separator for exploding rolls */ |
|
69 |
protected const string SYM_EXPLODE = "\u00bb"; //">>" |
|
70 |
||
71 |
/** Truncated output: ellipsis */ |
|
72 |
protected const string SYM_TRUNK_PART_ELLIPSIS = "\u2026"; //"..." |
|
73 |
/** Truncated output: equal */ |
|
74 |
protected const string SYM_TRUNK_PART_EQUAL = CH_EQUAL; //"=" |
|
75 |
/** Truncated output: begin */ |
|
57
by Gustav Hartvigsson
Made sure that no text rows exeed 80 columns. |
76 |
protected const string SYM_TRUNK_BEGIN = SYM_BEGIN |
77 |
+ SYM_TRUNK_PART_ELLIPSIS |
|
78 |
+ SYM_TRUNK_PART_EQUAL; //"[...=" |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
79 |
/** Truncated output: end */ |
80 |
protected const string SYM_TRUNK_END = SYM_END; //"]" |
|
81 |
|
|
82 |
construct { |
|
14
by Gustav Hartvigsson
* Use enum instead of static values for the priority of operations. |
83 |
this.priority = Prio.FUNCTION; |
1
by Gustav Hartvigsson
* Initial code - far from done |
84 |
} |
85 |
|
|
26
by Gustav Hartvigsson
* Fixed the "allowed function token type" map... |
86 |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
87 |
/** |
62
by Gustav Hartvigsson
various changes |
88 |
* Initialise the right function token by it's name.
|
1
by Gustav Hartvigsson
* Initial code - far from done |
89 |
*
|
90 |
* @param token Token of the Function.
|
|
91 |
* @param position Token position.
|
|
92 |
* @return An instance representing the function, or @c null if not found.
|
|
93 |
*/
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
94 |
public static FunctionToken? init_token (string token, int32 position) { |
26
by Gustav Hartvigsson
* Fixed the "allowed function token type" map... |
95 |
|
96 |
if (_allowed_functions == null) { |
|
62
by Gustav Hartvigsson
various changes |
97 |
// Initialise the HashMap if it is not created. |
26
by Gustav Hartvigsson
* Fixed the "allowed function token type" map... |
98 |
_allowed_functions = new Gee.HashMap<string, Type?> (); |
99 |
|
|
100 |
Entry[] entries = { |
|
101 |
{"round_up", typeof (RoundUpFunctionToken)}, |
|
102 |
{"round_down", typeof (RoundDownFunctionToken)}, |
|
35
by Gustav Hartvigsson
a few things: FastNumbers, simplifications and AbstractPoolToken. |
103 |
{"roll_and_keep", typeof (RollAndKeepFunctionToken)}, |
26
by Gustav Hartvigsson
* Fixed the "allowed function token type" map... |
104 |
{null, null} |
105 |
}; |
|
106 |
|
|
107 |
foreach (Entry e in entries) { |
|
108 |
_allowed_functions.@set (e.key, e.val); |
|
109 |
} |
|
110 |
|
|
111 |
} |
|
112 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
113 |
// We get the token type. |
114 |
Type? t = _allowed_functions.@get (token.down ()); |
|
115 |
|
|
116 |
if (t != null) { |
|
117 |
// Construct a new instance of the token. |
|
45
by Gustav Hartvigsson
* woopes. |
118 |
return (FunctionToken) GLib.Object.@new (t, null, null); |
1
by Gustav Hartvigsson
* Initial code - far from done |
119 |
} |
45
by Gustav Hartvigsson
* woopes. |
120 |
return null; |
1
by Gustav Hartvigsson
* Initial code - far from done |
121 |
} |
122 |
|
|
123 |
/** |
|
124 |
* Add a FunctionToken Type to the list of allowed functions.
|
|
125 |
*
|
|
126 |
* Note: The Type must be derived from FunctionToken, as there is an
|
|
127 |
* assert that chkecks.
|
|
128 |
*/
|
|
129 |
public static void add_function (string token, Type t) { |
|
130 |
assert (t.is_a (typeof (FunctionToken)) == true); |
|
131 |
_allowed_functions.@set (token, t); |
|
132 |
} |
|
133 |
|
|
134 |
public static string get_function_name (Type t) { |
|
135 |
assert (t.is_a (typeof (FunctionToken)) == true); |
|
136 |
string ret_val = null; |
|
137 |
|
|
138 |
_allowed_functions.map_iterator ().@foreach ((k,v) => { |
|
139 |
if (v == t) { |
|
140 |
ret_val = k; |
|
141 |
return false; |
|
142 |
} |
|
143 |
return true; |
|
144 |
}); |
|
145 |
|
|
146 |
return ret_val; |
|
147 |
} |
|
148 |
|
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
149 |
protected FastNumber get_optional_child_raw_result (Context instance, |
52.1.3
by Gustav Hartvigsson
int -> int32 |
150 |
int32 index, |
52.1.2
by Gustav Hartvigsson
no more 's |
151 |
int64 default_result) |
1
by Gustav Hartvigsson
* Initial code - far from done |
152 |
throws GLib.Error { |
153 |
Token? tmp_roll = get_child (index); |
|
154 |
|
|
155 |
if (tmp_roll != null) { |
|
156 |
tmp_roll.evaluate (instance); |
|
157 |
return tmp_roll.result_value; |
|
158 |
} else { |
|
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
159 |
return FastNumber.raw (default_result); |
1
by Gustav Hartvigsson
* Initial code - far from done |
160 |
} |
26
by Gustav Hartvigsson
* Fixed the "allowed function token type" map... |
161 |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
162 |
} |
163 |
} |
|
164 |
}
|