bool OsmAnd::RoutingRuleExpression::evaluate( const QBitArray& types, RoutingRulesetContext* context, ResultType resultType, void* result ) const
{
    if(!validate(types, context))
        return false;

    if(!evaluateExpressions(types, context))
        return false;

    float value;
    bool ok = false;
    if(!_tagRef.isEmpty())
        ok = resolveTagReferenceValue(context, types, _tagRef, type, value);
    else if(!_variableRef.isEmpty())
        ok = resolveVariableReferenceValue(context, _variableRef, type, value);
    else
    {
        value = _value;
        ok = true;
    }
    
    if(ok)
    {
        if(resultType == Float)
            *reinterpret_cast<float*>(result) = value;
        else if(resultType == Integer)
            *reinterpret_cast<int*>(result) = (int)value;
        else
            ok = false;
    }
    return ok;
}
Esempio n. 2
0
Error evaluateString(const std::string& str, 
                     SEXP* pSEXP, 
                     sexp::Protect* pProtect)
{
   // refresh source if necessary (no-op in production)
   r::sourceManager().reloadIfNecessary();
   
   // surrond the string with try in silent mode so we can capture error text
   std::string rCode = "try(" + str + ", TRUE)";

   // parse expression
   SEXP ps;
   Error parseError = parseString(rCode, &ps, pProtect);
   if (parseError)
      return parseError;

   // evaluate the expression
   Error evalError = evaluateExpressions(ps, pSEXP, pProtect);
   if (evalError)
   {
      evalError.addProperty("code", str);
      return evalError;
   }
   
   // check for try-error
   if (Rf_inherits(*pSEXP, "try-error"))
   {
      // get error message (merely log on failure so we can continue
      // and return the real error)
      std::string errorMsg ;
      Error extractError = sexp::extract(*pSEXP, &errorMsg);
      if (extractError)
         LOG_ERROR(extractError);
   
      // add it to the error
      return rCodeExecutionError(errorMsg, ERROR_LOCATION);
   }
   
   return Success();
}
Esempio n. 3
0
Error RFunction::call(SEXP evalNS, SEXP* pResultSEXP, sexp::Protect* pProtect)
{
   // verify the function
   if (functionSEXP_ == R_UnboundValue)
   {
      Error error(errc::SymbolNotFoundError, ERROR_LOCATION);
      if (!functionName_.empty())
         error.addProperty("symbol", functionName_);
      return error;
   }
   
   // create the call object (LANGSXP) with the correct number of elements
   SEXP callSEXP ;
   pProtect->add(callSEXP = Rf_allocVector(LANGSXP, 1 + params_.size()));
   SET_TAG(callSEXP, R_NilValue); // just like do_ascall() does 
   
   // assign the function to the first element of the call
   SETCAR(callSEXP, functionSEXP_);
   
   // assign parameters to the subseqent elements of the call
   SEXP nextSlotSEXP = CDR(callSEXP);
   for (std::vector<Param>::const_iterator 
            it = params_.begin(); it != params_.end(); ++it)
   {
      SETCAR(nextSlotSEXP, it->valueSEXP);
      // parameters can optionally be named
      if (!(it->name.empty()))
         SET_TAG(nextSlotSEXP, Rf_install(it->name.c_str()));
      nextSlotSEXP = CDR(nextSlotSEXP);
   }
   
   // call the function
   Error error = evaluateExpressions(callSEXP, evalNS, pResultSEXP, pProtect);  
   if (error)
      return error;
   
   // return success
   return Success();
}
Esempio n. 4
0
int main(int argc, char *argv[]) {
  evaluateExpressions();
  return 0;
}