/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: 2020-06-07 18:48:24 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20200607184824-jf14f7a1b1di2i2q
* Initial code - far from done

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;
5
4
 
6
5
namespace VQDR.Expression {
7
6
  public abstract class FunctionToken : Token {
9
8
      base (0);
10
9
    }
11
10
    
12
 
    private struct Entry {
13
 
      public string key;
14
 
      public Type? val;
15
 
    }
16
 
    
17
 
    
18
11
    // We only store the type, as that is what is important.
19
12
    private static Gee.HashMap<string, Type?> _allowed_functions;
20
13
    
77
70
    protected const string SYM_TRUNK_END = SYM_END; //"]"
78
71
    
79
72
    construct {
80
 
      this.priority = Prio.FUNCTION;
 
73
      _allowed_functions = new Gee.HashMap<string, Type?> ();
 
74
      this.priority = PRIO_FUNCTION;
81
75
    }
82
76
    
83
 
    
84
77
    /**
85
78
     * Ititialise the right functon token by it's name.
86
79
     * 
89
82
     * @return An instance representing the function, or @c null if not found.
90
83
     */
91
84
    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
 
      
109
85
      FunctionToken? retval = null;
110
86
      
111
87
      // We get the token type.
146
122
      return ret_val;
147
123
    }
148
124
    
149
 
    protected FastNumber get_optional_child_raw_result (Context instance,
 
125
    protected long get_optional_child_raw_result (Context instance,
150
126
                                                  int index,
151
127
                                                  long default_result)
152
128
                                                  throws GLib.Error {
156
132
         tmp_roll.evaluate (instance);
157
133
         return tmp_roll.result_value;
158
134
     } else {
159
 
       return FastNumber.raw (default_result);
 
135
       return default_result;
160
136
     }
161
 
     
162
137
    }
 
138
    
 
139
    
 
140
    
163
141
  }
164
142
}