void Foam::expressionField::execute()
{
    if(active_) {
        FieldValueExpressionDriver &driver=driver_();

        driver.clearVariables();

        driver.parse(expression_);

        if(driver.resultIsVector()) {
            storeField(
                driver.getVector(),
                vectorField_
            );
            
        } else if(driver.resultIsScalar()) {
            storeField(
                driver.getScalar(),
                scalarField_
            );
        } else {
            WarningIn("Foam::expressionField::execute()")
                << "Expression '" << expression_ 
                    << "' evaluated to an unsupported type"
                    << endl;
        }
    }
}
Beispiel #2
0
/**
 * Copy a native Invocation to the supplied Invocation instance.
 * @param invoc the native InvocStore 
 * @param mode the mode of copyout
 * @param invocObj the Invocation object to copy to
 * @param argsObj an object to use to refer to the arguments array
 * @param obj a temporary object handle
 * @return 0 if there were problems allocating Java Strings;
 *    1 if all the copies succeeded;
 *    -1 if the Java Arrays allocated for args or data were insufficient
 */
static int copyOut(StoredInvoc *invoc, int mode, 
            jobject invocObj, jobject argsObj, jobject obj)
{
    int datalen = 0;
    int arraylen = 0;

    /* Set the required lengths for args and data arrays. */
    KNI_SetIntField(invocObj, argsLenFid, invoc->argsLen);
    KNI_SetIntField(invocObj, dataLenFid, invoc->dataLen);

    /* Check if size of argument array and data array are correct. */
    KNI_GetObjectField(invocObj, dataFid, obj);
    datalen = KNI_GetArrayLength(obj);
    if (datalen != invoc->dataLen) {
        /* Data array allocated by Java is not correct size. */
        return -1;
    }
    KNI_GetObjectField(invocObj, argumentsFid, obj);
    arraylen = KNI_GetArrayLength(obj);
    if (arraylen != invoc->argsLen) {
        /* Args array allocated by Java is not correct size. */
        return -1;
    }

    /* Copy out all the string fields. */
    if (!(storeField(&invoc->url, invocObj, urlFid, obj) &&
          storeField(&invoc->type, invocObj, typeFid, obj) &&
          storeField(&invoc->action, invocObj, actionFid, obj) &&
          storeField(&invoc->ID, invocObj, IDFid, obj) &&
          storeField(&invoc->invokingClassname, 
                 invocObj, invokingClassnameFid, obj) &&
          storeField(&invoc->invokingAuthority,
                 invocObj, invokingAuthorityFid, obj) &&
          storeField(&invoc->invokingAppName,
                 invocObj, invokingAppNameFid, obj) &&
          storeField(&invoc->invokingID,
                 invocObj, invokingIDFid, obj) &&
          storeField(&invoc->username,
                 invocObj, usernameFid, obj) &&
          storeField(&invoc->password,
                 invocObj, passwordFid, obj))) {
        /* Some String allocation failed. */
        return 0;
    }
    KNI_SetIntField(invocObj, invokingSuiteIdFid, invoc->invokingSuiteId);
    /* See if the suite and classname are needed. */
    if (mode == MODE_TID || 
        mode == MODE_TID_PREV ||
        mode == MODE_TID_NEXT) {
        if (!storeField(&invoc->classname, invocObj, classnameFid, obj)) {
            /* A string allocation failed. */
            return 0;
        }
            KNI_SetIntField(invocObj, suiteIdFid, invoc->suiteId);
    }

    /* Return the arguments if any; array length already checked. */
    if (invoc->argsLen > 0) {
        int ndx;
        pcsl_string* args;
    
        /* For each stored arg create a string and store in the array.
         * No stored arg is null.  If a string cannot be created
         * it is due to insufficient heap memory. 
         */
        KNI_GetObjectField(invocObj, argumentsFid, argsObj);
        args = invoc->args;
        for (ndx = 0; ndx < invoc->argsLen; ndx++, args++) {
            if (!pcsl_string_is_null(args)) {
                if (PCSL_STRING_OK != 
                        midp_jstring_from_pcsl_string(args, obj)) {
                    /* String create failed; exit now. */
                    return 0;
                }
            } else {
                KNI_ReleaseHandle(obj);
            }
            KNI_SetObjectArrayElement(argsObj, ndx, obj);
        }
    }

    /* Return the data array if any; array length was already checked. */
    if (invoc->dataLen > 0) {
        KNI_GetObjectField(invocObj, dataFid, obj);
        KNI_SetRawArrayRegion(obj, 0, invoc->dataLen, invoc->data);
    }

    KNI_SetBooleanField(invocObj, responseRequiredFid,
            invoc->responseRequired);
    KNI_SetIntField(invocObj, statusFid, invoc->status);
    KNI_SetIntField(invocObj, tidFid, invoc->tid);
    KNI_SetIntField(invocObj, previousTidFid, invoc->previousTid);
    /* Successful copy out. */
    return 1;
}
bool
#else
void
#endif
Foam::expressionField::write()
{
    Dbug << "write()" << endl;

    if(active_) {
        Info << "Creating expression field " << name_ << " ..." << flush;

        FieldValueExpressionDriver &driver=driver_();

        bool oldDimsetDebug=dimensionSet::debug;
        dimensionSet::debug=false;

        driver.clearVariables();

        driver.parse(expression_);

        dimensionSet::debug=oldDimsetDebug;

        Info << " type:" << driver.getResultType() << endl;

        if(driver.resultIsTyp<volVectorField>()) {
            storeField(
                driver.getResult<volVectorField>()
            );
        } else if(driver.resultIsTyp<volScalarField>()) {
            storeField(
                driver.getResult<volScalarField>()
            );
        } else if(driver.resultIsTyp<volTensorField>()) {
            storeField(
                driver.getResult<volTensorField>()
            );
        } else if(driver.resultIsTyp<volSymmTensorField>()) {
            storeField(
                driver.getResult<volSymmTensorField>()
            );
        } else if(driver.resultIsTyp<volSphericalTensorField>()) {
            storeField(
                driver.getResult<volSphericalTensorField>()
            );
        } else if(driver.resultIsTyp<surfaceVectorField>()) {
            storeField(
                driver.getResult<surfaceVectorField>()
            );
        } else if(driver.resultIsTyp<surfaceScalarField>()) {
            storeField(
                driver.getResult<surfaceScalarField>()
            );
        } else if(driver.resultIsTyp<surfaceTensorField>()) {
            storeField(
                driver.getResult<surfaceTensorField>()
            );
        } else if(driver.resultIsTyp<surfaceSymmTensorField>()) {
            storeField(
                driver.getResult<surfaceSymmTensorField>()
            );
        } else if(driver.resultIsTyp<surfaceSphericalTensorField>()) {
            storeField(
                driver.getResult<surfaceSphericalTensorField>()
            );
        } else if(driver.resultIsTyp<pointVectorField>()) {
            storeField(
                driver.getResult<pointVectorField>()
            );
        } else if(driver.resultIsTyp<pointScalarField>()) {
            storeField(
                driver.getResult<pointScalarField>()
            );
        } else if(driver.resultIsTyp<pointTensorField>()) {
            storeField(
                driver.getResult<pointTensorField>()
            );
        } else if(driver.resultIsTyp<pointSymmTensorField>()) {
            storeField(
                driver.getResult<pointSymmTensorField>()
            );
        } else if(driver.resultIsTyp<pointSphericalTensorField>()) {
            storeField(
                driver.getResult<pointSphericalTensorField>()
            );
        } else {
            WarningIn("Foam::expressionField::execute()")
                << "Expression '" << expression_
                    << "' evaluated to an unsupported type "
                    << driver.typ()
                    << endl;
        }
    }

    driver_->tryWrite();
    Dbug << "write() - end" << endl;
#ifdef FOAM_IOFILTER_WRITE_NEEDS_BOOL
    return true;
#endif
}