/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvqdr/function/function_token.vala

  • Committer: Gustav Hartvigsson
  • Date: 2021-09-15 17:10:52 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210915171052-yhdw16iyipyj5a5l
* Fixed Fastnumber's normalisation problem with the getters/setters

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
using Gee;
2
2
 
3
3
using VQDR.Expression;
 
4
using VQDR.Common;
4
5
 
5
6
namespace VQDR.Expression {
6
7
  public abstract class FunctionToken : Token {
8
9
      base (0);
9
10
    }
10
11
    
 
12
    private struct Entry {
 
13
      public string key;
 
14
      public Type? val;
 
15
    }
 
16
    
 
17
    
11
18
    // We only store the type, as that is what is important.
12
19
    private static Gee.HashMap<string, Type?> _allowed_functions;
13
20
    
70
77
    protected const string SYM_TRUNK_END = SYM_END; //"]"
71
78
    
72
79
    construct {
73
 
      _allowed_functions = new Gee.HashMap<string, Type?> ();
74
 
      this.priority = PRIO_FUNCTION;
 
80
      this.priority = Prio.FUNCTION;
75
81
    }
76
82
    
 
83
    
77
84
    /**
78
85
     * Ititialise the right functon token by it's name.
79
86
     * 
82
89
     * @return An instance representing the function, or @c null if not found.
83
90
     */
84
91
    public static FunctionToken? init_token (string token, int position) {
 
92
      
 
93
      if (_allowed_functions == null) {
 
94
        // Intialise the HashMap if it is not created.
 
95
        _allowed_functions = new Gee.HashMap<string, Type?> ();
 
96
        
 
97
        Entry[] entries = {
 
98
            {"round_up", typeof (RoundUpFunctionToken)},
 
99
            {"round_down", typeof (RoundDownFunctionToken)},
 
100
            {null, null}
 
101
        };
 
102
        
 
103
        foreach (Entry e in entries) {
 
104
          _allowed_functions.@set (e.key, e.val);
 
105
        }
 
106
        
 
107
      }
 
108
      
85
109
      FunctionToken? retval = null;
86
110
      
87
111
      // We get the token type.
122
146
      return ret_val;
123
147
    }
124
148
    
125
 
    protected long get_optional_child_raw_result (Context instance,
 
149
    protected FastNumber get_optional_child_raw_result (Context instance,
126
150
                                                  int index,
127
151
                                                  long default_result)
128
152
                                                  throws GLib.Error {
132
156
         tmp_roll.evaluate (instance);
133
157
         return tmp_roll.result_value;
134
158
     } else {
135
 
       return default_result;
 
159
       return FastNumber.raw (default_result);
136
160
     }
 
161
     
137
162
    }
138
 
    
139
 
    
140
 
    
141
163
  }
142
164
}