/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-11-15 16:29:17 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20211115162917-yqz4q9epewtpe4p5
Sort of fixed object_to_string ()...
still needs figue out how to do the recurtion propperly.

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 Utils;
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
            {"roll_and_keep", typeof (RollAndKeepFunctionToken)},
 
101
            {null, null}
 
102
        };
 
103
        
 
104
        foreach (Entry e in entries) {
 
105
          _allowed_functions.@set (e.key, e.val);
 
106
        }
 
107
        
 
108
      }
 
109
      
85
110
      FunctionToken? retval = null;
86
111
      
87
112
      // We get the token type.
122
147
      return ret_val;
123
148
    }
124
149
    
125
 
    protected long get_optional_child_raw_result (Context instance,
 
150
    protected FastNumber get_optional_child_raw_result (Context instance,
126
151
                                                  int index,
127
152
                                                  long default_result)
128
153
                                                  throws GLib.Error {
132
157
         tmp_roll.evaluate (instance);
133
158
         return tmp_roll.result_value;
134
159
     } else {
135
 
       return default_result;
 
160
       return FastNumber.raw (default_result);
136
161
     }
 
162
     
137
163
    }
138
 
    
139
 
    
140
 
    
141
164
  }
142
165
}