Ejemplo n.º 1
0
ActionValue ASTNode::value(const ActionContext& context) const {
    if (this->children.size() != 0)
        throw std::invalid_argument("value() method should only reach leafnodes");

    if (this->type == TokenType::number)
        return ActionValue(this->number);

    if (this->arg_list.size() == 0)
        return ActionValue(context.get(this->func));
    else {
        /*
          The matching code is special case to handle one-argument cases with
          well patterns like 'P*'.
        */
        if ((this->arg_list.size() == 1) && (arg_list[0].find("*") != std::string::npos)) {
            ActionValue well_values;
            int fnmatch_flags = 0;
            for (const auto& well : context.wells(this->func)) {
                if (fnmatch(this->arg_list[0].c_str(), well.c_str(), fnmatch_flags) == 0)
                    well_values.add_well(well, context.get(this->func, well));
            }
            return well_values;
        } else {
            std::string arg_key = this->arg_list[0];
            for (size_t index = 1; index < this->arg_list.size(); index++)
                arg_key += ":" + this->arg_list[index];
            return ActionValue(context.get(this->func, arg_key));
        }
    }
}
Ejemplo n.º 2
0
double ASTNode::value(const ActionContext& context) const {
    if (this->children.size() != 0)
        throw std::invalid_argument("value() method should only reach leafnodes");

    if (this->type == TokenType::number)
        return this->number;

    if (this->arg_list.size() == 0)
        return context.get(this->func);
    else {
        std::string arg_key = this->arg_list[0];
        for (size_t index = 1; index < this->arg_list.size(); index++)
            arg_key += ":" + this->arg_list[index];
        return context.get(this->func, arg_key);
    }
}