# # # evaluate_param_cond_util.cfv # # subroutine(get_snapon_parameter_item_condition_value( node snapon_parameter_item), ( # The snapon_parameter_item is one send from the client and only # contains information to evaluate the parameter condition. # Info from Greg regarding expression handling. # You could get even fancier by wrapping the whole thing in a subroutine, # with each of the parameters as *subroutine* parameters, # which would let you just use the parameter names directly in the expression: # # # This subroutine definition is dynamically generated with the names of all snapon parameters as subroutine parameters # subroutine(eval_expression(string aggregation_operator, string file_type), ( # # The expression goes below this line # aggregation_operator eq 'unique' and (file_type eq 'HTLM' or file_type eq 'HTML'; # ); # # Then code is generate to call the subroutine, with the values of the snapon parameters # eval_expression('unique', 'HTML'); # # Then as usual, compile() and execute(). debug_message("#### get_snapon_parameter_item_condition_value()\n"); bool condition_value = false; node condition_parameters = snapon_parameter_item{"condition_parameters"}; # The parameters used in the expression string condition = @snapon_parameter_item{"condition"}; # The condition expression as defined in the snapon parameter item node item; string parameter_name; string parameter_value; string subroutine_as_string = "subroutine(eval_expression("; string subroutine_call_as_string = "eval_expression("; foreach item condition_parameters ( parameter_name = node_name(item); parameter_value = @item; # Add parameter_name as variable definition to subroutine_as_string subroutine_as_string .= "string " . parameter_name . ","; # Add parameter_value as argument to subroutine_call_as_string subroutine_call_as_string .= "'" . parameter_value . "',"; ); # Add the expression to subroutine_as_string and close the subroutine subroutine_as_string = replace_last(subroutine_as_string, ",", "), (\n(" . condition . ");\n));\n"); debug_message("#### subroutine_as_string:\n" . subroutine_as_string . "\n"); # subroutine_call_as_string subroutine_call_as_string = replace_last(subroutine_call_as_string, ",", ");"); debug_message("#### subroutine_call_as_string:\n" . subroutine_call_as_string . "\n"); # Compile and evaluate node n = compile(subroutine_as_string . subroutine_call_as_string); condition_value = evaluate(n); debug_message("#### condition_value: " . condition_value . "\n"); # Return condition_value condition_value; ));